From 4afdb44e920592eab474f0bd7342b2b03d7f0252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=B6nbach?= Date: Wed, 27 May 2020 14:31:46 +0200 Subject: [PATCH] =?UTF-8?q?LendController=20um=20weitere=20Methoden=20erg?= =?UTF-8?q?=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BuecherwurmAPI.csproj | 4 ++++ Controllers/LendController.cs | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/BuecherwurmAPI.csproj b/BuecherwurmAPI.csproj index 400722f..fdec702 100644 --- a/BuecherwurmAPI.csproj +++ b/BuecherwurmAPI.csproj @@ -4,5 +4,9 @@ netcoreapp3.1 + + + + diff --git a/Controllers/LendController.cs b/Controllers/LendController.cs index 40f02fc..559ef27 100644 --- a/Controllers/LendController.cs +++ b/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> GetAllLends() + public ActionResult> LendsGet() { - var lends = _repository.GetAllLends(); - return Ok(lends); + return Ok(_repository.GetAllLends()); + } + + //POST api/leihvorgang + [HttpPost] + public ActionResult 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 GetLend(int id) + public ActionResult LendById(int id) { var lend = _repository.GetLendById(id); return Ok(lend); } + + //PATCH api/leihvorgang/{id} + [HttpPatch("{id}")] + public ActionResult LendPatchById(int id, JsonPatchDocument patchDocument) + { + var lend = _repository.GetLendById(id); + if (lend == null) + { + return NotFound(); + } + return Ok(); + } } }