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> GetAllItems() { var items = _repository.GetAllItems(); if (items != null) { return Ok(items); } return NoContent(); } // POST Inventar [HttpPost] public ActionResult> NewItem(ItemPost item) { try { var newItem = _repository.NewItem(item); if (item != null) { return Ok(newItem); } return NotFound(); } catch (System.Exception) { return StatusCode(304); //not Modified } } // GET Inventar/{id} [HttpGet("{itemId}")] public ActionResult> GetItemByID(long id) { var item = _repository.GetItemById(id); if (item != null) { return Ok(item); } return NoContent(); } // DELETE inventory/{id} [HttpDelete("itemId")] public ActionResult> DeleteItem(long itemId) { var item = _repository.GetItemById(itemId); if(item == null) { return NotFound(); } _repository.DeleteItem(itemId); return NoContent(); } } }