LendController um weitere Methoden ergänzt
This commit is contained in:
parent
1c8ec4b517
commit
4afdb44e92
2 changed files with 29 additions and 6 deletions
|
@ -4,5 +4,9 @@
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BuecherwurmAPI.Data;
|
using BuecherwurmAPI.Data;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.JsonPatch;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using BuecherwurmAPI.Models;
|
using BuecherwurmAPI.Models;
|
||||||
|
|
||||||
|
@ -13,27 +14,45 @@ namespace BuecherwurmAPI.Controllers
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class LendController : ControllerBase
|
public class LendController : ControllerBase
|
||||||
{
|
{
|
||||||
private ILendRepo _repository;
|
private readonly ILendRepo _repository;
|
||||||
|
|
||||||
public LendController(ILendRepo repository)
|
public LendController(ILendRepo repository)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GET api/leihvorgang/
|
//GET api/leihvorgang
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ActionResult<IEnumerable<Lend>> GetAllLends()
|
public ActionResult<IEnumerable<Lend>> LendsGet()
|
||||||
{
|
{
|
||||||
var lends = _repository.GetAllLends();
|
return Ok(_repository.GetAllLends());
|
||||||
return Ok(lends);
|
}
|
||||||
|
|
||||||
|
//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}
|
//GET api/leihvorgang/{id}
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public ActionResult<Lend> GetLend(int id)
|
public ActionResult<Lend> LendById(int id)
|
||||||
{
|
{
|
||||||
var lend = _repository.GetLendById(id);
|
var lend = _repository.GetLendById(id);
|
||||||
return Ok(lend);
|
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…
Reference in a new issue