2020-05-28 12:41:01 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using BuecherwurmAPI.Models;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using System.Linq;
|
2020-06-02 12:23:21 +00:00
|
|
|
using Microsoft.Data.Sqlite;
|
2020-05-28 12:41:01 +00:00
|
|
|
//using Microsoft.EntityFrameworkCore;
|
2020-06-02 09:16:45 +00:00
|
|
|
|
2020-05-28 12:41:01 +00:00
|
|
|
|
|
|
|
namespace BuecherwurmAPI.Controllers
|
|
|
|
{
|
|
|
|
[Route("inventar")]
|
|
|
|
[ApiController]
|
2020-06-02 12:23:21 +00:00
|
|
|
public class ItemController : ControllerBase
|
2020-05-28 12:41:01 +00:00
|
|
|
{
|
2020-05-28 13:22:45 +00:00
|
|
|
private readonly IItemRepo _repository;
|
2020-05-28 12:41:01 +00:00
|
|
|
|
2020-06-02 12:23:21 +00:00
|
|
|
public ItemController(IItemRepo repository)
|
2020-05-28 12:41:01 +00:00
|
|
|
{
|
|
|
|
_repository = repository;
|
|
|
|
}
|
|
|
|
// GET Inventar
|
|
|
|
[HttpGet]
|
|
|
|
public ActionResult<IEnumerable<Item>> GetAllItems()
|
|
|
|
{
|
|
|
|
var items = _repository.GetAllItems();
|
|
|
|
return Ok(items);
|
|
|
|
}
|
|
|
|
|
|
|
|
// POST Inventar
|
|
|
|
[HttpPost]
|
2020-06-02 14:01:17 +00:00
|
|
|
public ActionResult<IEnumerable<Item>> NewItem(ItemPost item)
|
2020-05-28 12:41:01 +00:00
|
|
|
{
|
2020-06-03 06:26:54 +00:00
|
|
|
var newItem = _repository.NewItem(item);
|
|
|
|
return Ok(newItem);
|
2020-05-28 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET Inventar/{id}
|
2020-06-02 14:01:17 +00:00
|
|
|
[HttpGet("{itemId}")]
|
2020-06-03 06:26:54 +00:00
|
|
|
public ActionResult<IEnumerable<Item>> GetItemByID(long id)
|
2020-05-28 12:41:01 +00:00
|
|
|
{
|
|
|
|
var item = _repository.GetItemById(id);
|
|
|
|
if (item != null)
|
|
|
|
{
|
|
|
|
return Ok(item);
|
|
|
|
}
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DELETE inventory/{id}
|
2020-06-02 14:01:17 +00:00
|
|
|
|
|
|
|
[HttpDelete("itemId")]
|
2020-06-03 06:26:54 +00:00
|
|
|
public ActionResult<IEnumerable<Item>> DeleteItem(long itemId)
|
2020-05-28 12:41:01 +00:00
|
|
|
{
|
2020-06-02 14:01:17 +00:00
|
|
|
var item = _repository.GetItemById(itemId);
|
|
|
|
if(item == null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
2020-06-03 06:26:54 +00:00
|
|
|
_repository.DeleteItem(itemId);
|
2020-05-28 12:41:01 +00:00
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|