2020-05-29 10:12:09 +00:00
|
|
|
using System;
|
2020-05-28 08:55:56 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using AutoMapper;
|
2020-06-02 09:16:45 +00:00
|
|
|
using BuecherwurmAPI.Models;
|
2020-05-28 08:55:56 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.JsonPatch;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-06-03 07:26:07 +00:00
|
|
|
using Microsoft.Data.Sqlite;
|
2020-05-28 08:55:56 +00:00
|
|
|
|
|
|
|
namespace BuecherwurmAPI.Controllers
|
|
|
|
{
|
|
|
|
[Route("api/leihvorgang")]
|
|
|
|
[ApiController]
|
|
|
|
public class LendController : ControllerBase
|
|
|
|
{
|
2020-06-03 07:26:07 +00:00
|
|
|
private readonly LendModel _repository;
|
2020-06-03 09:34:12 +00:00
|
|
|
//private readonly IMapper _mapper;
|
2020-05-29 10:12:09 +00:00
|
|
|
|
2020-06-03 09:34:12 +00:00
|
|
|
public LendController(ILend repo)
|
2020-05-28 08:55:56 +00:00
|
|
|
{
|
2020-06-03 08:45:54 +00:00
|
|
|
_repository = (LendModel)repo;
|
2020-06-03 09:34:12 +00:00
|
|
|
//_mapper = mapper;
|
2020-05-28 08:55:56 +00:00
|
|
|
}
|
2020-05-29 10:12:09 +00:00
|
|
|
|
2020-05-28 08:55:56 +00:00
|
|
|
//GET api/leihvorgang
|
|
|
|
[HttpGet]
|
|
|
|
public ActionResult<IEnumerable<Lend>> LendsGet()
|
|
|
|
{
|
|
|
|
return Ok(_repository.GetAllLends());
|
|
|
|
}
|
2020-05-29 10:12:09 +00:00
|
|
|
|
2020-05-28 08:55:56 +00:00
|
|
|
//POST api/leihvorgang
|
|
|
|
[HttpPost]
|
2020-06-03 08:55:39 +00:00
|
|
|
public ActionResult<LendPost> LendsPost(LendPost lend)
|
2020-05-28 08:55:56 +00:00
|
|
|
{
|
2020-06-03 07:26:07 +00:00
|
|
|
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
|
2020-05-28 08:55:56 +00:00
|
|
|
{
|
2020-06-03 07:26:07 +00:00
|
|
|
return BadRequest();
|
|
|
|
}
|
2020-05-28 08:55:56 +00:00
|
|
|
//return Ok(_mapper.Map<LendReadDTO>(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
//GET api/leihvorgang/{id}
|
|
|
|
[HttpGet("{id}")]
|
2020-05-29 09:18:23 +00:00
|
|
|
public ActionResult<Lend> LendById(long id)
|
2020-05-28 08:55:56 +00:00
|
|
|
{
|
|
|
|
var lend = _repository.GetLendById(id);
|
2020-05-29 09:18:23 +00:00
|
|
|
if (!_repository.IdExits(Tables.Table.Lends, id))
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
2020-05-28 08:55:56 +00:00
|
|
|
|
2020-05-29 09:52:57 +00:00
|
|
|
return Ok(lend);
|
|
|
|
}
|
|
|
|
|
|
|
|
//PATCH api/leihvorgang/{id}
|
|
|
|
[HttpPatch("{id}")]
|
|
|
|
public ActionResult LendPatchById(int id, JsonPatchDocument<Lend> patchDocument)
|
|
|
|
{
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 10:12:09 +00:00
|
|
|
}
|