Added InventarController, IInventarRepo and Item
This commit is contained in:
parent
c7085081cb
commit
8bdc964d01
8 changed files with 96 additions and 1 deletions
69
Controllers/InventarController.cs
Normal file
69
Controllers/InventarController.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System.Collections.Generic;
|
||||
using BuecherwurmAPI.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
using BuecherwurmAPI.Data;
|
||||
|
||||
namespace BuecherwurmAPI.Controllers
|
||||
{
|
||||
[Route("inventar")]
|
||||
[ApiController]
|
||||
public class InventarController : ControllerBase
|
||||
{
|
||||
private readonly IInventarRepo _repository;
|
||||
|
||||
public InventarController(IInventarRepo repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
// GET Inventar
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<Item>> GetAllItems()
|
||||
{
|
||||
var items = _repository.GetAllItems();
|
||||
return Ok(items);
|
||||
}
|
||||
|
||||
// POST Inventar
|
||||
[HttpPost]
|
||||
public ActionResult<IEnumerable<Item>> NewItem(Item item)
|
||||
{
|
||||
return Ok(new Item
|
||||
{
|
||||
Id = item.Id,
|
||||
BookId = item.BookId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// GET Inventar/{id}
|
||||
[HttpGet("{id}", Name = "GetItemByID")]
|
||||
public ActionResult<IEnumerable<Item>> GetItemByID(int id)
|
||||
{
|
||||
var item = _repository.GetItemById(id);
|
||||
if (item != null)
|
||||
{
|
||||
return Ok(item);
|
||||
}
|
||||
return NoContent();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// DELETE inventory/{id}
|
||||
[HttpDelete("id")]
|
||||
public ActionResult<IEnumerable<Item>> DeleteItem(int id)
|
||||
{
|
||||
var item = _repository.GetItemById(id);
|
||||
if (item == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
_repository.DeleteItem(item);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
12
Data/IInventarRepo.cs
Normal file
12
Data/IInventarRepo.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using BuecherwurmAPI.Models;
|
||||
|
||||
namespace BuecherwurmAPI.Data
|
||||
{
|
||||
public interface IInventarRepo
|
||||
{
|
||||
IEnumerable<Item> GetAllItems();
|
||||
Item GetItemById(int id);
|
||||
void DeleteItem(Item item);
|
||||
}
|
||||
}
|
14
Models/Item.cs
Normal file
14
Models/Item.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BuecherwurmAPI.Models
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
[Key]
|
||||
[Required]
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int BookId { get; set; }
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
86b668f90c71d8d1cdd800a49275d51b363153fe
|
||||
cd0d5b7f5bc2ee5d9b23e69f3956b03d0178fe54
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue