From c9eb9132df0ee0c3865c978b16172cf04841bf6a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:41:22 +0000 Subject: [PATCH 1/2] Initial plan From edaf2be01baf96432aed8e11b13e757e7809ccab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:45:55 +0000 Subject: [PATCH 2/2] refactor failed sales queries to reduce complexity Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../ReportingManager.cs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/EstateReportingAPI.BusinessLogic/ReportingManager.cs b/EstateReportingAPI.BusinessLogic/ReportingManager.cs index 173af30..84ee446 100644 --- a/EstateReportingAPI.BusinessLogic/ReportingManager.cs +++ b/EstateReportingAPI.BusinessLogic/ReportingManager.cs @@ -368,8 +368,8 @@ public async Task> GetTodaysFailedSales(TransactionQueries.T using ResolvedDbContext? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString()); await using EstateManagementContext context = resolvedContext.Context; - var todaysSalesQuery = (from t in context.TodayTransactions where t.IsAuthorised == false && t.TransactionType == "Sale" && t.ResponseCode == request.ResponseCode select t.TransactionAmount); - var comparisonSalesQuery = (from t in context.TransactionHistory where t.IsAuthorised == false && t.TransactionType == "Sale" && t.TransactionDate == request.ComparisonDate && t.TransactionTime <= DateTime.Now.TimeOfDay && t.ResponseCode == request.ResponseCode select t.TransactionAmount); + IQueryable todaysSalesQuery = this.BuildTodaysFailedSalesQuery(context, request.ResponseCode); + IQueryable comparisonSalesQuery = this.BuildComparisonFailedSalesQuery(context, request.ComparisonDate, request.ResponseCode); var todaysSalesQueryResult = await ExecuteQuerySafeToList(todaysSalesQuery, cancellationToken, "Error retrieving todays failed sales"); if (todaysSalesQueryResult.IsFailed) @@ -1357,15 +1357,30 @@ private IQueryable BuildTodaySalesQuery(EstateManagementContex return from t in context.TodayTransactions where t.IsAuthorised && t.TransactionType == "Sale" && t.TransactionDate == DateTime.Now.Date && t.TransactionTime <= DateTime.Now.TimeOfDay select t; } + private IQueryable BuildTodaysFailedSalesQuery(EstateManagementContext context, + String responseCode) { + return from t in context.TodayTransactions + where t.IsAuthorised == false && t.TransactionType == "Sale" && t.ResponseCode == responseCode + select t.TransactionAmount; + } + private IQueryable BuildComparisonSalesQuery(EstateManagementContext context, - DateTime comparisonDate) { + DateTime comparisonDate) { return from t in context.TransactionHistory where t.IsAuthorised && t.TransactionType == "Sale" && t.TransactionDate == comparisonDate && t.TransactionTime <= DateTime.Now.TimeOfDay select t; } + private IQueryable BuildComparisonFailedSalesQuery(EstateManagementContext context, + DateTime comparisonDate, + String responseCode) { + return from t in context.TransactionHistory + where t.IsAuthorised == false && t.TransactionType == "Sale" && t.TransactionDate == comparisonDate && t.TransactionTime <= DateTime.Now.TimeOfDay && t.ResponseCode == responseCode + select t.TransactionAmount; + } + private static async Task>> LoadProductsAsync(EstateManagementContext context, - List contractIds, - CancellationToken cancellationToken, - string stepName) { + List contractIds, + CancellationToken cancellationToken, + string stepName) { var query = context.ContractProducts.Where(cp => contractIds.Contains(cp.ContractId)).Select(cp => new ContractProductData { ContractProductId = cp.ContractProductId, ContractProductReportingId = cp.ContractProductReportingId,