Browse Source

LendController um weitere Methoden ergänzt

ControllerJonas
Jonas Schönbach 2 years ago
parent
commit
4afdb44e92
  1. 4
      BuecherwurmAPI.csproj
  2. 31
      Controllers/LendController.cs

4
BuecherwurmAPI.csproj

@ -4,5 +4,9 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
</ItemGroup>
</Project>

31
Controllers/LendController.cs

@ -4,6 +4,7 @@ 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;
@ -13,27 +14,45 @@ namespace BuecherwurmAPI.Controllers
[ApiController]
public class LendController : ControllerBase
{
private ILendRepo _repository;
private readonly ILendRepo _repository;
public LendController(ILendRepo repository)
{
_repository = repository;
}
//GET api/leihvorgang/
//GET api/leihvorgang
[HttpGet]
public ActionResult<IEnumerable<Lend>> GetAllLends()
public ActionResult<IEnumerable<Lend>> LendsGet()
{
var lends = _repository.GetAllLends();
return Ok(lends);
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> GetLend(int 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();
}
}
}

Loading…
Cancel
Save