Browse Source

make items queryable

Amedeo
nek0 2 years ago
parent
commit
1d49265230
  1. 16
      Controllers/ItemController.cs
  2. 4
      Controllers/LendController.cs
  3. 1
      DTOs/LendRead.cs
  4. BIN
      LongWormMemory.db
  5. 2
      Models/ItemModel.cs
  6. 6
      Models/LendModel.cs
  7. 1
      Startup.cs

16
Controllers/ItemController.cs

@ -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)

4
Controllers/LendController.cs

@ -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;
}

1
DTOs/LendRead.cs

@ -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; }
}
}

BIN
LongWormMemory.db

Binary file not shown.

2
Models/ItemModel.cs

@ -6,7 +6,7 @@ using Microsoft.VisualBasic.CompilerServices;
namespace BuecherwurmAPI.Models
{
internal class ItemModel : IItemRepo
internal class ItemModel : IModel
{
private SqliteConnection _dbConnection;

6
Models/LendModel.cs

@ -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)

1
Startup.cs

@ -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…
Cancel
Save