From c6d1d862ff91c0678abd176b6577738f7e38ccca Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sun, 30 Aug 2026 15:19:56 +0200 Subject: [PATCH] Consolidate SyncUserEvent endpoints --- .../SyncIdentityUserEndpoint.cs | 30 ------------------- .../Endpoints/Users/SyncUserEndpoint.cs | 13 ++++---- .../Communications/Events/SyncUserEvent.cs | 2 ++ 3 files changed, 10 insertions(+), 35 deletions(-) delete mode 100644 PostFundManagement.Api/Endpoints/Communications/SyncIdentityUserEndpoint.cs diff --git a/PostFundManagement.Api/Endpoints/Communications/SyncIdentityUserEndpoint.cs b/PostFundManagement.Api/Endpoints/Communications/SyncIdentityUserEndpoint.cs deleted file mode 100644 index 3ce7bdb..0000000 --- a/PostFundManagement.Api/Endpoints/Communications/SyncIdentityUserEndpoint.cs +++ /dev/null @@ -1,30 +0,0 @@ -using PostFundManagement.Application.Extensions; -using PostFundManagement.Application.Services.Communications.Events; -using PostFundManagement.Domain.Abstractions; -using PostFundManagement.Domain.Extensions; -using PostFundManagement.Domain.Security; - -namespace PostFundManagement.Api.Endpoints.Communications; - -[ApiVersionTarget(1)] -public class SyncIdentityUserEndpoint : IEndpoint -{ - public void Map(IEndpointRouteBuilder builder) - { - builder.MapPost("api/integration/sync", async (IJobOrchestrator jobOrchestrator, - CancellationToken cancellationToken = default) => - { - var syncEvent = new SyncUserEvent(); - - await jobOrchestrator.SendAsync(syncEvent, cancellationToken); - - return Results.Ok(); - }) - .WithDescription("Trigger integration and data synchronization in the background") - .WithName(typeof(SyncIdentityUserEndpoint).ToEndpointName()) - .MapToApiVersion(new ApiVersion(1)) - .Produces(StatusCodes.Status200OK) - .Produces(StatusCodes.Status401Unauthorized) - .WithTags(EndpointTags.Communications); - } -} diff --git a/PostFundManagement.Api/Endpoints/Users/SyncUserEndpoint.cs b/PostFundManagement.Api/Endpoints/Users/SyncUserEndpoint.cs index 3ac6553..6d30e80 100644 --- a/PostFundManagement.Api/Endpoints/Users/SyncUserEndpoint.cs +++ b/PostFundManagement.Api/Endpoints/Users/SyncUserEndpoint.cs @@ -1,4 +1,5 @@ using PostFundManagement.Application.Extensions; +using PostFundManagement.Application.Services.Communications.Events; using PostFundManagement.Application.Services.Users; using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Extensions; @@ -11,21 +12,23 @@ public class SyncUserEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { - builder.MapPost("api/users/sync", async (HttpContext context, - UserService service, CancellationToken cancellationToken = default) => + builder.MapPost("api/integration/sync", async (IJobOrchestrator jobOrchestrator, + HttpContext context, UserService service, CancellationToken cancellationToken = default) => { var result = await service.SyncUserAsync(context.GetUserId(), context.GetUserEmail(), cancellationToken); + if (result.IsSuccess) + await jobOrchestrator.SendAsync(SyncUserEvent.Create(), cancellationToken); + return result.IsSuccess ? Results.Ok() : Results.BadRequest(result.Errors.ToProblems()); }) - .WithDescription("Synchronise caller user profile using id_token's SID, inserting/updating user details in database") + .WithDescription("Trigger integration and data synchronization in the background") .WithName(typeof(SyncUserEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) - .Produces(StatusCodes.Status400BadRequest) .Produces(StatusCodes.Status401Unauthorized) - .WithTags(EndpointTags.Users); + .WithTags(EndpointTags.Communications); } } diff --git a/PostFundManagement.Application/Services/Communications/Events/SyncUserEvent.cs b/PostFundManagement.Application/Services/Communications/Events/SyncUserEvent.cs index 86e93a4..3aa9e86 100644 --- a/PostFundManagement.Application/Services/Communications/Events/SyncUserEvent.cs +++ b/PostFundManagement.Application/Services/Communications/Events/SyncUserEvent.cs @@ -6,6 +6,8 @@ namespace PostFundManagement.Application.Services.Communications.Events; public class SyncUserEvent : EventBase, IEvent { public string Name { get; set; } = nameof(SyncUserEvent); + + public static SyncUserEvent Create() => new(); } public class SyncUserEventHandler(ILogger logger) : INotificationHandler