Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get order at Add Phone Order Conversations #115

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Serilog;
using SmartTalk.Core.Domain.PhoneOrder;
using SmartTalk.Messages.Dto.PhoneOrder;
using SmartTalk.Messages.Commands.PhoneOrder;
Expand Down Expand Up @@ -39,6 +40,15 @@ public async Task<AddPhoneOrderConversationsResponse> AddPhoneOrderConversations

var conversationsList = string.Concat(string.Join(",", conversations.Select(x => x.Question)), string.Join(",", conversations.Select(x => x.Answer)));

var orderItems = await _phoneOrderDataProvider.GetPhoneOrderOrderItemsAsync(command.Conversations.First().RecordId, cancellationToken: cancellationToken).ConfigureAwait(false);

if (orderItems.Any())
{
await _phoneOrderDataProvider.DeletePhoneOrderItemsAsync(orderItems,true, cancellationToken).ConfigureAwait(false);

Log.Information("Delete Phone Order Items When Add Phone Order Conversations {@orderItems}", orderItems);
}

await _phoneOrderUtilService.ExtractPhoneOrderShoppingCartAsync(conversationsList, record, cancellationToken).ConfigureAwait(false);

return new AddPhoneOrderConversationsResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,32 @@ public async Task ShouldGetOrAddPhoneOrderConversations()
},
};

var items = new List<PhoneOrderOrderItem>()
{
new PhoneOrderOrderItem()
{
Id = 1,
RecordId = 1,
FoodName = "BBQ",
Quantity = 1,
Price = 1,
OrderType = PhoneOrderOrderType.AIOrder
},
new PhoneOrderOrderItem()
{
Id = 2,
RecordId = 1,
FoodName = "BBc",
Quantity = 2,
Price = 2,
OrderType = PhoneOrderOrderType.AIOrder
}
};

await RunWithUnitOfWork<IRepository>(async repository =>
{
await repository.InsertAsync(record);
await repository.InsertAllAsync(items);
await repository.InsertAllAsync(conversations);
});

Expand Down Expand Up @@ -173,10 +196,14 @@ await mediator.SendAsync<AddPhoneOrderConversationsCommand, AddPhoneOrderConvers

var afterAdd = await repository.Query<PhoneOrderConversation>().ToListAsync();

var afterItems = await repository.Query<PhoneOrderOrderItem>().ToListAsync();

afterAdd.ShouldNotBeNull();
afterAdd.All(x => x.Question.Contains("早上好")).ShouldBeTrue();
afterAdd.All(x => x.Answer.Contains("中午好")).ShouldBeTrue();
afterAdd.Count.ShouldBe(4);

afterItems.Count.ShouldBe(0);
},
builder =>
{
Expand Down