diff --git a/Controllers/InventarController.cs b/Controllers/InventarController.cs new file mode 100644 index 0000000..8a16a64 --- /dev/null +++ b/Controllers/InventarController.cs @@ -0,0 +1,69 @@ +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> GetAllItems() + { + var items = _repository.GetAllItems(); + return Ok(items); + } + + // POST Inventar + [HttpPost] + public ActionResult> NewItem(Item item) + { + return Ok(new Item + { + Id = item.Id, + BookId = item.BookId, + }); + } + + + // GET Inventar/{id} + [HttpGet("{id}", Name = "GetItemByID")] + public ActionResult> GetItemByID(int id) + { + var item = _repository.GetItemById(id); + if (item != null) + { + return Ok(item); + } + return NoContent(); + + } + + + // DELETE inventory/{id} + [HttpDelete("id")] + public ActionResult> DeleteItem(int id) + { + var item = _repository.GetItemById(id); + if (item == null) + { + return NotFound(); + } + _repository.DeleteItem(item); + return NoContent(); + } + + } + +} diff --git a/Data/IInventarRepo.cs b/Data/IInventarRepo.cs new file mode 100644 index 0000000..50bb73e --- /dev/null +++ b/Data/IInventarRepo.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using BuecherwurmAPI.Models; + +namespace BuecherwurmAPI.Data +{ + public interface IInventarRepo + { + IEnumerable GetAllItems(); + Item GetItemById(int id); + void DeleteItem(Item item); + } +} \ No newline at end of file diff --git a/Models/Item.cs b/Models/Item.cs new file mode 100644 index 0000000..c6e6012 --- /dev/null +++ b/Models/Item.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace BuecherwurmAPI.Models +{ + public class Item + { + [Key] + [Required] + public int Id { get; set; } + [Required] + public int BookId { get; set; } + } + +} \ No newline at end of file diff --git a/bin/Debug/netcoreapp3.1/BuecherwurmAPI.dll b/bin/Debug/netcoreapp3.1/BuecherwurmAPI.dll index dc5c540..b0645a9 100644 Binary files a/bin/Debug/netcoreapp3.1/BuecherwurmAPI.dll and b/bin/Debug/netcoreapp3.1/BuecherwurmAPI.dll differ diff --git a/bin/Debug/netcoreapp3.1/BuecherwurmAPI.pdb b/bin/Debug/netcoreapp3.1/BuecherwurmAPI.pdb index 2c890e7..7738b39 100644 Binary files a/bin/Debug/netcoreapp3.1/BuecherwurmAPI.pdb and b/bin/Debug/netcoreapp3.1/BuecherwurmAPI.pdb differ diff --git a/obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.CoreCompileInputs.cache b/obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.CoreCompileInputs.cache index b7c3332..e2e86e8 100644 --- a/obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.CoreCompileInputs.cache +++ b/obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -86b668f90c71d8d1cdd800a49275d51b363153fe +cd0d5b7f5bc2ee5d9b23e69f3956b03d0178fe54 diff --git a/obj/Debug/netcoreapp3.1/BuecherwurmAPI.dll b/obj/Debug/netcoreapp3.1/BuecherwurmAPI.dll index dc5c540..b0645a9 100644 Binary files a/obj/Debug/netcoreapp3.1/BuecherwurmAPI.dll and b/obj/Debug/netcoreapp3.1/BuecherwurmAPI.dll differ diff --git a/obj/Debug/netcoreapp3.1/BuecherwurmAPI.pdb b/obj/Debug/netcoreapp3.1/BuecherwurmAPI.pdb index 2c890e7..7738b39 100644 Binary files a/obj/Debug/netcoreapp3.1/BuecherwurmAPI.pdb and b/obj/Debug/netcoreapp3.1/BuecherwurmAPI.pdb differ