MediatR added
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register;
|
using TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register;
|
||||||
using TimetableDesigner.Backend.Services.Authentication.DTO.API;
|
using TimetableDesigner.Backend.Services.Authentication.DTO.API;
|
||||||
|
|
||||||
@@ -18,10 +19,10 @@ public static class Endpoints
|
|||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Results<Created<RegisterResponse>, ProblemHttpResult>> Register(RegisterCommand command, RegisterHandler handler)
|
public static async Task<Results<Created<RegisterResponse>, ProblemHttpResult>> Register(RegisterCommand command, IMediator mediator)
|
||||||
{
|
{
|
||||||
RegisterDto data = await handler.HandleAsync(command);
|
await mediator.Send(command);
|
||||||
return Results.Created($"accounts/{data.Id}", data);
|
return Results.Created($"accounts/0", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Results<Ok<AuthenticateResponse>, ProblemHttpResult>> AuthenticatePassword(AuthenticatePasswordRequest request)
|
public static async Task<Results<Ok<AuthenticateResponse>, ProblemHttpResult>> AuthenticatePassword(AuthenticatePasswordRequest request)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
namespace TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register;
|
using MediatR;
|
||||||
|
|
||||||
public record RegisterCommand(string Email, string Password);
|
namespace TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register;
|
||||||
|
|
||||||
|
public record RegisterCommand(string Email, string Password) : IRequest;
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using TimetableDesigner.Backend.Services.Authentication.Database;
|
using MediatR;
|
||||||
|
using TimetableDesigner.Backend.Services.Authentication.Database;
|
||||||
|
|
||||||
namespace TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register;
|
namespace TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register;
|
||||||
|
|
||||||
public class RegisterHandler
|
public class RegisterHandler : IRequestHandler<RegisterCommand>
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext _databaseContext;
|
private readonly DatabaseContext _databaseContext;
|
||||||
|
|
||||||
@@ -11,8 +12,8 @@ public class RegisterHandler
|
|||||||
_databaseContext = databaseContext;
|
_databaseContext = databaseContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RegisterDto> HandleAsync(RegisterCommand command)
|
public async Task Handle(RegisterCommand command, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ public static class Program
|
|||||||
.SetupSecurity()
|
.SetupSecurity()
|
||||||
.SetupDatabase()
|
.SetupDatabase()
|
||||||
.SetupValidation()
|
.SetupValidation()
|
||||||
|
.SetupMediatR()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
@@ -52,6 +53,12 @@ public static class Program
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static WebApplicationBuilder SetupMediatR(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddMediatR(x => x.RegisterServicesFromAssembly(typeof(Program).Assembly));
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
private static WebApplication InitializeDatabase(this WebApplication app)
|
private static WebApplication InitializeDatabase(this WebApplication app)
|
||||||
{
|
{
|
||||||
using (IServiceScope scope = app.Services.CreateScope())
|
using (IServiceScope scope = app.Services.CreateScope())
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
||||||
|
<PackageReference Include="MediatR" Version="14.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.9">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.9">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|||||||
Reference in New Issue
Block a user