Browse Source

Added SetOrder for different situation

Still need the improvement
pull/92/head
malik masis 5 years ago
parent
commit
418f060507
  1. 1
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs
  2. 2
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs
  3. 7
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/UpdateOrderDto.cs
  4. 17
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  5. 21
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs
  6. 7
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs
  7. 9
      services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs
  8. 57
      services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/ordering-generate-proxy.json
  9. 12
      services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs

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

@ -12,4 +12,5 @@ public interface IOrderAppService : IApplicationService
Task<List<OrderDto>> GetMyOrdersAsync(GetMyOrdersInput input);
Task<List<OrderDto>> GetOrdersAsync(GetOrdersInput input);
Task<OrderDto> GetByOrderNoAsync(int orderNo);
Task<OrderDto> UpdateAsync(Guid id, UpdateOrderDto input);
}

2
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs

@ -7,7 +7,7 @@ namespace EShopOnAbp.OrderingService.Orders;
public class OrderDto : EntityDto<Guid>
{
public DateTime OrderDate { get; set; }
public int OrderNo {get;set;}
public int OrderNo { get; set; }
public int OrderStatusId { get; set; }
public string OrderStatus { get; set; }
public string PaymentMethod { get; set; }

7
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/UpdateOrderDto.cs

@ -0,0 +1,7 @@
namespace EShopOnAbp.OrderingService.Orders
{
public class UpdateOrderDto
{
public int OrderStatusId { get; set; }
}
}

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

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EShopOnAbp.OrderingService.Localization;
using EShopOnAbp.OrderingService.Localization;
using EShopOnAbp.OrderingService.Orders.Specifications;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Specifications;
using Volo.Abp.Users;
@ -52,6 +52,15 @@ public class OrderAppService : ApplicationService, IOrderAppService
return CreateOrderDtoMapping(order);
}
public async Task<OrderDto> UpdateAsync(Guid id, UpdateOrderDto input)
{
var order = await _orderRepository.GetAsync(id);
order.SetOrder(input.OrderStatusId);
await _orderRepository.UpdateAsync(order);
return CreateOrderDtoMapping(order);
}
public async Task<OrderDto> CreateAsync(OrderCreateDto input)
{
var orderItems = GetProductListTuple(input.Products);

21
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs

@ -1,8 +1,8 @@
using System;
using EShopOnAbp.PaymentService.PaymentRequests;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using EShopOnAbp.PaymentService.PaymentRequests;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
@ -25,7 +25,7 @@ public class Order : AggregateRoot<Guid>
{
}
internal Order(Guid id, Buyer buyer, Address address, [NotNull]string paymentMethod, Guid? paymentRequestId = null) : base(id)
internal Order(Guid id, Buyer buyer, Address address, [NotNull] string paymentMethod, Guid? paymentRequestId = null) : base(id)
{
_orderStatusId = OrderStatus.Placed.Id;
OrderDate = DateTime.UtcNow;
@ -33,7 +33,7 @@ public class Order : AggregateRoot<Guid>
Buyer = buyer;
Address = address;
PaymentRequestId = paymentRequestId;
PaymentMethod = Check.NotNullOrEmpty(paymentMethod,nameof(paymentMethod),maxLength:OrderConstants.OrderPaymentMethodNameMaxLength);
PaymentMethod = Check.NotNullOrEmpty(paymentMethod, nameof(paymentMethod), maxLength: OrderConstants.OrderPaymentMethodNameMaxLength);
PaymentStatus = PaymentRequestState.Waiting.ToString(); // From PaymentService.Domain.Shared
OrderItems = new List<OrderItem>();
}
@ -87,4 +87,15 @@ public class Order : AggregateRoot<Guid>
{
return OrderItems.Sum(o => o.Units * o.UnitPrice);
}
public Order SetOrder(int orderStatus)
{
if (orderStatus == OrderStatus.Cancelled.Id)
{
return this;
}
//TODO no enough to update the object.
_orderStatusId = orderStatus;
return this;
}
}

7
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs

