API zum verleihen von Medien
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.2 KiB

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<IEnumerable<Lend>> LendsGet()
{
return Ok(_repository.GetAllLends());
}
//POST api/leihvorgang
[HttpPost]
public ActionResult<LendPost> LendsPost(LendPost lend)
{
var newId = _repository.AddLend(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<LendReadDTO>(item));
}
//GET api/leihvorgang/{id}
[HttpGet("{id}")]
public ActionResult<Lend> LendById(long id)
{
var lend = _repository.GetLendById(id);
if (!_repository.IdExits(Tables.Table.Lends, id))
{
return NotFound();
}
return Ok(lend);
}
//PUT api/leihvorgang/{id}
[HttpPut("{id}")]
public ActionResult LendPatchById(long id, LendPost lend)
{
var lendPatch = _repository.insertLendReturningId(id, lend);
return Ok(lendPatch);
}
}
}