using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.MMHead; namespace MMSL.EndPoints.MMHead { public class CancelMMHead : BaseEndpoint { private readonly IMMHeadBLL _mmHeadBll; public CancelMMHead(IMMHeadBLL mmHeadBll) { _mmHeadBll = mmHeadBll; } public override void Configure() { Put("/MMHead/CancelMMHead"); AllowAnonymous(); } public record CancelMMHeadParameters( [property: QueryParam] int DocumentId, [property: FromHeader] string Login ); protected override string? GetCacheKey(CancelMMHeadParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( CancelMMHeadParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _mmHeadBll.CancelMMHeadAsync(req.DocumentId, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login); } catch (ArgumentException ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 400); } catch (InvalidOperationException ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 409); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login, "An unexpected error occurred. Please try again.", 500); } } } }