zwischenstand - nicht funktionstüchtig!

This commit is contained in:
David Renner 2020-06-02 16:01:17 +02:00
parent eba2ba64fc
commit bd0f852d9b
4 changed files with 30 additions and 15 deletions

View File

@ -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,14 +54,15 @@ 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);
if (item == null)
{
return NotFound();
}
var item = _repository.GetItemById(itemId);
if(item == null)
{
return NotFound();
}
_repository.DeleteItem(item);
return NoContent();
}

View File

@ -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);
}
}

View File

@ -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
View File

@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace BuecherwurmAPI.Models
{
public class ItemPost
{
[Required]
public int BookId { get; set; }
}
}