BuecherwurmAPI/Controllers/ItemController.cs

72 lines
1.7 KiB
C#

using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Microsoft.Data.Sqlite;
//using Microsoft.EntityFrameworkCore;
namespace BuecherwurmAPI.Controllers
{
[Route("inventar")]
[ApiController]
public class ItemController : ControllerBase
{
private readonly IItemRepo _repository;
public ItemController(IItemRepo 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(ItemPost item)
{
return Ok(new Item
{
ItemId = itemId,
BookId = bookId
});
}
// GET Inventar/{id}
[HttpGet("{itemId}")]
public ActionResult<IEnumerable<Item>> GetItemByID(int id)
{
var item = _repository.GetItemById(id);
if (item != null)
{
return Ok(item);
}
return NoContent();
}
// DELETE inventory/{id}
[HttpDelete("itemId")]
public ActionResult<IEnumerable<Item>> DeleteItem(int itemId)
{
var item = _repository.GetItemById(itemId);
if(item == null)
{
return NotFound();
}
_repository.DeleteItem(item);
return NoContent();
}
}
}