Skip to content

Commit 5f9ad12

Browse files
committed
[AI:Coder, HUMAN:-, MODEL: Claude 3.7 Sonnet] (#1) Add CustomerOverdueOrdersData DTO, extend ICustomerService, and implement GetCustomersWithOverdueOrders
1 parent 7f066a6 commit 5f9ad12

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Contracts.Sales;
2+
3+
public sealed class CustomerOverdueOrdersData
4+
{
5+
public required string CustomerName { get; init; }
6+
public int OverdueOrderCount { get; init; }
7+
public DateTime OldestOverdueOrderDate { get; init; }
8+
}

Modules/Contracts/Sales/ICustomerService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public interface ICustomerService
77
CustomerData[] GetCustomersWithOrdersStartingWith(string prefix);
88

99
CustomerData[] GetCustomersWithOrdersContaining(string fragment);
10+
11+
CustomerOverdueOrdersData[] GetCustomersWithOverdueOrders();
1012
}

Modules/Sales/Sales.Services/CustomerService.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
using AppBoot.DependencyInjection;
44
using Contracts.Sales;
55
using DataAccess;
6+
using Microsoft.Extensions.Logging;
67
using Sales.DataModel.SalesLT;
8+
using Sales.DataModel.Values;
79

810
namespace Sales.Services;
911

1012
[Service(typeof(ICustomerService))]
11-
class CustomerService(IRepository repository) : ICustomerService
13+
class CustomerService(IRepository repository, ILogger<CustomerService> logger) : ICustomerService
1214
{
1315
public CustomerData[] GetCustomersWithOrders()
1416
{
@@ -52,4 +54,32 @@ public CustomerData[] GetCustomersWithOrdersContaining(string fragment)
5254

5355
return GetCustomersWithOrdersFilteredBy(filter);
5456
}
57+
58+
public CustomerOverdueOrdersData[] GetCustomersWithOverdueOrders()
59+
{
60+
logger.LogInformation("Retrieving customers with overdue orders");
61+
62+
var today = DateTime.Today;
63+
var closedStatuses = new[] { SalesOrderHeaderStatusValues.Shipped, SalesOrderHeaderStatusValues.Cancelled };
64+
65+
var results = repository.GetEntities<SalesOrderHeader>()
66+
.Where(o => o.DueDate < today && !closedStatuses.Contains(o.Status))
67+
.GroupBy(o => o.Customer)
68+
.Select(g => new CustomerOverdueOrdersData
69+
{
70+
CustomerName = !string.IsNullOrWhiteSpace(g.Key.CompanyName)
71+
? g.Key.CompanyName
72+
: !string.IsNullOrWhiteSpace(g.Key.FirstName) || !string.IsNullOrWhiteSpace(g.Key.LastName)
73+
? $"{g.Key.FirstName} {g.Key.LastName}".Trim()
74+
: $"Customer {g.Key.CustomerID}",
75+
OverdueOrderCount = g.Count(),
76+
OldestOverdueOrderDate = g.Min(o => o.DueDate)
77+
})
78+
.OrderBy(c => c.OldestOverdueOrderDate)
79+
.ToArray();
80+
81+
logger.LogDebug("Found {Count} customers with overdue orders", results.Length);
82+
83+
return results;
84+
}
5585
}

0 commit comments

Comments
 (0)