make items queryable
This commit is contained in:
parent
d0672366dc
commit
1d49265230
7 changed files with 16 additions and 14 deletions
|
@ -8,17 +8,17 @@ using Microsoft.Data.Sqlite;
|
|||
|
||||
namespace BuecherwurmAPI.Controllers
|
||||
{
|
||||
[Route("inventar")]
|
||||
[Route("api/inventar")]
|
||||
[ApiController]
|
||||
public class ItemController : ControllerBase
|
||||
{
|
||||
private readonly IItemRepo _repository;
|
||||
private readonly ItemModel _repository;
|
||||
|
||||
public ItemController(IItemRepo repository)
|
||||
public ItemController(IModel repository)
|
||||
{
|
||||
_repository = repository;
|
||||
_repository = (ItemModel)repository;
|
||||
}
|
||||
// GET Inventar
|
||||
// GET api/inventar
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<Item>> GetAllItems()
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ namespace BuecherwurmAPI.Controllers
|
|||
return Ok(items);
|
||||
}
|
||||
|
||||
// POST Inventar
|
||||
// POST api/inventar
|
||||
[HttpPost]
|
||||
|
||||
public ActionResult<IEnumerable<Item>> NewItem(ItemPost item)
|
||||
|
@ -36,7 +36,7 @@ namespace BuecherwurmAPI.Controllers
|
|||
|
||||
}
|
||||
|
||||
// GET Inventar/{id}
|
||||
// GET api/nventar/{id}
|
||||
[HttpGet("{itemId}")]
|
||||
public ActionResult<IEnumerable<Item>> GetItemByID(long id)
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ namespace BuecherwurmAPI.Controllers
|
|||
return NoContent();
|
||||
}
|
||||
|
||||
// DELETE inventory/{id}
|
||||
// DELETE api/inventar/{id}
|
||||
|
||||
[HttpDelete("itemId")]
|
||||
public ActionResult<IEnumerable<Item>> DeleteItem(long itemId)
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace BuecherwurmAPI.Controllers
|
|||
private readonly LendModel _repository;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public LendController(SqliteConnection connection, IMapper mapper)
|
||||
public LendController(IModel repo, IMapper mapper)
|
||||
{
|
||||
_repository = new LendModel(connection);
|
||||
_repository = (LendModel)repo;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,5 @@ namespace BuecherwurmAPI.DTOs
|
|||
public int ItemId { get; set;}
|
||||
public DateTime ReturnDate { get; set; }
|
||||
public string Customer { get; set; }
|
||||
public bool Returned { get; set; }
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -6,7 +6,7 @@ using Microsoft.VisualBasic.CompilerServices;
|
|||
|
||||
namespace BuecherwurmAPI.Models
|
||||
{
|
||||
internal class ItemModel : IItemRepo
|
||||
internal class ItemModel : IModel
|
||||
{
|
||||
private SqliteConnection _dbConnection;
|
||||
|
||||
|
|
|
@ -10,9 +10,11 @@ namespace BuecherwurmAPI.Models
|
|||
{
|
||||
public SqliteConnection _dbConnection;
|
||||
|
||||
public LendModel(SqliteConnection connection)
|
||||
public LendModel()
|
||||
{
|
||||
_dbConnection = connection;
|
||||
var connectionBuilder = new SqliteConnectionStringBuilder {DataSource = "LongWormMemory.db"};
|
||||
_dbConnection = new SqliteConnection(connectionBuilder.ConnectionString);
|
||||
_dbConnection.Open();
|
||||
}
|
||||
|
||||
public bool IdExits(string table, long id)
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace BuecherwurmAPI
|
|||
// It takes an interface and a specific implementation.
|
||||
// That allows to swap the implementation easily.
|
||||
services.AddScoped<IModel, LendModel>();
|
||||
services.AddScoped<IModel, ItemModel>();
|
||||
|
||||
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue