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