diff --git a/TimetableDesigner.Backend.Services.Authentication.slnx b/TimetableDesigner.Backend.Services.Authentication.slnx index 6654fd0..733c0df 100644 --- a/TimetableDesigner.Backend.Services.Authentication.slnx +++ b/TimetableDesigner.Backend.Services.Authentication.slnx @@ -1,5 +1,4 @@ - diff --git a/TimetableDesigner.Backend.Services.Authentication/Events/Handlers.cs b/TimetableDesigner.Backend.Services.Authentication/Events/Handlers.cs new file mode 100644 index 0000000..cac7bb8 --- /dev/null +++ b/TimetableDesigner.Backend.Services.Authentication/Events/Handlers.cs @@ -0,0 +1,18 @@ +using TimetableDesigner.Backend.Events; +using TimetableDesigner.Backend.Events.Extensions.AspNetCore.OpenApi; +using TimetableDesigner.Backend.Services.Authentication.DTO.WebAPI; + +namespace TimetableDesigner.Backend.Services.Authentication.Events; + +public static class Handlers +{ + public static void MapEventHandlers(this WebApplication app) + { + app.AddEventHandler(Test); + } + + public static async Task Test(RegisterRequest registerRequest) + { + Console.WriteLine(registerRequest.Email); + } +} \ No newline at end of file diff --git a/TimetableDesigner.Backend.Services.Authentication/Program.cs b/TimetableDesigner.Backend.Services.Authentication/Program.cs index 70d70e3..abff260 100644 --- a/TimetableDesigner.Backend.Services.Authentication/Program.cs +++ b/TimetableDesigner.Backend.Services.Authentication/Program.cs @@ -2,12 +2,14 @@ using System.Reflection; using FluentValidation; using Microsoft.AspNetCore.Identity.Data; using Microsoft.EntityFrameworkCore; -using TimetableDesigner.Backend.Events; -using TimetableDesigner.Backend.Events.RabbitMQ; +using TimetableDesigner.Backend.Events.Extensions.AspNetCore.OpenApi; +using TimetableDesigner.Backend.Events.Providers.RabbitMQ; using TimetableDesigner.Backend.Services.Authentication.API; using TimetableDesigner.Backend.Services.Authentication.API.Validators; using TimetableDesigner.Backend.Services.Authentication.Application.Helpers; using TimetableDesigner.Backend.Services.Authentication.Database; +using TimetableDesigner.Backend.Services.Authentication.Events; +using TimetableDesigner.Backend.Services.Authentication.WebAPI; namespace TimetableDesigner.Backend.Services.Authentication; @@ -27,20 +29,23 @@ public static class Program if (app.Environment.IsDevelopment()) app.MapOpenApi(); app.InitializeDatabase(); - app.UseHttpsRedirection(); - app.MapEndpoints(); + //app.UseHttpsRedirection(); + app.MapWebAPIEndpoints(); + app.MapEventHandlers(); app.Run(); } private static WebApplicationBuilder SetupOpenApi(this WebApplicationBuilder builder) { - builder.Services.AddEventQueue(cfg => + builder.Services.AddEventQueue(cfg => { cfg.Hostname = "localhost"; cfg.Port = 5672; cfg.Username = "user"; cfg.Password = "l4JxOIuSoyod86N"; + cfg.ExchangeName = "events"; + cfg.QueuePrefix = "authentication"; }); builder.Services.AddOpenApi(); return builder; diff --git a/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj b/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj index 27f76da..7b69a71 100644 --- a/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj +++ b/TimetableDesigner.Backend.Services.Authentication/TimetableDesigner.Backend.Services.Authentication.csproj @@ -12,16 +12,17 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + - diff --git a/TimetableDesigner.Backend.Services.Authentication/WebAPI/Endpoints.cs b/TimetableDesigner.Backend.Services.Authentication/WebAPI/Endpoints.cs index f0c14d2..a52532b 100644 --- a/TimetableDesigner.Backend.Services.Authentication/WebAPI/Endpoints.cs +++ b/TimetableDesigner.Backend.Services.Authentication/WebAPI/Endpoints.cs @@ -2,15 +2,15 @@ using FluentValidation.Results; using MediatR; using Microsoft.AspNetCore.Http.HttpResults; -using Microsoft.AspNetCore.Mvc; +using TimetableDesigner.Backend.Events; using TimetableDesigner.Backend.Services.Authentication.Application.Commands.Register; using TimetableDesigner.Backend.Services.Authentication.DTO.WebAPI; -namespace TimetableDesigner.Backend.Services.Authentication.API; +namespace TimetableDesigner.Backend.Services.Authentication.WebAPI; public static class Endpoints { - public static IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder app) + public static IEndpointRouteBuilder MapWebAPIEndpoints(this IEndpointRouteBuilder app) { app.MapPost("/register", Register) .AllowAnonymous() @@ -22,6 +22,9 @@ public static class Endpoints .WithName("AuthenticatePassword"); app.MapPost("/authenticate_token", AuthenticateToken) .WithName("AuthenticateToken"); + app.MapPost("/test", Test) + .AllowAnonymous() + .WithName("Test"); return app; } @@ -50,4 +53,11 @@ public static class Endpoints { return null; } + + public static async Task> Test(IEventQueuePublisher publisher) + { + await publisher.PublishAsync(new RegisterRequest("aaaa", "bbbb", "ccccc")); + + return TypedResults.Ok(); + } } \ No newline at end of file