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

View file

@ -4,7 +4,6 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoMapper; using AutoMapper;
using BuecherwurmAPI.Models; using BuecherwurmAPI.Models;
using BuecherwurmAPI.DTOs;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.JsonPatch;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -17,12 +16,12 @@ namespace BuecherwurmAPI.Controllers
public class LendController : ControllerBase public class LendController : ControllerBase
{ {
private readonly LendModel _repository; 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; _repository = (LendModel)repo;
_mapper = mapper; //_mapper = mapper;
} }
//GET api/leihvorgang //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 namespace BuecherwurmAPI.Models
{ {
internal class ItemModel : IModel public interface IItem
{
}
internal class ItemModel : IItem
{ {
private SqliteConnection _dbConnection; private SqliteConnection _dbConnection;
@ -49,7 +54,7 @@ namespace BuecherwurmAPI.Models
// using automatically disposes the command after completion // using automatically disposes the command after completion
using (var command = _dbConnection.CreateCommand()) using (var command = _dbConnection.CreateCommand())
{ {
command.CommandText = "SELECT FROM Items"; command.CommandText = "SELECT * FROM Items";
var dataReader = command.ExecuteReader(); var dataReader = command.ExecuteReader();
while (dataReader.Read()) while (dataReader.Read())
@ -71,13 +76,11 @@ namespace BuecherwurmAPI.Models
using (var command = _dbConnection.CreateCommand()) using (var command = _dbConnection.CreateCommand())
{ {
command.Parameters.Add(new SqliteParameter("@itemId", itemId)); 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(); var dataReader = command.ExecuteReader();
while (dataReader.Read()) while (dataReader.Read())
{ {
var returned = (long) dataReader["Returned"] == 1;
var item = new Item var item = new Item
{ {
ItemId = (long) dataReader["ItemId"], ItemId = (long) dataReader["ItemId"],
@ -111,7 +114,6 @@ namespace BuecherwurmAPI.Models
{ {
using (var command = _dbConnection.CreateCommand()) using (var command = _dbConnection.CreateCommand())
{ {
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = itemId;
command.CommandText = "DELETE FROM Items WHERE ItemId = @itemId"; command.CommandText = "DELETE FROM Items WHERE ItemId = @itemId";
command.Parameters.Add(new SqliteParameter("@itemId", itemId)); command.Parameters.Add(new SqliteParameter("@itemId", itemId));
command.ExecuteNonQuery(); command.ExecuteNonQuery();

View file

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

View file

@ -1,5 +1,4 @@
using AutoMapper; using AutoMapper;
using BuecherwurmAPI.DTOs;
using BuecherwurmAPI.Models; using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Profiles namespace BuecherwurmAPI.Profiles
@ -8,7 +7,7 @@ namespace BuecherwurmAPI.Profiles
{ {
public LendProfile() 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. // Adds a service that is created once per connection.
// It takes an interface and a specific implementation. // It takes an interface and a specific implementation.
// That allows to swap the implementation easily. // That allows to swap the implementation easily.
services.AddScoped<IModel, LendModel>(); services.AddScoped<ILend, LendModel>();
services.AddScoped<IModel, ItemModel>(); services.AddScoped<IItem, ItemModel>();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
} }