using FastEndpoints; using FrameworkBLL.WorkFlow; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using System.Text.Json; using GB5Shared.DateConverter; using static FrameworkDAL.Constant.Constant; namespace FrameworkSL.Endpoints.WorkFlow { /// /// GET /WorkFlow/CurrentApprovalStatus /// /// Returns the real-time approval status for a specific document. /// Shows the current approval level, who has the task, and the full step history. /// /// Query parameters: /// EntityId — MENTITY.ENTITYID of the document /// ObjectId — PK of the document record (e.g. TaskId) /// public class GetCurrentApprovalStatus : BaseEndpoint> { private readonly IWorkFlowBLL _bll; public GetCurrentApprovalStatus(IWorkFlowBLL bll) => _bll = bll; public override void Configure() { Get("/WorkFlow/CurrentApprovalStatus"); AllowAnonymous(); } public record CurrentApprovalStatusParameters( [property: FromHeader] string Login, [property: QueryParam] int EntityId, [property: QueryParam] int ObjectId ); protected override string? GetCacheKey( CurrentApprovalStatusParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( CurrentApprovalStatusParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.CurrentApprovalStatus(req.EntityId, req.ObjectId, login); var options = new JsonSerializerOptions { PropertyNamingPolicy = null }; options.AddGB5Converters(); string json = JsonSerializer.Serialize(result, options); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(json, CacheKeyLevel.NotRequired, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NotRequired, login, ex.Message, 500); } } } }