using AccountsDAL.DTO.Account; using AccountsDAL.DTO.AccountGroup; using AccountsDAL.DTO.AccountSchedule; using AccountsDAL.Query.Account; using AccountsDAL.Query.AccountGroup; using AccountsDAL.Query.AccountSchedule; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using Newtonsoft.Json; namespace AccountsDAL.CustomCode.AccountTree { public class AccountTreeDAL : IAccountTreeDAL { private readonly IQueryExecutor _QueryExecutor; public AccountTreeDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task GetAccountScheduleFlatList(LoginDTO loginDTO, CancellationToken ct) { try { var sql = AccountScheduleQB.GET_ACCOUNTSCHEDULE_FLAT_LIST; var result = await _QueryExecutor .QueryAsync(loginDTO, sql, null!, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch (Exception) { throw; } } // Reuses AccountGroupQB.GET_ACCOUNTGROUP_FLAT_LIST as-is — same query AccountGroupDAL // already uses for its own (Group-only) tree, so the flat rows carry ParentId + // AccountScheduleId that this Group node needs to nest under either another Group or // its owning Schedule. public async Task GetAccountGroupFlatList(LoginDTO loginDTO, CancellationToken ct) { try { var sql = AccountGroupQB.GET_ACCOUNTGROUP_FLAT_LIST; var result = await _QueryExecutor .QueryAsync(loginDTO, sql, null!, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch (Exception) { throw; } } public async Task> GetAccountsByGroup( int accountGroupId, int firstNumber, int maxResult, LoginDTO loginDTO, CancellationToken ct) { try { var sql = AccountQB.GET_ACCOUNT_FLAT_BY_GROUP; var parameters = new { AccountGroupId = accountGroupId, Offset = Math.Max(0, firstNumber - 1), PageSize = maxResult }; // QueryPagedAsync has no CancellationToken parameter on this repo's IQueryExecutor // overload (see GB5Shared/QueryExecutor/IQueryExecutor.cs) — ct is accepted on this // method for interface consistency and is honored via the caller's own cancellation // of the surrounding request pipeline. var paged = await _QueryExecutor .QueryPagedAsync(loginDTO, sql, parameters) .ConfigureAwait(false); return (paged.Items ?? Enumerable.Empty()).ToList(); } catch (Exception) { throw; } } } }