Browse Source

reviewed, debugged and meowed with items

Amedeo
nek0 11 months ago
parent
commit
56e1cc1452
8 changed files with 24 additions and 27 deletions
  1. +2
    -2
      Controllers/ItemController.cs
  2. +3
    -4
      Controllers/LendController.cs
  3. BIN
      LongWormMemory.db
  4. +0
    -9
      Models/Interfaces.cs
  5. +8
    -6
      Models/ItemModel.cs
  6. +8
    -2
      Models/LendModel.cs
  7. +1
    -2
      Profiles/LendProfile.cs
  8. +2
    -2
      Startup.cs

+ 2
- 2
Controllers/ItemController.cs View File

@ -14,7 +14,7 @@ namespace BuecherwurmAPI.Controllers
{
private readonly ItemModel _repository;
public ItemController(IModel repository)
public ItemController(IItem repository)
{
_repository = (ItemModel)repository;
}
@ -50,7 +50,7 @@ namespace BuecherwurmAPI.Controllers
// DELETE api/inventar/{id}
[HttpDelete("itemId")]
[HttpDelete("{itemId}")]
public ActionResult<IEnumerable<Item>> DeleteItem(long itemId)
{
var item = _repository.GetItemById(itemId);


+ 3
- 4
Controllers/LendController.cs View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using BuecherwurmAPI.Models;
using BuecherwurmAPI.DTOs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.Extensions.Logging;
@ -17,12 +16,12 @@ namespace BuecherwurmAPI.Controllers
public class LendController : ControllerBase
{
private readonly LendModel _repository;
private readonly IMapper _mapper;
//private readonly IMapper _mapper;
public LendController(IModel repo, IMapper mapper)
public LendController(ILend repo)
{
_repository = (LendModel)repo;
_mapper = mapper;
//_mapper = mapper;
}
//GET api/leihvorgang


BIN
LongWormMemory.db View File


+ 0
- 9
Models/Interfaces.cs View File

@ -1,9 +0,0 @@
using Microsoft.Data.Sqlite;
namespace BuecherwurmAPI.Models
{
public interface IModel
{
}
}

+ 8
- 6
Models/ItemModel.cs View File

@ -6,7 +6,12 @@ using Microsoft.VisualBasic.CompilerServices;
namespace BuecherwurmAPI.Models
{
internal class ItemModel : IModel
public interface IItem
{
}
internal class ItemModel : IItem
{
private SqliteConnection _dbConnection;
@ -49,7 +54,7 @@ namespace BuecherwurmAPI.Models
// using automatically disposes the command after completion
using (var command = _dbConnection.CreateCommand())
{
command.CommandText = "SELECT FROM Items";
command.CommandText = "SELECT * FROM Items";
var dataReader = command.ExecuteReader();
while (dataReader.Read())
@ -71,13 +76,11 @@ namespace BuecherwurmAPI.Models
using (var command = _dbConnection.CreateCommand())
{
command.Parameters.Add(new SqliteParameter("@itemId", itemId));
command.CommandText = "SELECT FROM Items WHERE Id = @itemId";
command.CommandText = "SELECT * FROM Items WHERE ItemId = @itemId";
var dataReader = command.ExecuteReader();
while (dataReader.Read())
{
var returned = (long) dataReader["Returned"] == 1;
var item = new Item
{
ItemId = (long) dataReader["ItemId"],
@ -111,7 +114,6 @@ namespace BuecherwurmAPI.Models
{
using (var command = _dbConnection.CreateCommand())
{
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = itemId;
command.CommandText = "DELETE FROM Items WHERE ItemId = @itemId";
command.Parameters.Add(new SqliteParameter("@itemId", itemId));
command.ExecuteNonQuery();


+ 8
- 2
Models/LendModel.cs View File

@ -6,9 +6,15 @@ using Microsoft.VisualBasic.CompilerServices;
namespace BuecherwurmAPI.Models
{
internal class LendModel : IModel
public interface ILend
{
}
internal class LendModel : ILend
{
public SqliteConnection _dbConnection;
private SqliteConnection _dbConnection;
public LendModel()
{


+ 1
- 2
Profiles/LendProfile.cs View File

@ -1,5 +1,4 @@
using AutoMapper;
using BuecherwurmAPI.DTOs;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Profiles
@ -8,7 +7,7 @@ namespace BuecherwurmAPI.Profiles
{
public LendProfile()
{
CreateMap<Lend, LendReadDTO>();
CreateMap<Lend, LendPost>();
}
}
}

+ 2
- 2
Startup.cs View File

@ -32,8 +32,8 @@ namespace BuecherwurmAPI
// Adds a service that is created once per connection.
// It takes an interface and a specific implementation.
// That allows to swap the implementation easily.
services.AddScoped<IModel, LendModel>();
services.AddScoped<IModel, ItemModel>();
services.AddScoped<ILend, LendModel>();
services.AddScoped<IItem, ItemModel>();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
}


Loading…
Cancel
Save