using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using TMSBLL.Certificate; using TMSSL.EndPoints.TrainingCertificate; using static GB5Shared.GB5Constant.Constant; namespace TMSSL.EndPoints.Certificate { public class GetTrainingCertificate : BaseEndpoint> { private readonly ITrainingCertificateBLL _TrainingCertificateBLL; public GetTrainingCertificate(ITrainingCertificateBLL TrainingCertificateBLL) { _TrainingCertificateBLL = TrainingCertificateBLL; } public override void Configure() { Get("/TrainingCertificate/GetTrainingCertificate"); AllowAnonymous(); } public record GetTrainingCertificateParameters( [property: QueryParam] int TrainingCertificateId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetTrainingCertificateParameters req, LoginDTO loginDTO) => KeyGenerator.KeyGeneration(req.TrainingCertificateId, EntityConstant.OBJECTTRAININGCERTIFICATE, CacheKeyLevel.CLIENT_LEVEL, loginDTO); protected override async Task> ExecuteAsync(GetTrainingCertificateParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _TrainingCertificateBLL.GetCertificate(req.TrainingCertificateId, loginDTO); 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); } } } }