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.
BuecherwurmAPI/Controllers/InventarController.cs

69 lines
1.7 KiB

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 IBookRepo _repository;
public InventarController(IBookRepo repository)
{
_repository = repository;
}
// GET Inventar
[HttpGet]
public ActionResult<IEnumerable<Copy>> GetAllCopies()
{
var copies = _repository.GetAllCopies();
return Ok(copies);
}
// POST Inventar
[HttpPost]
public ActionResult<IEnumerable<Copy>> NeuesExemplar(Copy copy)
{
return Ok(new Copy
{
CopyId = copy.CopyId,
ProductId = book.ProductId,
});
}
// GET Inventar/{id}
[HttpGet("{id}", Name = "GetCopyByID")]
public ActionResult<IEnumerable<Copy>> GetCopyByID(int id)
{
var copy = _repository.GetCopyById(id);
if (copy != null)
{
return Ok(copy);
}
return NoContent();
}
// DELETE inventory/{id}
[HttpDelete("id")]
public ActionResult<IEnumerable<Copy>> ExemplarEntfernen(int id)
{
var copy = _repository.GetCopyById(id);
if (copy == null)
{
return NotFound();
}
_repository.ExemplarEntfernen(copy);
return NoContent();
}
}
}