using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Api; using PostFundManagement.Domain.Extensions; namespace PostFundManagement.Api.Endpoints.Communications; public class SyncEvent : EventBase, IEvent { public string Name { get; set; } = nameof(SyncEvent); } public class SyncEventHandler : INotificationHandler { public ValueTask Handle(SyncEvent notification, CancellationToken cancellationToken) { Trace.WriteLine($"Integration Sync executed. Correlation ID: {notification.CorrelationId}"); return ValueTask.CompletedTask; } } [ApiVersionTarget(1)] public class SyncEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapPost("api/integration/sync", async (IJobOrchestrator jobOrchestrator, CancellationToken cancellationToken = default) => { var syncEvent = new SyncEvent(); await jobOrchestrator.SendAsync(syncEvent, cancellationToken); return Results.Ok(new { Queued = true, syncEvent.CorrelationId }); }) .RequireAuthorization() .WithDescription("Trigger integration and data synchronization in the background") .WithName(typeof(SyncEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status401Unauthorized) .WithTags(EndpointTags.Communications); } }