using FastEndpoints; using FrameworkBLL.Encrypt; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.Encrypt { public class GetEncrypt : BaseEndpoint { private readonly IEncryptService _encryptService; public GetEncrypt(IEncryptService encryptService) { _encryptService = encryptService; } public override void Configure() { Get("/Encrypt/GetEncrypt"); AllowAnonymous(); } public record GetEncryptParameters( [property: QueryParam] string PlainText, [property: QueryParam] string? Key, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync( GetEncryptParameters encryptParameter, LoginDTO loginDTO, CancellationToken ct) { try { string encryptedValue = _encryptService.Encrypt( encryptParameter.PlainText, encryptParameter.Key ?? "GB5" ); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(encryptedValue, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError( ex, CacheKeyLevel.USER_LEVEL, loginDTO, ex.Message, 500 ); } } } }