using Dapr.Client; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMDAL.DTO.MRPRun; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MRPRun { public class TriggerMRPRun : BaseEndpoint> { private readonly DaprClient _DaprClient; public TriggerMRPRun(DaprClient daprClient) => _DaprClient = daprClient; public override void Configure() { Post("/MRPRun/TriggerMRPRun"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: FromBody] MRPRunTriggerDTO Trigger ); protected override string? GetCacheKey(Params req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Params req, LoginDTO loginDTO, CancellationToken ct) { try { req.Trigger.WorkOUId = loginDTO.WorkOUId; req.Trigger.TenantId = loginDTO.ClientId; req.Trigger.UserId = loginDTO.UserId; req.Trigger.IsCombined = false; await _DaprClient.PublishEventAsync("pubsub", "mrprun.trigger", req.Trigger, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( "MRP run queued successfully.", CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }