2020-05-28 08:07:58 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using BuecherwurmAPI.Models;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using System.Linq;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using BuecherwurmAPI.Data;
|
|
|
|
|
|
|
|
namespace BuecherwurmAPI.Controllers
|
|
|
|
{
|
|
|
|
[Route("inventar")]
|
|
|
|
[ApiController]
|
|
|
|
public class InventarController : ControllerBase
|
|
|
|
{
|
2020-05-28 13:22:45 +00:00
|
|
|
private readonly IItemRepo _repository;
|
2020-05-28 08:07:58 +00:00
|
|
|
|
2020-05-28 13:22:45 +00:00
|
|
|
public InventarController(IItemRepo repository)
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
|
|
|
_repository = repository;
|
|
|
|
}
|
|
|
|
// GET Inventar
|
|
|
|
[HttpGet]
|
2020-05-28 08:38:21 +00:00
|
|
|
public ActionResult<IEnumerable<Item>> GetAllItems()
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
2020-05-28 08:38:21 +00:00
|
|
|
var items = _repository.GetAllItems();
|
|
|
|
return Ok(items);
|
2020-05-28 08:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// POST Inventar
|
|
|
|
[HttpPost]
|
2020-05-28 08:38:21 +00:00
|
|
|
public ActionResult<IEnumerable<Item>> NewItem(Item item)
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
2020-05-28 08:38:21 +00:00
|
|
|
return Ok(new Item
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
2020-05-28 08:38:21 +00:00
|
|
|
Id = item.Id,
|
|
|
|
BookId = book.ProductId,
|
2020-05-28 08:07:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET Inventar/{id}
|
2020-05-28 08:38:21 +00:00
|
|
|
[HttpGet("{id}", Name = "GetItemByID")]
|
|
|
|
public ActionResult<IEnumerable<Item>> GetItemByID(int id)
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
2020-05-28 08:38:21 +00:00
|
|
|
var item = _repository.GetItemById(id);
|
|
|
|
if (item != null)
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
2020-05-28 08:38:21 +00:00
|
|
|
return Ok(item);
|
2020-05-28 08:07:58 +00:00
|
|
|
}
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-28 08:10:32 +00:00
|
|
|
// DELETE inventory/{id}
|
2020-05-28 08:31:04 +00:00
|
|
|
[HttpDelete("id")]
|
2020-05-28 08:38:21 +00:00
|
|
|
public ActionResult<IEnumerable<Item>> DeleteItem(int id)
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
2020-05-28 08:38:21 +00:00
|
|
|
var item = _repository.GetItemById(id);
|
|
|
|
if (item == null)
|
2020-05-28 08:07:58 +00:00
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
2020-05-28 13:22:45 +00:00
|
|
|
_repository.DeleteItem(item);
|
2020-05-28 08:07:58 +00:00
|
|
|
return NoContent();
|
2020-05-28 08:31:04 +00:00
|
|
|
}
|
2020-05-28 08:07:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-05-28 13:22:45 +00:00
|
|
|
l
|