Browse Source

Top 10 selling products

Added action named GetTopSellingAsync
pull/110/head
malik masis 4 years ago
parent
commit
afd10a736e
  1. 12
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderItems/TopSellingDto.cs
  2. 7
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderItems/TopSellingInput.cs
  3. 3
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderingServiceRemoteServiceConsts.cs
  4. 4
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs
  5. 4
      services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs
  6. 10
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  7. 5
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs
  8. 1
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EShopOnAbp.OrderingService.EntityFrameworkCore.csproj
  9. 18
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs
  10. 9
      services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs
  11. 37
      services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/ordering-generate-proxy.json
  12. 9
      services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs

12
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderItems/TopSellingDto.cs

@ -0,0 +1,12 @@
using System;
using Volo.Abp.Application.Dtos;
namespace EShopOnAbp.OrderingService.OrderItems
{
public class TopSellingDto : EntityDto<Guid>
{
public string ProductName { get; set; }
public string PictureUrl { get; set; }
public int Units { get; set; }
}
}

7
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderItems/TopSellingInput.cs

@ -0,0 +1,7 @@
namespace EShopOnAbp.OrderingService.OrderItems
{
public class TopSellingInput
{
public string Filter { get; set; }
}
}

3
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderingServiceRemoteServiceConsts.cs

@ -1,7 +1,8 @@
namespace EShopOnAbp.OrderingService
{
public class OrderingServiceRemoteServiceConsts
public static class OrderingServiceRemoteServiceConsts
{
public const string RemoteServiceName = "Ordering";
public const int Top10 = 10;
}
}

4
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs

@ -1,4 +1,5 @@
using System;
using EShopOnAbp.OrderingService.OrderItems;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
@ -16,5 +17,6 @@ public interface IOrderAppService : IApplicationService
Task SetAsCancelledAsync(Guid id, SetAsCancelledDto input);
Task SetAsShippedAsync(Guid id);
Task<PagedResultDto<OrderDto>> GetListPagedAsync(PagedAndSortedResultRequestDto input);
Task<List<TopSellingDto>> GetTopSellingAsync(TopSellingInput input);
}

4
services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs

@ -1,5 +1,6 @@
using AutoMapper;
using EShopOnAbp.OrderingService.Orders;
using EShopOnAbp.OrderingService.OrderItems;
using Volo.Abp.AutoMapper;
namespace EShopOnAbp.OrderingService
@ -12,7 +13,8 @@ namespace EShopOnAbp.OrderingService
CreateMap<Buyer, BuyerDto>();
CreateMap<OrderItem, OrderItemDto>();
CreateMap<OrderItem, TopSellingDto > ();
CreateMap<Order, OrderDto>()
.Ignore(q => q.Address)
.Ignore(q => q.Items)

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

@ -1,4 +1,5 @@
using EShopOnAbp.OrderingService.Localization;
using EShopOnAbp.OrderingService.OrderItems;
using EShopOnAbp.OrderingService.Orders.Specifications;
using EShopOnAbp.OrderingService.Permissions;
using Microsoft.AspNetCore.Authorization;
@ -43,7 +44,7 @@ public class OrderAppService : ApplicationService, IOrderAppService
return CreateOrderDtoMapping(orders);
}
//[Authorize(OrderingServicePermissions.Orders.Default)]
[Authorize(OrderingServicePermissions.Orders.Default)]
public async Task<List<OrderDto>> GetOrdersAsync(GetOrdersInput input)
{
ISpecification<Order> specification = SpecificationFactory.Create(input.Filter);
@ -70,6 +71,13 @@ public class OrderAppService : ApplicationService, IOrderAppService
);
}
public async Task<List<TopSellingDto>> GetTopSellingAsync(TopSellingInput input)
{
ISpecification<Order> specification = SpecificationFactory.Create(input.Filter);
var orderItems = await _orderRepository.GetTopSelling(specification, true);
return ObjectMapper.Map<List<OrderItem>, List<TopSellingDto>>(orderItems);
}
public async Task<OrderDto> GetByOrderNoAsync(int orderNo)
{
var order = await _orderRepository.GetByOrderNoAsync(orderNo);

5
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs

@ -20,6 +20,11 @@ public interface IOrderRepository : IRepository<Order, Guid>
bool includeDetails = true,
CancellationToken cancellationToken = default);
Task<List<OrderItem>> GetTopSelling(
ISpecification<Order> spec,
bool includeDetails = true,
CancellationToken cancellationToken = default);
Task<Order> GetByOrderNoAsync(int orderNo,
bool includeDetails = true,
CancellationToken cancellationToken = default);

1
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EShopOnAbp.OrderingService.EntityFrameworkCore.csproj

@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\EShopOnAbp.OrderingService.Domain\EShopOnAbp.OrderingService.Domain.csproj" />
<ProjectReference Include="..\EShopOnAbp.OrderingService.Application.Contracts\EShopOnAbp.OrderingService.Application.Contracts.csproj" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.PostgreSql" Version="5.1.2" />
</ItemGroup>

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

@ -54,6 +54,24 @@ public class EfCoreOrderRepository : EfCoreRepository<OrderingServiceDbContext,
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OrderItem>> GetTopSelling(
ISpecification<Order> spec,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return (await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(spec.ToExpression())
.SelectMany(oi => oi.OrderItems)
.GroupBy(p => p.ProductCode)
.OrderByDescending(o => o.Sum(p => p.Units))
.Select(o => o.ToList())
.ToListAsync())
.SelectMany(t => t)
.Take(OrderingServiceRemoteServiceConsts.Top10)
.ToList();
}
public async Task<Order> GetByOrderNoAsync(
int orderNo,
bool includeDetails = true,

9
services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs

@ -8,6 +8,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Client.ClientProxying;
using EShopOnAbp.OrderingService.Orders;
using System.Collections.Generic;
using EShopOnAbp.OrderingService.OrderItems;
// ReSharper disable once CheckNamespace
namespace EShopOnAbp.OrderingService.Orders.ClientProxies;
@ -48,6 +49,14 @@ public partial class OrderClientProxy : ClientProxyBase<IOrderAppService>, IOrde
});
}
public virtual async Task<List<TopSellingDto>> GetTopSellingAsync(TopSellingInput input)
{
return await RequestAsync<List<TopSellingDto>>(nameof(GetTopSellingAsync), new ClientProxyRequestTypeValue
{
{ typeof(TopSellingInput), input }
});
}
public virtual async Task<OrderDto> GetByOrderNoAsync(int orderNo)
{
return await RequestAsync<OrderDto>(nameof(GetByOrderNoAsync), new ClientProxyRequestTypeValue

37
services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/ordering-generate-proxy.json

@ -195,6 +195,43 @@
"allowAnonymous": false,
"implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService"
},
"GetTopSellingAsyncByInput": {
"uniqueName": "GetTopSellingAsyncByInput",
"name": "GetTopSellingAsync",
"httpMethod": "GET",
"url": "api/ordering/order/top-selling",
"supportedVersions": [],
"parametersOnMethod": [
{
"name": "input",
"typeAsString": "EShopOnAbp.OrderingService.OrderItems.TopSellingInput, EShopOnAbp.OrderingService.Application.Contracts",
"type": "EShopOnAbp.OrderingService.OrderItems.TopSellingInput",
"typeSimple": "EShopOnAbp.OrderingService.OrderItems.TopSellingInput",
"isOptional": false,
"defaultValue": null
}
],
"parameters": [
{
"nameOnMethod": "input",
"name": "Filter",
"jsonName": null,
"type": "System.String",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "ModelBinding",
"descriptorName": "input"
}
],
"returnValue": {
"type": "System.Collections.Generic.List<EShopOnAbp.OrderingService.OrderItems.TopSellingDto>",
"typeSimple": "[EShopOnAbp.OrderingService.OrderItems.TopSellingDto]"
},
"allowAnonymous": null,
"implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService"
},
"GetByOrderNoAsyncByOrderNo": {
"uniqueName": "GetByOrderNoAsyncByOrderNo",
"name": "GetByOrderNoAsync",

9
services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs

@ -66,15 +66,6 @@ public class OrderApplication_Tests : OrderingServiceApplicationTestBase
var myOrder = await _orderAppService.GetByOrderNoAsync(placedOrder.OrderNo);
myOrder.ShouldNotBeNull();
var cancelledMyOrder = await _orderAppService.SetAsCancelledAsync(placedOrder.Id, new SetAsCancelledDto()
{
OrderStatusId = OrderStatus.Shipped.Id,
});
//TODO - temp value - it should be Shipped
cancelledMyOrder.OrderStatus.ShouldBe(OrderStatus.Placed.ToString());
// Get all orders
var orders = await _orderAppService.GetOrdersAsync(new GetOrdersInput()
{

Loading…
Cancel
Save