Added all projects

We are almost working.
This commit is contained in:
2026-07-13 17:29:43 +02:00
parent 7bcb1802af
commit bf16b7b807
20 changed files with 322 additions and 52 deletions
@@ -0,0 +1,25 @@
using FinancialApi.Application;
using FinancialApi.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace FinancialApi;
public static class ApplyFeeHandler
{
public static Task<Account?> LoadAsync(ApplyFeeCommand cmd, AccountDbContext db)
=> db.Set<Account>().AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == cmd.AccountId);
public static (Account UpdatedAccount, FeeAppliedEvent Event) Handle(ApplyFeeCommand cmd, Account account)
{
var updatedAccount = account.ApplyFee(cmd.Amount);
var @event = new FeeAppliedEvent(account.Id, cmd.Amount);
return (updatedAccount, @event);
}
}
public record ApplyFeeCommand(int AccountId, decimal Amount);
public record FeeAppliedEvent(int AccountId, decimal Amount);
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.9"/>
<PackageReference Include="Microsoft.OpenApi" Version="2.10.0" />
<PackageReference Include="WolverineFx" Version="6.17.3" />
<PackageReference Include="WolverineFx.Http" Version="6.17.3" />
<PackageReference Include="WolverineFx.RuntimeCompilation" Version="6.17.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FinancialApi.Infrastructure\FinancialApi.Infrastructure.csproj" />
<ProjectReference Include="..\FinancialApi.ServiceDefaults\FinancialApi.ServiceDefaults.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,17 @@
@FinancialApi_HostAddress = https://localhost:7010
GET {{FinancialApi_HostAddress}}/weatherforecast/
Accept: application/json
###
POST {{FinancialApi_HostAddress}}/accounts/apply-fee
Accept: application/json
Content-Type: application/json
{
"accountId": 1,
"amount": 5.0
}
###
@@ -0,0 +1,50 @@
using FinancialApi;
using FinancialApi.Infrastructure;
using FinancialApi.ServiceDefaults;
using JasperFx.CodeGeneration;
using Microsoft.EntityFrameworkCore;
using Wolverine;
using Wolverine.EntityFrameworkCore;
using Wolverine.Sqlite;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AccountDbContext>(options =>
options.UseSqlite("Data Source=demo.db"));
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.AddServiceDefaults();
builder.Host.UseWolverine(opts =>
{
opts.PersistMessagesWithSqlite("Data Source=demo.db");
opts.UseEntityFrameworkCoreTransactions();
});
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AccountDbContext>();
await db.Database.MigrateAsync();
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.MapPost("/accounts/apply-fee", async (ApplyFeeCommand cmd, IMessageBus bus) =>
{
await bus.InvokeAsync(cmd);
return Results.Accepted();
});
app.Run();
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5115",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7010;http://localhost:5115",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Binary file not shown.