using MMBLL.Charge; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.Charge { public class GetCharge : BaseEndpoint> { private readonly IChargeBLL _ChargeBLL; public GetCharge(IChargeBLL ChargeBLL) { _ChargeBLL = ChargeBLL; } public override void Configure() { Get("/Charge/GetCharge"); AllowAnonymous(); } public record GetChargeParameters( [property: FromHeader] string Login, [property: QueryParam] int ChargeId ); protected override string? GetCacheKey(GetChargeParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration( Parameters.ChargeId!, EntityConstant.OBJECTCHARGE, CacheKeyLevel.USER_LEVEL, LoginDTO ); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetChargeParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _ChargeBLL.GetCharge(req.ChargeId, 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 ); } } } }