using AccountsBLL.Voucher; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.Voucher { // Faithful port of GB4 Voucher.svc's GetVoucherSummaryInfo. Despite the "Summary" name this // is a plain header lookup (voucher + its main account's code/name) — no aggregation, no // detail/bill-allocation rollup. public class GetVoucherSummaryInfo : BaseEndpoint> { private readonly IVoucherBLL _VoucherBLL; public GetVoucherSummaryInfo(IVoucherBLL voucherBLL) { _VoucherBLL = voucherBLL; } public override void Configure() { Get("/Voucher/Summary/Info"); AllowAnonymous(); } public record GetVoucherSummaryInfoParameters( [property: FromHeader] string Login, [property: QueryParam] int VoucherId ); protected override string? GetCacheKey(GetVoucherSummaryInfoParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync(GetVoucherSummaryInfoParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _VoucherBLL.GetVoucherSummaryInfo(req.VoucherId, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }