Skip to content

Commit 4dc88bd

Browse files
committed
Added a SQLite database connection, created the initial version of the model.
- added initial progress of the MarketOrder repository
1 parent 4ffbb66 commit 4dc88bd

File tree

11 files changed

+163
-15
lines changed

11 files changed

+163
-15
lines changed

CryptoTracker.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
EndProject
1313
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptoStatsSource", "CryptoStatsSource\CryptoStatsSource.csproj", "{E4791BC6-E56B-48DA-AE0C-A860FFDB794E}"
1414
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{7C2B472F-EB2B-41D3-ABEF-09714AB46458}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository", "Repository\Repository.csproj", "{058C7D42-A1FF-4212-9732-4F2E2F55A777}"
18+
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Database", "Database\Database.csproj", "{0FAABB54-8CF7-42E5-9971-3B9E2C9AD24C}"
20+
EndProject
1521
Global
1622
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1723
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +32,18 @@ Global
2632
{E4791BC6-E56B-48DA-AE0C-A860FFDB794E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2733
{E4791BC6-E56B-48DA-AE0C-A860FFDB794E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2834
{E4791BC6-E56B-48DA-AE0C-A860FFDB794E}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{7C2B472F-EB2B-41D3-ABEF-09714AB46458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{7C2B472F-EB2B-41D3-ABEF-09714AB46458}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{7C2B472F-EB2B-41D3-ABEF-09714AB46458}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{7C2B472F-EB2B-41D3-ABEF-09714AB46458}.Release|Any CPU.Build.0 = Release|Any CPU
39+
{058C7D42-A1FF-4212-9732-4F2E2F55A777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{058C7D42-A1FF-4212-9732-4F2E2F55A777}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{058C7D42-A1FF-4212-9732-4F2E2F55A777}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{058C7D42-A1FF-4212-9732-4F2E2F55A777}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{0FAABB54-8CF7-42E5-9971-3B9E2C9AD24C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44+
{0FAABB54-8CF7-42E5-9971-3B9E2C9AD24C}.Debug|Any CPU.Build.0 = Debug|Any CPU
45+
{0FAABB54-8CF7-42E5-9971-3B9E2C9AD24C}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{0FAABB54-8CF7-42E5-9971-3B9E2C9AD24C}.Release|Any CPU.Build.0 = Release|Any CPU
2947
EndGlobalSection
3048
GlobalSection(SolutionProperties) = preSolution
3149
HideSolutionNode = FALSE

Database/Database.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<RootNamespace>Database</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="SqlKata.Execution" Version="2.3.2" />
10+
</ItemGroup>
11+
12+
</Project>

Database/SqlKataDatabase.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Data;
3+
using SqlKata.Compilers;
4+
using SqlKata.Execution;
5+
6+
namespace Database
7+
{
8+
public class SqlKataDatabase : IDisposable
9+
{
10+
private readonly QueryFactory _queryFactory;
11+
private readonly IDbConnection _dbConnection;
12+
13+
public SqlKataDatabase(IDbConnection dbConnection, Compiler compiler)
14+
{
15+
_dbConnection = dbConnection;
16+
_queryFactory = new(dbConnection, compiler);
17+
18+
Console.WriteLine("SqlKataDatabase constructor invoked");
19+
}
20+
21+
public QueryFactory Get() => _queryFactory;
22+
23+
public void Dispose()
24+
{
25+
Console.WriteLine("Disposing SqlKataDatabase");
26+
_dbConnection.Close();
27+
}
28+
}
29+
}

Model/Model.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace Model
4+
{
5+
public record MarketOrder(string Symbol, Currency Currency, decimal FilledPrice, decimal Fee, decimal Size,
6+
DateTime Date, bool Buy, int Id = -1, int PortfolioId = -1);
7+
8+
public record Portfolio(string Name, string Description, int Id = -1);
9+
10+
public enum Currency
11+
{
12+
Czk,
13+
Eur,
14+
Usd
15+
}
16+
}

Model/Model.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Model;
2+
3+
namespace Repository.MarketOrders
4+
{
5+
public interface IMarketOrderRepository
6+
{
7+
public void AddMarketOrder(MarketOrder order);
8+
9+
public void UpdateMarketOrder(MarketOrder order);
10+
11+
public void DeleteMarketOrder(MarketOrder order);
12+
}
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Database;
3+
using Model;
4+
5+
namespace Repository.MarketOrders
6+
{
7+
public class SqlKataMarketOrderRepository : IMarketOrderRepository
8+
{
9+
private readonly SqlKataDatabase _db;
10+
11+
public SqlKataMarketOrderRepository(SqlKataDatabase db)
12+
{
13+
_db = db;
14+
}
15+
16+
public void AddMarketOrder(MarketOrder order)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
21+
public void UpdateMarketOrder(MarketOrder order)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
26+
public void DeleteMarketOrder(MarketOrder order)
27+
{
28+
throw new NotImplementedException();
29+
}
30+
}
31+
}

Repository/Repository.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<AssemblyName>Repository</AssemblyName>
6+
<RootNamespace>Repository</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Model\Model.csproj" />
11+
<ProjectReference Include="..\Database\Database.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="5.0.4" />
16+
<PackageReference Include="SqlKata.Execution" Version="2.3.2" />
17+
</ItemGroup>
18+
19+
</Project>

WebFrontend/Program.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ public static void Main(string[] args)
1818

1919
public static IHostBuilder CreateHostBuilder(string[] args) =>
2020
Host.CreateDefaultBuilder(args)
21-
.ConfigureWebHostDefaults(webBuilder =>
22-
{
23-
webBuilder.UseStartup<Startup>();
24-
});
21+
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
2522
}
26-
}
23+
}

WebFrontend/Startup.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1+
using System.Net.Http;
2+
using CryptoStatsSource;
3+
using Database;
14
using Microsoft.AspNetCore.Builder;
2-
using Microsoft.AspNetCore.Components;
35
using Microsoft.AspNetCore.Hosting;
4-
using Microsoft.AspNetCore.HttpsPolicy;
6+
using Microsoft.Data.Sqlite;
57
using Microsoft.Extensions.Configuration;
68
using Microsoft.Extensions.DependencyInjection;
79
using Microsoft.Extensions.Hosting;
810
using ServerSideBlazor.Data;
9-
using System;
10-
using System.Collections.Generic;
11-
using System.Linq;
12-
using System.Net.Http;
13-
using System.Threading.Tasks;
14-
using CryptoStatsSource;
11+
using SqlKata.Compilers;
1512

1613
namespace WebFrontend
1714
{
@@ -32,8 +29,13 @@ public void ConfigureServices(IServiceCollection services)
3229
services.AddRazorPages();
3330
services.AddServerSideBlazor();
3431
services.AddSingleton<WeatherForecastService>();
35-
32+
33+
3634
services.AddScoped<ICryptoStatsSource, CoingeckoSource>();
35+
36+
// TODO ensure that SqlKataDatabase gets disposed
37+
var dbConnection = new SqliteConnection("Data Source=data.db");
38+
services.AddSingleton(ctx => new SqlKataDatabase(dbConnection, new SqliteCompiler()));
3739
}
3840

3941
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -62,4 +64,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6264
});
6365
}
6466
}
65-
}
67+
}

0 commit comments

Comments
 (0)