Consolidate SyncUserEvent endpoints

This commit is contained in:
2026-08-30 15:19:56 +02:00
parent 4827cb5795
commit c6d1d862ff
3 changed files with 10 additions and 35 deletions
@@ -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);
}
}
@@ -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<Microsoft.AspNetCore.Mvc.ProblemDetails>(StatusCodes.Status400BadRequest)
.Produces(StatusCodes.Status401Unauthorized)
.WithTags(EndpointTags.Users);
.WithTags(EndpointTags.Communications);
}
}
@@ -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<SyncUserEvent> logger) : INotificationHandler<SyncUserEvent>