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 GetUsedVoucherInBillAllocation — given a voucher // (typically a bill/invoice), returns the reference/detail numbers of payment entries already // allocated against its bill-allocation lines. public class GetUsedVoucherInBillAllocation : BaseEndpoint> { private readonly IVoucherBLL _VoucherBLL; public GetUsedVoucherInBillAllocation(IVoucherBLL voucherBLL) { _VoucherBLL = voucherBLL; } public override void Configure() { Post("/Voucher/GetUsedVoucherInBillAllocation"); AllowAnonymous(); } public record GetUsedVoucherInBillAllocationParameters( [property: FromHeader] string Login, [property: QueryParam] int VoucherId ); protected override string? GetCacheKey(GetUsedVoucherInBillAllocationParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( GetUsedVoucherInBillAllocationParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _VoucherBLL.GetUsedVoucherInBillAllocation(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); } } } }