using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using Microsoft.AspNetCore.Mvc; using RecruitmentBLL.Candidate; using static GB5Shared.GB5Constant.Constant; namespace RecruitmentSL.EndPoints.Candidate { public class GetSelectListCandidate : BaseEndpoint< GetSelectListCandidate.GetSelectListCandidateParameters, ResponseStandardDTO> { private readonly ICandidateBLL _CandidateBLL; public GetSelectListCandidate(ICandidateBLL candidateBLL) { _CandidateBLL = candidateBLL; } public override void Configure() { Post("/Candidate/GetSelectListCandidate"); // Roles("HR", "Recruiter", "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(); } // FirstNumber/MaxResult follow the same FromBody-criteria + QueryParam-paging wire shape // and naming already used by GetSelectListMeter (FM), GetSelectListProblem/GetSelectListAction // (CRM), etc. Both default so existing callers that don't pass them keep working — the // candidate pool must never fall back to an unbounded result, so CandidateBLL.GetSelectListCandidate // also re-applies these defaults defensively if 0/negative values arrive. public record GetSelectListCandidateParameters( [property: FastEndpoints.FromHeader] string Login, [property: FastEndpoints.FromBody] CriteriaDTO CriteriaDTO, [property: QueryParam] int FirstNumber = 1, [property: QueryParam] int MaxResult = 100 ); protected override string? GetCacheKey(GetSelectListCandidateParameters req, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration( -1, EntityConstant.OBJECTRECRUITMENTCANDIDATE, CacheKeyLevel.CLIENT_LEVEL, LoginDTO, req.CriteriaDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync( GetSelectListCandidateParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _CandidateBLL .GetSelectListCandidate(req.FirstNumber, req.MaxResult, req.CriteriaDTO, LoginDTO!, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse( result, CacheKeyLevel.CLIENT_LEVEL, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError( ex, CacheKeyLevel.CLIENT_LEVEL, LoginDTO, ex.Message, 500); } } } }