using System.Collections.Generic; using BuecherwurmAPI.Models; using Microsoft.AspNetCore.Mvc; using System.Linq; //using Microsoft.EntityFrameworkCore; namespace BuecherwurmAPI.Controllers { [Route("api/katalog") ] [ApiController] public class KatalogController :ControllerBase { private readonly KatalogModel _repository; public KatalogController (ICatalogue repository) { _repository= (KatalogModel)repository; } // GET Katalog [HttpGet] public ActionResult> GetAllProducts() { var Products =_repository.GetAllProducts(); return Ok(Products); } // POST katalog/buch [HttpPost("buch")] public ActionResult AddProduct(BookPost book) { var id = _repository.AddProduct(book); return Ok(_repository.GetProductById(id)); } // POST katalog/magazin [HttpPost("magazin")] public ActionResult AddProduct(MagazinPost book) { var id = _repository.AddProduct(book); return Ok(_repository.GetProductById(id)); } // GET katalog/{id} [HttpGet("{id}")] public ActionResult GetProductByID(long id) { var book = _repository.GetProductById(id); if (book != null) { return Ok(book); } return NoContent(); } // PUT Katalog/{id} [HttpPut("{id}")] public ActionResult EditProduct(long id, IProduct book) { _repository.EditProduct(id, book); return Ok(book); } // DELETE katalog/{id} [HttpDelete("{id}")] public ActionResult DeleteProduct (long id) { var book = _repository.GetProductById(id); if(book == null) { return NotFound(); } _repository.DeleteProduct(id); return NoContent(); } } }