diff --git a/TimetableDesigner.Backend.Services.Authentication/API/Endpoints.cs b/TimetableDesigner.Backend.Services.Authentication/API/Endpoints.cs index 1bce858..22b1607 100644 --- a/TimetableDesigner.Backend.Services.Authentication/API/Endpoints.cs +++ b/TimetableDesigner.Backend.Services.Authentication/API/Endpoints.cs @@ -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.DTO.API; @@ -18,10 +19,10 @@ public static class Endpoints return app; } - public static async Task, ProblemHttpResult>> Register(RegisterCommand command, RegisterHandler handler) + public static async Task, ProblemHttpResult>> Register(RegisterCommand command, IMediator mediator) { - RegisterDto data = await handler.HandleAsync(command); - return Results.Created($"accounts/{data.Id}", data); + await mediator.Send(command); + return Results.Created($"accounts/0", null); } public static async Task, ProblemHttpResult>> AuthenticatePassword(AuthenticatePasswordRequest request) diff --git a/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterCommand.cs b/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterCommand.cs index 33f6676..21ce121 100644 --- a/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterCommand.cs +++ b/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterCommand.cs @@ -1,3 +1,5 @@ -namespace TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register; +using MediatR; -public record RegisterCommand(string Email, string Password); \ No newline at end of file +namespace TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register; + +public record RegisterCommand(string Email, string Password) : IRequest; \ No newline at end of file diff --git a/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterHandler.cs b/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterHandler.cs index f2b2a97..49fbff7 100644 --- a/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterHandler.cs +++ b/TimetableDesigner.Backend.Services.Authentication/Application/Commands/Register/RegisterHandler.cs @@ -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; -public class RegisterHandler +public class RegisterHandler : IRequestHandler { private readonly DatabaseContext _databaseContext; @@ -11,8 +12,8 @@ public class RegisterHandler _databaseContext = databaseContext; } - public async Task HandleAsync(RegisterCommand command) + public async Task Handle(RegisterCommand command, CancellationToken cancellationToken) { - return null; + } } \ No newline at end of file diff --git a/TimetableDesigner.Backend.Services.Authentication/Program.cs b/TimetableDesigner.Backend.Services.Authentication/Program.cs index 8944403..16b0d31 100644 --- a/TimetableDesigner.Backend.Services.Authentication/Program.cs +++ b/TimetableDesigner.Backend.Services.Authentication/Program.cs @@ -17,6 +17,7 @@ public static class Program .SetupSecurity() .SetupDatabase() .SetupValidation() + .SetupMediatR() .Build(); if (app.Environment.IsDevelopment()) @@ -52,6 +53,12 @@ public static class Program 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) { using (IServiceScope scope = app.Services.CreateScope()) diff --git a/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj b/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj index 6d817d5..37d6399 100644 --- a/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj +++ b/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj @@ -10,6 +10,7 @@ + all