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 CheckReferenceNumberDuplication. On success returns an // empty-body success response; if a duplicate is found, the BLL throws and this endpoint // returns an error response carrying the same "already used in {VoucherNumber}" message GB4 // used — matching GB4's own duplicate-signaled-via-exception contract. public class CheckReferenceNumberDuplication : BaseEndpoint> { private readonly IVoucherBLL _VoucherBLL; public CheckReferenceNumberDuplication(IVoucherBLL voucherBLL) { _VoucherBLL = voucherBLL; } public override void Configure() { Get("/Voucher/Check/Reference/Number/Duplication"); AllowAnonymous(); } public record CheckReferenceNumberDuplicationParameters( [property: FromHeader] string Login, [property: QueryParam] int OuId, [property: QueryParam] int PeriodId, [property: QueryParam] int BiztransactiontypeId, [property: QueryParam] int AccountId, [property: QueryParam] string ReferenceNumber ); protected override string? GetCacheKey(CheckReferenceNumberDuplicationParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( CheckReferenceNumberDuplicationParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _VoucherBLL.CheckReferenceNumberDuplication( req.OuId, req.PeriodId, req.BiztransactiontypeId, req.AccountId, req.ReferenceNumber, 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); } } } }