BuecherwurmAPI/Controllers/InventarController.cs

70 lines
1.7 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
//using Microsoft.EntityFrameworkCore;
2020-06-02 09:16:45 +00:00
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 13:22:45 +00:00
public InventarController(IItemRepo repository)
{
_repository = repository;
}
// GET Inventar
[HttpGet]
public ActionResult<IEnumerable<Item>> GetAllItems()
{
var items = _repository.GetAllItems();
return Ok(items);
}
// POST Inventar
[HttpPost]
2020-06-03 07:26:07 +00:00
public ActionResult<IEnumerable<Item>> NewItem(int bookId)
{
2020-06-03 07:26:07 +00:00
var itemid = insertItemReturningId(bookId);
return Ok(new Item
{
2020-06-03 07:26:07 +00:00
Id = itemId,
BookId = bookId,
});
}
2020-06-03 07:26:07 +00:00
// GET Inventar/{id}
[HttpGet("{id}", Name = "GetItemByID")]
public ActionResult<IEnumerable<Item>> GetItemByID(int id)
{
var item = _repository.GetItemById(id);
if (item != null)
{
return Ok(item);
}
return NoContent();
}
// DELETE inventory/{id}
[HttpDelete("id")]
public ActionResult<IEnumerable<Item>> DeleteItem(int id)
{
var item = _repository.GetItemById(id);
if (item == null)
{
return NotFound();
}
2020-05-28 13:56:51 +00:00
_repository.DeleteItem(item);
return NoContent();
}
}
}