using FastEndpoints; using FrameworkBLL.GOP; using GB5Shared.DTO.Framework.Login; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.GOP.Flow { public class PublishGopFlow : BaseEndpoint> { private readonly IGopFlowBLL _Bll; public PublishGopFlow(IGopFlowBLL bll) => _Bll = bll; public override void Configure() { Post("/GOP/PublishGopFlow"); AllowAnonymous(); } public record PublishGopFlowParameters( [property: FromHeader] string Login, [property: FromBody] PublishGopFlowRequest Request ); public record PublishGopFlowRequest( int FlowId, string SnapshotVersionLabel ); protected override async Task> ExecuteAsync( PublishGopFlowParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _Bll.PublishGopFlow( req.Request.FlowId, req.Request.SnapshotVersionLabel, loginDTO, ct); if (!result.IsSuccess) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError( new Exception(string.Join("; ", result.Errors)), CacheKeyLevel.NOT_REQUIRED, loginDTO, string.Join("; ", result.Errors), 422); } return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }