using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using RecruitmentBLL.Application; using static GB5Shared.GB5Constant.Constant; namespace RecruitmentSL.EndPoints.Application { // Thin read-only passthrough to ApplicationBLL.GetRequiredQuizForStage — lets a Recruitment // FE (stage config screen, or the candidate pipeline board) ask "does this stage require a // Quiz, and if so, what quiz is it currently?" without knowing anything about how TMS's // Quiz engine works. Direct DI cross-module call under the hood (RecruitmentSL/TMSSL both // HostedBy HRFinanceHost) — see ApplicationBLL.GetRequiredQuizForStage's doc comment. // // NOTE: this only reads the Quiz *definition* (title, pass threshold, mode). It cannot read // back a Candidate's attempt result (pass/fail/score) — TQUIZATTEMPT.EMPLOYEEID has a real // FK to MEMPLOYEE and a Candidate has no MEMPLOYEE row, so no TQUIZATTEMPT row can exist for // one today. See Docs/Quiz-Assessment-Feature-Guide.md and this module's migration // 20260903_Recruitment_Phase2_QuizScreening_Schema_SqlServer.sql for the full explanation. public class GetApplicationStageRequiredQuiz : BaseEndpoint { private readonly IApplicationBLL _ApplicationBLL; public GetApplicationStageRequiredQuiz(IApplicationBLL applicationBLL) { _ApplicationBLL = applicationBLL; } public override void Configure() { Get("/Application/GetApplicationStageRequiredQuiz"); // Roles(...) throws 500 here — no host in this repo configures AddAuthentication // (HRFinanceHost included). AllowAnonymous matches every other endpoint in this SL // module today. AllowAnonymous(); } public record GetApplicationStageRequiredQuizParameters( [property: QueryParam] int SelectionProcessStageId, [property: FastEndpoints.FromHeader] string Login ); protected override string? GetCacheKey(GetApplicationStageRequiredQuizParameters parameters, LoginDTO loginDTO) => KeyGenerator.KeyGeneration( parameters.SelectionProcessStageId, EntityConstant.OBJECTRECRUITMENTSELECTIONPROCESSSTAGE, CacheKeyLevel.CLIENT_LEVEL, loginDTO); protected override async Task> ExecuteAsync( GetApplicationStageRequiredQuizParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _ApplicationBLL .GetRequiredQuizForStage(parameters.SelectionProcessStageId, 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); } } } }