using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using Microsoft.AspNetCore.Mvc; using RecruitmentBLL.ManpowerBudget; using System.Threading; using static GB5Shared.GB5Constant.Constant; namespace RecruitmentSL.EndPoints.ManpowerBudget { public class GetManpowerBudget : BaseEndpoint { private readonly IManpowerBudgetBLL _ManpowerBudgetBLL; public GetManpowerBudget(IManpowerBudgetBLL manpowerBudgetBLL) { _ManpowerBudgetBLL = manpowerBudgetBLL; } public override void Configure() { Get("/ManpowerBudget/GetManpowerBudget"); // Roles("HR", "Finance", "Manager") throws 500 here — no host in this repo configures // AddAuthentication (HRFinanceHost included; see PayRollSL's GetHRMSDashboard.cs for // the same documented, repo-wide gap). AllowAnonymous matches every other endpoint in // this SL module today. AllowAnonymous(); } public record GetManpowerBudgetParameters( [property: QueryParam] int ManpowerBudgetId, [property: FastEndpoints.FromHeader] string Login ); protected override string? GetCacheKey( GetManpowerBudgetParameters parameters, LoginDTO loginDTO) => KeyGenerator.KeyGeneration( parameters.ManpowerBudgetId, EntityConstant.OBJECTRECRUITMENTMANPOWERBUDGET, CacheKeyLevel.CLIENT_LEVEL, loginDTO); protected override async Task> ExecuteAsync( GetManpowerBudgetParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _ManpowerBudgetBLL .GetManpowerBudget(parameters.ManpowerBudgetId, loginDTO!, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse( result, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError( ex, CacheKeyLevel.USER_LEVEL, loginDTO, ex.Message, 500); } } } }