API zum verleihen von Medien
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB

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<IEnumerable<IProduct>> GetAllProducts()
{
var Products =_repository.GetAllProducts();
return Ok(Products);
}
// POST katalog/buch
[HttpPost("buch")]
public ActionResult<Book> AddProduct(BookPost book)
{
var id = _repository.AddProduct(book);
return Ok(_repository.GetProductById(id));
}
// POST katalog/magazin
[HttpPost("magazin")]
public ActionResult<Magazin> AddProduct(MagazinPost book)
{
var id = _repository.AddProduct(book);
return Ok(_repository.GetProductById(id));
}
// GET katalog/{id}
[HttpGet("{id}")]
public ActionResult <IProduct> GetProductByID(long id)
{
var book = _repository.GetProductById(id);
if (book != null)
{
return Ok(book);
}
return NoContent();
}
// PUT Katalog/{id}
[HttpPut("{id}")]
public ActionResult<IProduct> EditProduct(long id, IProduct book)
{
_repository.EditProduct(id, book);
return Ok(book);
}
// DELETE katalog/{id}
[HttpDelete("{id}")]
public ActionResult<IProduct> DeleteProduct (long id)
{
var book = _repository.GetProductById(id);
if(book == null)
{
return NotFound();
}
_repository.DeleteProduct(id);
return NoContent();
}
}
}