Browse Source

added application service method

pull/56/head
Galip Tolga Erdem 5 years ago
parent
commit
ce55206c04
  1. 6
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/GetMyOrdersInput.cs
  2. 2
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs
  3. 34
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs

6
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; }
}

2
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<OrderDto> CreateAsync(OrderCreateDto input);
Task<OrderDto> GetAsync(Guid id);
Task<List<OrderDto>> GetMyOrders(GetMyOrdersInput input);
}

34
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<OrderDto> GetAsync(Guid id)
{
var order = await _orderRepository.GetAsync(id);
return await CreateOrderDtoMappingAsync(order);
return CreateOrderDtoMapping(order);
}
public async Task<List<OrderDto>> GetMyOrders(GetMyOrdersInput input)
{
ISpecification<Order> 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<OrderDto> 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<OrderDto> CreateOrderDtoMappingAsync(Order placedOrder)
private List<OrderDto> CreateOrderDtoMapping(List<Order> orders)
{
List<OrderDto> dtoList = new List<OrderDto>();
foreach (var order in orders)
{
dtoList.Add(CreateOrderDtoMapping(order));
}
return dtoList;
}
private OrderDto CreateOrderDtoMapping(Order placedOrder)
{
return new OrderDto()
{

Loading…
Cancel
Save