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 // POST Inventar
[HttpPost] [HttpPost]
public ActionResult<IEnumerable<Item>> NewItem(int bookId) public ActionResult<IEnumerable<Item>> NewItem(ItemPost item)
{ {
return Ok(new Item return Ok(new Item
{ {
@ -40,7 +40,7 @@ namespace BuecherwurmAPI.Controllers
// GET Inventar/{id} // GET Inventar/{id}
[HttpGet("{id}", Name = "GetItemByID")] [HttpGet("{itemId}")]
public ActionResult<IEnumerable<Item>> GetItemByID(int id) public ActionResult<IEnumerable<Item>> GetItemByID(int id)
{ {
var item = _repository.GetItemById(id); var item = _repository.GetItemById(id);
@ -54,14 +54,15 @@ namespace BuecherwurmAPI.Controllers
// DELETE inventory/{id} // 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) if(item == null)
{ {
return NotFound(); return NotFound();
} }
_repository.DeleteItem(item); _repository.DeleteItem(item);
return NoContent(); return NoContent();
} }

View file

@ -6,8 +6,8 @@ namespace BuecherwurmAPI.Models
public interface IItemRepo public interface IItemRepo
{ {
IEnumerable<Item> GetAllItems(); IEnumerable<Item> GetAllItems();
Item GetItemById(int id); Item GetItemById(int itemId);
void NewItem(Item item); void NewItem(ItemPost item);
void DeleteItem(Item item); void DeleteItem(Item item);
} }
} }

View file

@ -88,21 +88,24 @@ namespace BuecherwurmAPI.Models
} }
return null; return null;
} }
public Item NewItem(int bookId) public Item NewItem(ItemPost itemPost)
{ {
using (var command = _dbConnection.CreateCommand()) using (var command = _dbConnection.CreateCommand())
{ {
//hier soll jetz der NewItem Command folgen. ein POST mit EingabeInfo {id} = "BookId" //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; return item;
} }
} }
public void DeleteItem(Item item) public void DeleteItem(int itemId)
{ {
using (var command = _dbConnection.CreateCommand()) 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" //hier soll jetz der NewItem Command folgen. ein POST mit EingabeInfo {id} = "BookId"
command.CommandText = @"SELECT * FROM Items WHERE ItemId = @id"; 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; }
}
}