using FastEndpoints;
using FrameworkBLL.WorkFlow;
using FrameworkDAL.DTO.Workflow;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using GB5Shared.WorkFlow.WorkFlowEngine;
using static FrameworkDAL.Constant.Constant;
namespace FrameworkSL.Endpoints.WorkFlow
{
///
/// POST /WorkFlow/WorkFlowActions
///
/// Processes one or more approver actions (Approve / Reject / Return / Escalate).
///
/// Request body — :
/// Items[].TaskId — TWORKFLOWTASK.WORKFLOWTASKID
/// Items[].Action — 0=Submit 1=Approve 2=Reject 3=Return 4=Escalate
/// Items[].Comment — Optional comment
/// Items[].Facts — Runtime key/value pairs for next-step condition evaluation
///
public class WorkFlowActions
: BaseEndpoint>
{
private readonly IWorkFlowBLL _bll;
public WorkFlowActions(IWorkFlowBLL bll) => _bll = bll;
public override void Configure()
{
Post("/WorkFlow/WorkFlowActions");
AllowAnonymous();
}
public record WorkFlowActionsParameters(
[property: FromHeader] string Login,
[property: FromBody] WorkFlowActionDTO WorkFlowActionDTO
);
protected override string? GetCacheKey(
WorkFlowActionsParameters req, LoginDTO login) => null;
protected override async Task> ExecuteAsync(
WorkFlowActionsParameters req,
LoginDTO login,
CancellationToken ct)
{
try
{
var result = await _bll.WorkFlowActions(req.WorkFlowActionDTO, login);
return await GB5Shared.ResponseStandard.Response
.CreateSuccessResponse(result, CacheKeyLevel.NotRequired, login);
}
catch (WorkflowEngineException ex)
{
// Business / configuration error — surface exact message to caller
return await GB5Shared.ResponseStandard.Response
.CreateExceptionError(ex, CacheKeyLevel.NotRequired,
login, ex.Message, 400);
}
catch (Exception ex)
{
return await GB5Shared.ResponseStandard.Response
.CreateExceptionError(ex, CacheKeyLevel.NotRequired,
login, ex.Message, 500);
}
}
}
}