diff --git a/BuecherwurmAPI.csproj b/BuecherwurmAPI.csproj
index cfb35fd..f1755c4 100644
--- a/BuecherwurmAPI.csproj
+++ b/BuecherwurmAPI.csproj
@@ -7,6 +7,14 @@
+
+
+
+
+
+
+ Always
+
diff --git a/Controllers/LendController.cs b/Controllers/LendController.cs
index 136b429..40cdc93 100644
--- a/Controllers/LendController.cs
+++ b/Controllers/LendController.cs
@@ -16,10 +16,10 @@ namespace BuecherwurmAPI.Controllers
[ApiController]
public class LendController : ControllerBase
{
- private readonly ILendRepo _repository;
+ private readonly IRepository _repository;
private readonly IMapper _mapper;
- public LendController(ILendRepo repository, IMapper mapper)
+ public LendController(IRepository repository, IMapper mapper)
{
_repository = repository;
_mapper = mapper;
diff --git a/Data/IRepository.cs b/Data/IRepository.cs
index e69de29..d8cc2dd 100644
--- a/Data/IRepository.cs
+++ b/Data/IRepository.cs
@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+using BuecherwurmAPI.Models;
+
+namespace BuecherwurmAPI.Data
+{
+ public interface IRepository
+ {
+ IEnumerable GetAllLends();
+ Lend GetLendById(int id);
+ }
+}
\ No newline at end of file
diff --git a/Data/Repository.cs b/Data/Repository.cs
index e69de29..162a540 100644
--- a/Data/Repository.cs
+++ b/Data/Repository.cs
@@ -0,0 +1,51 @@
+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 GetAllLends()
+ {
+ var lends = new List();
+
+ // 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};
+ }
+ }
+}
\ No newline at end of file
diff --git a/LongWormMemory.db b/LongWormMemory.db
new file mode 100644
index 0000000..4b1deb5
Binary files /dev/null and b/LongWormMemory.db differ
diff --git a/Models/Lend.cs b/Models/Lend.cs
index b740853..4be118e 100644
--- a/Models/Lend.cs
+++ b/Models/Lend.cs
@@ -4,8 +4,8 @@ namespace BuecherwurmAPI.Models
{
public class Lend
{
- public int Id { get; set; }
- public int ItemId { get; set;}
+ public long Id { get; set; }
+ public long ItemId { get; set;}
public DateTime ReturnDate { get; set; }
public string Customer { get; set; }
public bool Returned { get; set; }
diff --git a/Startup.cs b/Startup.cs
index d9a3ef4..8e8c8dc 100644
--- a/Startup.cs
+++ b/Startup.cs
@@ -32,7 +32,7 @@ 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();
+ services.AddScoped();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
}