Browse Source

updated specification implementation

pull/56/head
Galip Tolga Erdem 5 years ago
parent
commit
81a96d2fd4
  1. 9
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  2. 6
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Specifications/Last30DaysSpecification.cs
  3. 4
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Specifications/MonthsAgoSpecification.cs
  4. 8
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Specifications/SpecificationFactory.cs
  5. 1
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs

9
services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs

@ -32,13 +32,10 @@ public class OrderAppService : ApplicationService, IOrderAppService
public async Task<List<OrderDto>> GetMyOrdersAsync(GetMyOrdersInput input)
{
ISpecification<Order> specification = null;
if (!input.Filter.IsNullOrEmpty())
{
specification = SpecificationFactory.Create(input.Filter);
}
ISpecification<Order> specification = SpecificationFactory.Create(input.Filter);
var orders = await _orderRepository.GetOrdersByUserId(CurrentUser.GetId(), specification, true);
return CreateOrderDtoMapping(orders);
}

6
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Specifications/Last30DaysSpecification.cs

@ -8,7 +8,9 @@ public class Last30DaysSpecification : Specification<Order>
{
public override Expression<Func<Order, bool>> ToExpression()
{
var daysAgo30 = DateTime.Now.AddDays(-30);
return query => query.OrderDate >= daysAgo30 && query.OrderDate <= DateTime.Now;
var daysAgo30 = DateTime.UtcNow.Subtract(TimeSpan.FromDays(30));
return query => query.OrderDate >= daysAgo30
;
// && query.OrderDate <= DateTime.UtcNow;
}
}

4
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Specifications/MonthsAgoSpecification.cs

@ -15,7 +15,7 @@ public class MonthsAgoSpecification : Specification<Order>
public override Expression<Func<Order, bool>> ToExpression()
{
var monthsAgo = DateTime.Now.AddMonths(NumberOfMonths);
return query => query.OrderDate >= monthsAgo && query.OrderDate <= DateTime.Now;
var monthsAgo = DateTime.UtcNow.AddMonths(-NumberOfMonths);
return query => query.OrderDate >= monthsAgo;
}
}

8
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Specifications/SpecificationFactory.cs

@ -1,4 +1,5 @@
using Volo.Abp.Specifications;
using System;
using Volo.Abp.Specifications;
namespace EShopOnAbp.OrderingService.Orders.Specifications;
@ -6,6 +7,11 @@ public static class SpecificationFactory
{
public static ISpecification<Order> Create(string filter)
{
if (filter.IsNullOrEmpty())
{
return new Last30DaysSpecification();
}
if (filter.StartsWith("y"))
{
var year = int.Parse(filter.Split('y')[1]);

1
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs

@ -38,6 +38,7 @@ public class EfCoreOrderRepository : EfCoreRepository<OrderingServiceDbContext,
.IncludeDetails(includeDetails)
.Where(q=>q.Buyer.Id == userId)
.Where(spec.ToExpression())
.OrderByDescending(o=>o.OrderDate)
.ToListAsync(GetCancellationToken(cancellationToken));
}

Loading…
Cancel
Save