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 ReAccountPostFastAllOU — loops ReAccountPost's rebuild // across every active organizational unit instead of just the caller's current OU. public class ReAccountPostAllOU : BaseEndpoint> { private readonly IVoucherBLL _VoucherBLL; public ReAccountPostAllOU(IVoucherBLL voucherBLL) { _VoucherBLL = voucherBLL; } public override void Configure() { Get("/Voucher/ReAccountPost/All/OU"); AllowAnonymous(); } public record ReAccountPostAllOUParameters( [property: FromHeader] string Login, [property: QueryParam] int PeriodId, [property: QueryParam] int AccountId ); protected override string? GetCacheKey(ReAccountPostAllOUParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync(ReAccountPostAllOUParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _VoucherBLL.ReAccountPostFastAllOU(req.PeriodId, req.AccountId, 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); } } } }