Browse Source

zwischenstand - nicht funktionstüchtig!

David
David Renner 2 years ago
parent
commit
bd0f852d9b
  1. 19
      Controllers/ItemController.cs
  2. 4
      Models/IItemRepo.cs
  3. 11
      Models/ItemModel.cs
  4. 11
      Models/ItemPost.cs

19
Controllers/ItemController.cs

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

4
Models/IItemRepo.cs

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

11
Models/ItemModel.cs

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

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