diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/GetMyOrdersInput.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/GetMyOrdersInput.cs new file mode 100644 index 00000000..7c5f93c2 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/GetMyOrdersInput.cs @@ -0,0 +1,6 @@ +namespace EShopOnAbp.OrderingService.Orders; + +public class GetMyOrdersInput +{ + public string Filter { get; set; } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs index cf232c60..a14f75b8 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Application.Services; @@ -8,4 +9,5 @@ public interface IOrderAppService : IApplicationService { Task CreateAsync(OrderCreateDto input); Task GetAsync(Guid id); + Task> GetMyOrders(GetMyOrdersInput input); } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index bdb3fd17..d669f6cc 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using EShopOnAbp.OrderingService.Buyers; using EShopOnAbp.OrderingService.Localization; +using EShopOnAbp.OrderingService.Orders.Specifications; using Volo.Abp.Application.Services; +using Volo.Abp.Specifications; using Volo.Abp.Users; namespace EShopOnAbp.OrderingService.Orders; @@ -15,7 +16,7 @@ public class OrderAppService : ApplicationService, IOrderAppService public OrderAppService(OrderManager orderManager, IOrderRepository orderRepository - ) + ) { _orderManager = orderManager; _orderRepository = orderRepository; @@ -26,7 +27,19 @@ public class OrderAppService : ApplicationService, IOrderAppService public async Task GetAsync(Guid id) { var order = await _orderRepository.GetAsync(id); - return await CreateOrderDtoMappingAsync(order); + return CreateOrderDtoMapping(order); + } + + public async Task> GetMyOrders(GetMyOrdersInput input) + { + ISpecification specification = null; + if (!input.Filter.IsNullOrEmpty()) + { + specification = SpecificationFactory.Create(input.Filter); + } + + var orders = await _orderRepository.GetOrdersByUserId(CurrentUser.GetId(), specification, true); + return CreateOrderDtoMapping(orders); } public async Task CreateAsync(OrderCreateDto input) @@ -47,7 +60,7 @@ public class OrderAppService : ApplicationService, IOrderAppService addressDescription: input.Address.Description ); - return await CreateOrderDtoMappingAsync(placedOrder); + return CreateOrderDtoMapping(placedOrder); } private List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string @@ -67,7 +80,18 @@ public class OrderAppService : ApplicationService, IOrderAppService return orderItems; } - private async Task CreateOrderDtoMappingAsync(Order placedOrder) + private List CreateOrderDtoMapping(List orders) + { + List dtoList = new List(); + foreach (var order in orders) + { + dtoList.Add(CreateOrderDtoMapping(order)); + } + + return dtoList; + } + + private OrderDto CreateOrderDtoMapping(Order placedOrder) { return new OrderDto() {