Merge branch 'InventarDavid' of https://gitea.nek0.eu/nek0/BuecherwurmAPI into InventarDavid
This commit is contained in:
commit
6a0fed4b16
6 changed files with 1113 additions and 0 deletions
1027
.vs/BuecherwurmAPI/config/applicationhost.config
Normal file
1027
.vs/BuecherwurmAPI/config/applicationhost.config
Normal file
File diff suppressed because it is too large
Load diff
BIN
.vs/BuecherwurmAPI/v16/.suo
Normal file
BIN
.vs/BuecherwurmAPI/v16/.suo
Normal file
Binary file not shown.
3
.vs/ProjectSettings.json
Normal file
3
.vs/ProjectSettings.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"CurrentProjectSetting": null
|
||||
}
|
BIN
.vs/slnx.sqlite
Normal file
BIN
.vs/slnx.sqlite
Normal file
Binary file not shown.
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 IBookRepo _repository;
|
||||
|
||||
public InventarController(IBookRepo 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 = book.ProductId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
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; }
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue