using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.ChargeElement; using MMDAL.CustomCode.ChargeElement; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.ChargeElement { public class GetChargeElement : BaseEndpoint> { private readonly IChargeElementBLL _ChargeElementBLL; public GetChargeElement(IChargeElementBLL ChargeElementBLL) { _ChargeElementBLL = ChargeElementBLL; } public override void Configure() { Get("/ChargeElement/GetChargeElement"); AllowAnonymous(); } public record GetChargeElementParameters( [property: FromHeader] string Login, [property: QueryParam] int ChargeElementId ); protected override string? GetCacheKey(GetChargeElementParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration( Parameters.ChargeElementId!, EntityConstant.OBJECTCHARGEELEMENT, CacheKeyLevel.USER_LEVEL, LoginDTO ); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetChargeElementParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _ChargeElementBLL.GetChargeElement(req.ChargeElementId, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.USER_LEVEL, LoginDTO ); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500 ); } } } }