zwischenstand - nicht funktionstüchtig!
This commit is contained in:
parent
eba2ba64fc
commit
bd0f852d9b
4 changed files with 30 additions and 15 deletions
|
@ -28,7 +28,7 @@ namespace BuecherwurmAPI.Controllers
|
|||
|
||||
// POST Inventar
|
||||
[HttpPost]
|
||||
public ActionResult<IEnumerable<Item>> NewItem(int bookId)
|
||||
public ActionResult<IEnumerable<Item>> NewItem(ItemPost item)
|
||||
{
|
||||
return Ok(new Item
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ namespace BuecherwurmAPI.Controllers
|
|||
|
||||
|
||||
// GET Inventar/{id}
|
||||
[HttpGet("{id}", Name = "GetItemByID")]
|
||||
[HttpGet("{itemId}")]
|
||||
public ActionResult<IEnumerable<Item>> GetItemByID(int id)
|
||||
{
|
||||
var item = _repository.GetItemById(id);
|
||||
|
@ -54,10 +54,11 @@ namespace BuecherwurmAPI.Controllers
|
|||
|
||||
|
||||
// DELETE inventory/{id}
|
||||
[HttpDelete("id")]
|
||||
public ActionResult<IEnumerable<Item>> DeleteItem(int id)
|
||||
|
||||
[HttpDelete("itemId")]
|
||||
public ActionResult<IEnumerable<Item>> DeleteItem(int itemId)
|
||||
{
|
||||
var item = _repository.GetItemById(id);
|
||||
var item = _repository.GetItemById(itemId);
|
||||
if(item == null)
|
||||
{
|
||||
return NotFound();
|
||||
|
|
|
@ -6,8 +6,8 @@ namespace BuecherwurmAPI.Models
|
|||
public interface IItemRepo
|
||||
{
|
||||
IEnumerable<Item> GetAllItems();
|
||||
Item GetItemById(int id);
|
||||
void NewItem(Item item);
|
||||
Item GetItemById(int itemId);
|
||||
void NewItem(ItemPost item);
|
||||
void DeleteItem(Item item);
|
||||
}
|
||||
}
|
|
@ -88,21 +88,24 @@ namespace BuecherwurmAPI.Models
|
|||
}
|
||||
return null;
|
||||
}
|
||||
public Item NewItem(int bookId)
|
||||
public Item NewItem(ItemPost itemPost)
|
||||
{
|
||||
using (var command = _dbConnection.CreateCommand())
|
||||
{
|
||||
//hier soll jetz der NewItem Command folgen. ein POST mit EingabeInfo {id} = "BookId"
|
||||
command.CommandText = @"INSERT INTO Item(ItemId,BookId) OUTPUT INSERTED.ID VALUES (@ItemID,@BookId";
|
||||
command.CommandText = "INSERT INTO Item(BOOKID) VALUES (@item)";
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.Parameters.Add(new SqliteParameter("@ITEMID", itemPost)
|
||||
item;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteItem(Item item)
|
||||
public void DeleteItem(int itemId)
|
||||
{
|
||||
using (var command = _dbConnection.CreateCommand())
|
||||
{
|
||||
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = item;
|
||||
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = itemId;
|
||||
//hier soll jetz der NewItem Command folgen. ein POST mit EingabeInfo {id} = "BookId"
|
||||
|
||||
command.CommandText = @"SELECT * FROM Items WHERE ItemId = @id";
|
||||
|
|
11
Models/ItemPost.cs
Normal file
11
Models/ItemPost.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BuecherwurmAPI.Models
|
||||
{
|
||||
public class ItemPost
|
||||
{
|
||||
[Required]
|
||||
public int BookId { get; set; }
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue