59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using BuecherwurmAPI.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.JsonPatch;
|
|
using Microsoft.Extensions.Logging;
|
|
using BuecherwurmAPI.Models;
|
|
|
|
namespace BuecherwurmAPI.Controllers
|
|
{
|
|
[Route("api/leihvorgang")]
|
|
[ApiController]
|
|
public class LendController : ControllerBase
|
|
{
|
|
private readonly ILendRepo _repository;
|
|
|
|
public LendController(ILendRepo repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
//GET api/leihvorgang
|
|
[HttpGet]
|
|
public ActionResult<IEnumerable<Lend>> LendsGet()
|
|
{
|
|
return Ok(_repository.GetAllLends());
|
|
}
|
|
|
|
//POST api/leihvorgang
|
|
[HttpPost]
|
|
public ActionResult<Lend> LendsPost(Lend lend)
|
|
{
|
|
return Ok(new Lend{Id = lend.Id, Customer = lend.Customer, Returned = lend.Returned, ItemId = lend.ItemId, ReturnDate = lend.ReturnDate});
|
|
}
|
|
|
|
//GET api/leihvorgang/{id}
|
|
[HttpGet("{id}")]
|
|
public ActionResult<Lend> LendById(int id)
|
|
{
|
|
var lend = _repository.GetLendById(id);
|
|
return Ok(lend);
|
|
}
|
|
|
|
//PATCH api/leihvorgang/{id}
|
|
[HttpPatch("{id}")]
|
|
public ActionResult LendPatchById(int id, JsonPatchDocument<Lend> patchDocument)
|
|
{
|
|
var lend = _repository.GetLendById(id);
|
|
if (lend == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|