Compare commits
No commits in common. "41a53631dddafd7b47840dc1db918daedb4bccd5" and "22e87cd58acb46c59a7c46bac1d9b41c8e6930aa" have entirely different histories.
41a53631dd
...
22e87cd58a
|
@ -7,14 +7,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.4" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="LongWormMemory.db" />
|
|
||||||
<Resource Include="LongWormMemory.db">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Resource>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ namespace BuecherwurmAPI.Controllers
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class LendController : ControllerBase
|
public class LendController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IRepository _repository;
|
private readonly ILendRepo _repository;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public LendController(IRepository repository, IMapper mapper)
|
public LendController(ILendRepo repository, IMapper mapper)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using BuecherwurmAPI.Models;
|
|
||||||
|
|
||||||
namespace BuecherwurmAPI.Data
|
|
||||||
{
|
|
||||||
public interface IRepository
|
|
||||||
{
|
|
||||||
IEnumerable<Lend> GetAllLends();
|
|
||||||
Lend GetLendById(int id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BuecherwurmAPI.Models;
|
|
||||||
using Microsoft.Data.Sqlite;
|
|
||||||
|
|
||||||
namespace BuecherwurmAPI.Data
|
|
||||||
{
|
|
||||||
internal class Repository : IRepository
|
|
||||||
{
|
|
||||||
private SqliteConnection _dbConnection;
|
|
||||||
|
|
||||||
public Repository()
|
|
||||||
{
|
|
||||||
var connectionBuilder = new SqliteConnectionStringBuilder {DataSource = "LongWormMemory.db"};
|
|
||||||
_dbConnection = new SqliteConnection(connectionBuilder.ConnectionString);
|
|
||||||
_dbConnection.Open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Lend> GetAllLends()
|
|
||||||
{
|
|
||||||
var lends = new List<Lend>();
|
|
||||||
|
|
||||||
// using automatically disposes the command after completion
|
|
||||||
using (var command = _dbConnection.CreateCommand())
|
|
||||||
{
|
|
||||||
command.CommandText = @"SELECT * FROM Lends";
|
|
||||||
var dataReader = command.ExecuteReader();
|
|
||||||
|
|
||||||
while (dataReader.Read())
|
|
||||||
{
|
|
||||||
var returned = (long) dataReader["Returned"] == 0;
|
|
||||||
|
|
||||||
lends.Add(new Lend
|
|
||||||
{
|
|
||||||
Id = (long) dataReader["Id"],
|
|
||||||
Customer = (string) dataReader["Customer"],
|
|
||||||
ItemId = (long) dataReader["ItemId"],
|
|
||||||
Returned = !returned,
|
|
||||||
ReturnDate = DateTime.Parse((string)dataReader["ReturnDate"])
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lends;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lend GetLendById(int id)
|
|
||||||
{
|
|
||||||
return new Lend{Id = 1, Customer = "Nek0", ItemId = 1337, Returned = false, ReturnDate = DateTime.Now};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
|
@ -4,8 +4,8 @@ namespace BuecherwurmAPI.Models
|
||||||
{
|
{
|
||||||
public class Lend
|
public class Lend
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public int Id { get; set; }
|
||||||
public long ItemId { get; set;}
|
public int ItemId { get; set;}
|
||||||
public DateTime ReturnDate { get; set; }
|
public DateTime ReturnDate { get; set; }
|
||||||
public string Customer { get; set; }
|
public string Customer { get; set; }
|
||||||
public bool Returned { get; set; }
|
public bool Returned { get; set; }
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace BuecherwurmAPI
|
||||||
// Adds a service that is created once per connection.
|
// Adds a service that is created once per connection.
|
||||||
// It takes an interface and a specific implementation.
|
// It takes an interface and a specific implementation.
|
||||||
// That allows to swap the implementation easily.
|
// That allows to swap the implementation easily.
|
||||||
services.AddScoped<IRepository, Repository>();
|
services.AddScoped<ILendRepo, MockLendRepo>();
|
||||||
|
|
||||||
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue