Added a-frame-architecture usiung wolverine sample.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using FinancialApi.Domain.Exceptions;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FinancialApi;
|
||||
|
||||
public class DomainExceptionHandler : IExceptionHandler
|
||||
{
|
||||
public async ValueTask<bool> TryHandleAsync(
|
||||
HttpContext httpContext,
|
||||
Exception exception,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
if (exception is not (InvalidOperationException or ArgumentException or GaapViolationException))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var problemDetails = new ProblemDetails
|
||||
{
|
||||
Status = StatusCodes.Status400BadRequest,
|
||||
Title = "Domain Validation Error",
|
||||
Detail = exception.Message,
|
||||
Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1"
|
||||
};
|
||||
|
||||
httpContext.Response.StatusCode = problemDetails.Status.Value;
|
||||
await httpContext.Response.WriteAsJsonAsync(problemDetails, cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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.18.0"/>
|
||||
<PackageReference Include="WolverineFx.Http" Version="6.18.0"/>
|
||||
<PackageReference Include="WolverineFx.RuntimeCompilation" Version="6.18.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FinancialApi.Infrastructure\FinancialApi.Infrastructure.csproj"/>
|
||||
<ProjectReference Include="..\FinancialApi.ServiceDefaults\FinancialApi.ServiceDefaults.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,38 @@
|
||||
@FinancialApi_HostAddress = https://localhost:7010
|
||||
|
||||
### Apply Fee to an Account
|
||||
|
||||
POST {{FinancialApi_HostAddress}}/accounts/apply-fee
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"accountId": 2,
|
||||
"amount": 100
|
||||
}
|
||||
|
||||
### Transfer Between Accounts
|
||||
|
||||
POST {{FinancialApi_HostAddress}}/accounts/transfer
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"sourceAccountId": 1,
|
||||
"destinationAccountId": 2,
|
||||
"amount": 1000.00
|
||||
}
|
||||
|
||||
### Reverse a Journal Entry
|
||||
|
||||
POST {{FinancialApi_HostAddress}}/journal/reverse
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"originalJournalId": "E7FB25DB-406F-4063-A4B0-DE6BB8292437",
|
||||
"reason": "Incorrect Account Fee"
|
||||
}
|
||||
|
||||
### Events
|
||||
|
||||
GET {{FinancialApi_HostAddress}}/events
|
||||
Content-Type: application/json
|
||||
@@ -0,0 +1,103 @@
|
||||
using FinancialApi;
|
||||
using FinancialApi.Application.Commands;
|
||||
using FinancialApi.Application.Handlers;
|
||||
using FinancialApi.Application.Interfaces;
|
||||
using FinancialApi.Domain.Events;
|
||||
using FinancialApi.Infrastructure;
|
||||
using FinancialApi.ServiceDefaults;
|
||||
using JasperFx.Resources;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Wolverine;
|
||||
using Wolverine.EntityFrameworkCore;
|
||||
using Wolverine.Sqlite;
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddExceptionHandler<DomainExceptionHandler>();
|
||||
builder.Services.AddProblemDetails();
|
||||
|
||||
var connectionString = "Data Source=demo.db";
|
||||
|
||||
builder.Services.AddDbContext<AccountDbContext>(options => options.UseSqlite(connectionString));
|
||||
|
||||
builder.Services.AddScoped<IAccountQuery, AccountQuery>();
|
||||
builder.Services.AddScoped<IReversalQuery, ReversalQuery>();
|
||||
builder.Services.AddSingleton<IEventTracker, DemoEventStore>();
|
||||
|
||||
// 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.Discovery.IncludeAssembly(typeof(DemoEventStore).Assembly);
|
||||
opts.Discovery.IncludeAssembly(typeof(ApplyFeeHandler).Assembly);
|
||||
opts.PersistMessagesWithSqlite(connectionString);
|
||||
opts.UseEntityFrameworkCoreTransactions();
|
||||
opts.Policies.AutoApplyTransactions();
|
||||
}
|
||||
);
|
||||
builder.Host.UseResourceSetupOnStartup();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseExceptionHandler();
|
||||
|
||||
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.MapPost(
|
||||
"/accounts/transfer",
|
||||
async (TransferFundsCommand cmd, IMessageBus bus) =>
|
||||
{
|
||||
await bus.InvokeAsync(cmd);
|
||||
return Results.Accepted();
|
||||
}
|
||||
);
|
||||
|
||||
app.MapPost(
|
||||
"/journal/reverse",
|
||||
async (ReverseJournalCommand cmd, IMessageBus bus) =>
|
||||
{
|
||||
await bus.InvokeAsync(cmd);
|
||||
return Results.Accepted();
|
||||
}
|
||||
);
|
||||
|
||||
app.MapGet(
|
||||
"/events",
|
||||
(IEventTracker tracker) =>
|
||||
{
|
||||
if (tracker is DemoEventStore store)
|
||||
{
|
||||
return Results.Ok(store.CapturedEvents);
|
||||
}
|
||||
|
||||
return Results.NotFound();
|
||||
}
|
||||
);
|
||||
|
||||
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": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user