@ -5,6 +5,7 @@ using Volo.Abp;
namespace EShopOnAbp.OrderingService.Orders;
//TODO will use enum instead of Enumeration
public class OrderStatus : Enumeration
{
public static OrderStatus Placed = new OrderStatus(1, nameof(Placed).ToLowerInvariant());
@ -22,12 +23,12 @@ public class OrderStatus : Enumeration
public static OrderStatus FromName(string name)
{
var state = List()
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
.SingleOrDefault(s => string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
if (state == null)
{
throw new BusinessException(OrderingServiceErrorCodes.OrderingStatusNotFound)
.WithData("OrderStatus", String.Join(",", List().Select(s => s.Name)));
.WithData("OrderStatus", string.Join(",", List().Select(s => s.Name)));
}
return state;
@ -40,7 +41,7 @@ public class OrderStatus : Enumeration
if (state == null)
{
throw new BusinessException(OrderingServiceErrorCodes.OrderingStatusNotFound)
.WithData("OrderStatus", String.Join(",", List().Select(s => s.Name)));
.WithData("OrderStatus", string.Join(",", List().Select(s => s.Name)));
}
return state;

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

@ -48,6 +48,15 @@ public partial class OrderClientProxy : ClientProxyBase<IOrderAppService>, IOrde
});
}
public virtual async Task<OrderDto> UpdateAsync(Guid id, UpdateOrderDto input)
{
return await RequestAsync<OrderDto>(nameof(UpdateAsync), new ClientProxyRequestTypeValue
{
{ typeof(Guid), id },
{ typeof(UpdateOrderDto), input }
});
}
public virtual async Task<OrderDto> CreateAsync(OrderCreateDto input)
{
return await RequestAsync<OrderDto>(nameof(CreateAsync), new ClientProxyRequestTypeValue

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

@ -171,6 +171,63 @@
"allowAnonymous": null,
"implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService"
},
"UpdateAsyncByIdAndInput": {
"uniqueName": "UpdateAsyncByIdAndInput",
"name": "UpdateAsync",
"httpMethod": "PUT",
"url": "api/ordering/order/{id}",
"supportedVersions": [],
"parametersOnMethod": [
{
"name": "id",
"typeAsString": "System.Guid, System.Private.CoreLib",
"type": "System.Guid",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
},
{
"name": "input",
"typeAsString": "EShopOnAbp.OrderingService.Orders.UpdateOrderDto, EShopOnAbp.OrderingService.Application.Contracts",
"type": "EShopOnAbp.OrderingService.Orders.UpdateOrderDto",
"typeSimple": "EShopOnAbp.OrderingService.Orders.UpdateOrderDto",
"isOptional": false,
"defaultValue": null
}
],
"parameters": [
{
"nameOnMethod": "id",
"name": "id",
"jsonName": null,
"type": "System.Guid",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null,
"constraintTypes": [],
"bindingSourceId": "Path",
"descriptorName": ""
},
{
"nameOnMethod": "input",
"name": "input",
"jsonName": null,
"type": "EShopOnAbp.OrderingService.Orders.UpdateOrderDto",
"typeSimple": "EShopOnAbp.OrderingService.Orders.UpdateOrderDto",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "Body",
"descriptorName": ""
}
],
"returnValue": {
"type": "EShopOnAbp.OrderingService.Orders.OrderDto",
"typeSimple": "EShopOnAbp.OrderingService.Orders.OrderDto"
},
"allowAnonymous": null,
"implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService"
},
"CreateAsyncByInput": {
"uniqueName": "CreateAsyncByInput",
"name": "CreateAsync",

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

@ -39,7 +39,8 @@ public class OrderApplication_Tests : OrderingServiceApplicationTestBase
new OrderItemCreateDto()
{
Discount = 0,
Units = 2, PictureUrl = string.Empty,
Units = 2,
PictureUrl = string.Empty,
ProductCode = "Test-001",
ProductId = Guid.NewGuid(),
ProductName = "Test product",
@ -65,6 +66,15 @@ public class OrderApplication_Tests : OrderingServiceApplicationTestBase
var myOrder = await _orderAppService.GetByOrderNoAsync(placedOrder.OrderNo);
myOrder.ShouldNotBeNull();
var cancelledMyOrder = await _orderAppService.UpdateAsync(placedOrder.Id, new UpdateOrderDto()
{
OrderStatusId = OrderStatus.Cancelled.Id,
});
//TODO - temp value - it should be Cancelled
cancelledMyOrder.OrderStatus.ShouldBe(OrderStatus.Placed.ToString());
// Get all orders
var orders = await _orderAppService.GetOrdersAsync(new GetOrdersInput()
{

Loading…
Cancel
Save