using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using TMSBLL.Certificate; using static GB5Shared.GB5Constant.Constant; namespace TMSSL.EndPoints.Certificate { // Retries the PDF generation + signing pipeline for a certificate whose SaveCertificate // completed (DB row exists) but whose PDF was never generated (no TTRAININGCERTIFICATESIGNATURE // row) — typically because the pipeline failed non-fatally on first issue (no signatory // configured, storage error, etc.). Safe to call multiple times — pipeline overwrites the // existing signature row if one already exists. public class RegenerateCertificate : BaseEndpoint> { private readonly ITrainingCertificateBLL _TrainingCertificateBLL; public RegenerateCertificate(ITrainingCertificateBLL trainingCertificateBLL) { _TrainingCertificateBLL = trainingCertificateBLL; } public override void Configure() { Post("/TrainingCertificate/RegenerateCertificate"); AllowAnonymous(); } public record Parameters( [property: QueryParam] int TrainingCertificateId, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync(Parameters req, LoginDTO login, CancellationToken ct) { try { var result = await _TrainingCertificateBLL.RegenerateCertificatePdf(req.TrainingCertificateId, login, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } } }