using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AutoMapper; using BuecherwurmAPI.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.JsonPatch; using Microsoft.Extensions.Logging; using Microsoft.Data.Sqlite; namespace BuecherwurmAPI.Controllers { [Route("api/leihvorgang")] [ApiController] public class LendController : ControllerBase { private readonly LendModel _repository; //private readonly IMapper _mapper; public LendController(ILend repo) { _repository = (LendModel)repo; //_mapper = mapper; } //GET api/leihvorgang [HttpGet] public ActionResult> LendsGet() { return Ok(_repository.GetAllLends()); } //POST api/leihvorgang [HttpPost] public ActionResult LendsPost(LendPost lend) { var newId = _repository.insertLendReturningId(lend); if (newId > 0) { var item = new Lend { Id = newId, Customer = lend.Customer, Returned = false, ItemId = lend.ItemId, ReturnDate = lend.ReturnDate }; return Ok(item); } else { return BadRequest(); } //return Ok(_mapper.Map(item)); } //GET api/leihvorgang/{id} [HttpGet("{id}")] public ActionResult LendById(long id) { var lend = _repository.GetLendById(id); if (!_repository.IdExits(Tables.Table.Lends, id)) { return NotFound(); } return Ok(lend); } //PATCH api/leihvorgang/{id} [HttpPatch("{id}")] public ActionResult LendPatchById(int id, JsonPatchDocument patchDocument) { return Ok(); } } }