using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using RecruitmentBLL.Candidate; using System.Collections.Generic; using System.Threading; using static GB5Shared.GB5Constant.Constant; namespace RecruitmentSL.EndPoints.Candidate { // Bridge endpoint for gb4.7mfe's legacy Applicant dashboard (projects/recruitment/dashboard/ // applicantdashboard) — see RecruitmentDAL.Query.Candidate.CandidateQB.GET_CURRENT_STAGE_BY_EMAIL // for why this exists as its own endpoint instead of a JOIN added to the legacy report's own // SQL: that report (GET /prs/Applicant.svc/ApplicantReport) is served by an external legacy // GB4 WCF service, not by any query in this repo. The FE posts the batch of ApplicantMailId // values it already has from that legacy response; this endpoint returns a // CandidateCurrentStageDTO row for every email that matched a real, active Candidate — an // email with no match is simply absent from the result, never fabricated. public class GetCandidateCurrentStageByEmail : BaseEndpoint< GetCandidateCurrentStageByEmail.GetCandidateCurrentStageByEmailParameters, ResponseStandardDTO> { private readonly ICandidateBLL _CandidateBLL; public GetCandidateCurrentStageByEmail(ICandidateBLL candidateBLL) { _CandidateBLL = candidateBLL; } public override void Configure() { Post("/Candidate/GetCandidateCurrentStageByEmail"); // Roles("HR", "Recruiter", "Manager") throws 500 here — no host in this repo // configures AddAuthentication. AllowAnonymous matches every other endpoint in this // SL module today. AllowAnonymous(); } // [FromBody] on a record property binds the raw top-level body — the client posts a plain // JSON array of emails, not a wrapped object. public record GetCandidateCurrentStageByEmailParameters( [property: FastEndpoints.FromHeader] string Login, [property: FastEndpoints.FromBody] List Emails ); // Not cached — this reflects the candidate's live pipeline stage (can change the moment a // recruiter advances them) and the cache key would otherwise have to encode an arbitrary, // request-varying email batch for no real hit-rate benefit. protected override string? GetCacheKey(GetCandidateCurrentStageByEmailParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( GetCandidateCurrentStageByEmailParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _CandidateBLL .GetCurrentStageByEmail(req.Emails ?? new List(), LoginDTO!, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }