BuecherwurmAPI/Controllers/InventarController.cs

70 lines
1.6 KiB
C#
Raw Normal View History

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
{
private readonly IInventarRepo _repository;
public InventarController(IInventarRepo repository)
{
_repository = repository;
}
// GET Inventar
[HttpGet]
public ActionResult<IEnumerable<Item>> GetAllItems()
{
var items = _repository.GetAllItems();
return Ok(items);
}
// POST Inventar
[HttpPost]
public ActionResult<IEnumerable<Item>> NewItem(Item item)
{
return Ok(new Item
{
Id = item.Id,
BookId = item.BookId,
});
}
// 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();
}
_repository.DeleteItem(item);
return NoContent();
}
}
}