reviewed, debugged and meowed with items

This commit is contained in:
nek0 2020-06-03 11:34:12 +02:00
parent f970ccc07e
commit 56e1cc1452
8 changed files with 24 additions and 27 deletions

View File

@ -14,7 +14,7 @@ namespace BuecherwurmAPI.Controllers
{
private readonly ItemModel _repository;
public ItemController(IModel repository)
public ItemController(IItem repository)
{
_repository = (ItemModel)repository;
}
@ -50,7 +50,7 @@ namespace BuecherwurmAPI.Controllers
// DELETE api/inventar/{id}
[HttpDelete("itemId")]
[HttpDelete("{itemId}")]
public ActionResult<IEnumerable<Item>> DeleteItem(long itemId)
{
var item = _repository.GetItemById(itemId);

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using BuecherwurmAPI.Models;
using BuecherwurmAPI.DTOs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.Extensions.Logging;
@ -17,12 +16,12 @@ namespace BuecherwurmAPI.Controllers
public class LendController : ControllerBase
{
private readonly LendModel _repository;
private readonly IMapper _mapper;
//private readonly IMapper _mapper;
public LendController(IModel repo, IMapper mapper)
public LendController(ILend repo)
{
_repository = (LendModel)repo;
_mapper = mapper;
//_mapper = mapper;
}
//GET api/leihvorgang

Binary file not shown.

View File

@ -1,9 +0,0 @@
using Microsoft.Data.Sqlite;
namespace BuecherwurmAPI.Models
{
public interface IModel
{
}
}

View File

@ -6,7 +6,12 @@ using Microsoft.VisualBasic.CompilerServices;
namespace BuecherwurmAPI.Models
{
internal class ItemModel : IModel
public interface IItem
{
}
internal class ItemModel : IItem
{
private SqliteConnection _dbConnection;
@ -49,7 +54,7 @@ namespace BuecherwurmAPI.Models
// using automatically disposes the command after completion
using (var command = _dbConnection.CreateCommand())
{
command.CommandText = "SELECT FROM Items";
command.CommandText = "SELECT * FROM Items";
var dataReader = command.ExecuteReader();
while (dataReader.Read())
@ -71,13 +76,11 @@ namespace BuecherwurmAPI.Models
using (var command = _dbConnection.CreateCommand())
{
command.Parameters.Add(new SqliteParameter("@itemId", itemId));
command.CommandText = "SELECT FROM Items WHERE Id = @itemId";
command.CommandText = "SELECT * FROM Items WHERE ItemId = @itemId";
var dataReader = command.ExecuteReader();
while (dataReader.Read())
{
var returned = (long) dataReader["Returned"] == 1;
var item = new Item
{
ItemId = (long) dataReader["ItemId"],
@ -111,7 +114,6 @@ namespace BuecherwurmAPI.Models
{
using (var command = _dbConnection.CreateCommand())
{
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = itemId;
command.CommandText = "DELETE FROM Items WHERE ItemId = @itemId";
command.Parameters.Add(new SqliteParameter("@itemId", itemId));
command.ExecuteNonQuery();

View File

@ -6,9 +6,15 @@ using Microsoft.VisualBasic.CompilerServices;
namespace BuecherwurmAPI.Models
{
internal class LendModel : IModel
public interface ILend
{
public SqliteConnection _dbConnection;
}
internal class LendModel : ILend
{
private SqliteConnection _dbConnection;
public LendModel()
{

View File

@ -1,5 +1,4 @@
using AutoMapper;
using BuecherwurmAPI.DTOs;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Profiles
@ -8,7 +7,7 @@ namespace BuecherwurmAPI.Profiles
{
public LendProfile()
{
CreateMap<Lend, LendReadDTO>();
CreateMap<Lend, LendPost>();
}
}
}

View File

@ -32,8 +32,8 @@ namespace BuecherwurmAPI
// Adds a service that is created once per connection.
// It takes an interface and a specific implementation.
// That allows to swap the implementation easily.
services.AddScoped<IModel, LendModel>();
services.AddScoped<IModel, ItemModel>();
services.AddScoped<ILend, LendModel>();
services.AddScoped<IItem, ItemModel>();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
}