Skip to content

Commit 21fe9b7

Browse files
committed
Create checkout call in webmvc
Created Cancel call in webmvc
1 parent 46ee0db commit 21fe9b7

24 files changed

Lines changed: 415 additions & 172 deletions

File tree

src/Services/Basket/Basket.API/Controllers/BasketController.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
1010
using Basket.API.IntegrationEvents.Events;
1111
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
12+
using Basket.API.Model;
1213

1314
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
1415
{
@@ -50,20 +51,23 @@ public async Task<IActionResult> Post([FromBody]CustomerBasket value)
5051
return Ok(basket);
5152
}
5253

53-
[Route("checkouts")]
54-
[HttpPost]
55-
public async Task<IActionResult> Checkout()
54+
[Route("checkout")]
55+
[HttpPut]
56+
public async Task<IActionResult> Checkout([FromBody]BasketCheckout value)
5657
{
5758
var userId = _identitySvc.GetUserIdentity();
5859
var basket = await _repository.GetBasketAsync(userId);
59-
_eventBus.Publish(new UserCheckoutAccepted(userId, basket));
60+
var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, value.City, value.Street,
61+
value.State, value.Country, value.ZipCode, value.CardNumber, value.CardHolderName,
62+
value.CardExpiration, value.CardSecurityNumber, value.CardTypeId, value.Buyer, value.RequestId, basket);
63+
64+
_eventBus.Publish(eventMessage);
65+
6066
if (basket == null)
6167
{
6268
return BadRequest();
6369
}
6470

65-
66-
6771
return Accepted();
6872
}
6973

src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAccepted.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
2+
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Basket.API.IntegrationEvents.Events
9+
{
10+
public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
11+
{
12+
public string UserId { get; }
13+
14+
public int OrderNumber { get; set; }
15+
16+
public string City { get; set; }
17+
18+
public string Street { get; set; }
19+
20+
public string State { get; set; }
21+
22+
public string Country { get; set; }
23+
24+
public string ZipCode { get; set; }
25+
26+
public string CardNumber { get; set; }
27+
28+
public string CardHolderName { get; set; }
29+
30+
public DateTime CardExpiration { get; set; }
31+
32+
public string CardSecurityNumber { get; set; }
33+
34+
public int CardTypeId { get; set; }
35+
36+
public string Buyer { get; set; }
37+
38+
public Guid RequestId { get; set; }
39+
40+
public CustomerBasket Basket { get; }
41+
42+
public UserCheckoutAcceptedIntegrationEvent(string userId, string city, string street,
43+
string state, string country, string zipCode, string cardNumber, string cardHolderName,
44+
DateTime cardExpiration, string cardSecurityNumber, int cardTypeId, string buyer, Guid requestId,
45+
CustomerBasket basket)
46+
{
47+
UserId = userId;
48+
City = city;
49+
Street = street;
50+
State = state;
51+
Country = country;
52+
ZipCode = zipCode;
53+
CardNumber = cardNumber;
54+
CardHolderName = cardHolderName;
55+
CardExpiration = cardExpiration;
56+
CardSecurityNumber = cardSecurityNumber;
57+
CardTypeId = cardTypeId;
58+
Buyer = buyer;
59+
Basket = basket;
60+
RequestId = requestId;
61+
}
62+
63+
}
64+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Basket.API.Model
7+
{
8+
public class BasketCheckout
9+
{
10+
public string City { get; set; }
11+
12+
public string Street { get; set; }
13+
14+
public string State { get; set; }
15+
16+
public string Country { get; set; }
17+
18+
public string ZipCode { get; set; }
19+
20+
public string CardNumber { get; set; }
21+
22+
public string CardHolderName { get; set; }
23+
24+
public DateTime CardExpiration { get; set; }
25+
26+
public string CardSecurityNumber { get; set; }
27+
28+
public int CardTypeId { get; set; }
29+
30+
public string Buyer { get; set; }
31+
32+
public Guid RequestId { get; set; }
33+
}
34+
}
35+

src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/SubmitOrderCommandMsg.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
2+
using Ordering.API.Application.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Ordering.API.Application.IntegrationEvents.Events
9+
{
10+
public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
11+
{
12+
public string UserId { get; }
13+
14+
public string City { get; set; }
15+
16+
public string Street { get; set; }
17+
18+
public string State { get; set; }
19+
20+
public string Country { get; set; }
21+
22+
public string ZipCode { get; set; }
23+
24+
public string CardNumber { get; set; }
25+
26+
public string CardHolderName { get; set; }
27+
28+
public DateTime CardExpiration { get; set; }
29+
30+
public string CardSecurityNumber { get; set; }
31+
32+
public int CardTypeId { get; set; }
33+
34+
public string Buyer { get; set; }
35+
36+
public Guid RequestId { get; set; }
37+
38+
public CustomerBasket Basket { get; }
39+
40+
public UserCheckoutAcceptedIntegrationEvent(string userId, string city, string street,
41+
string state, string country, string zipCode, string cardNumber, string cardHolderName,
42+
DateTime cardExpiration, string cardSecurityNumber, int cardTypeId, string buyer, Guid requestId,
43+
CustomerBasket basket)
44+
{
45+
UserId = userId;
46+
City = city;
47+
Street = street;
48+
State = state;
49+
Country = country;
50+
ZipCode = zipCode;
51+
CardNumber = cardNumber;
52+
CardHolderName = cardHolderName;
53+
CardExpiration = cardExpiration;
54+
CardSecurityNumber = cardSecurityNumber;
55+
CardTypeId = cardTypeId;
56+
Buyer = buyer;
57+
Basket = basket;
58+
RequestId = requestId;
59+
}
60+
61+
}
62+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Ordering.API.Application.Models
7+
{
8+
public class BasketItem
9+
{
10+
public string Id { get; set; }
11+
public string ProductId { get; set; }
12+
public string ProductName { get; set; }
13+
public decimal UnitPrice { get; set; }
14+
public decimal OldUnitPrice { get; set; }
15+
public int Quantity { get; set; }
16+
public string PictureUrl { get; set; }
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Ordering.API.Application.Models
7+
{
8+
public class CustomerBasket
9+
{
10+
public string BuyerId { get; set; }
11+
public List<BasketItem> Items { get; set; }
12+
13+
public CustomerBasket(string customerId)
14+
{
15+
BuyerId = customerId;
16+
Items = new List<BasketItem>();
17+
}
18+
}
19+
}

src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
88
using Ordering.API.Application.Commands;
99
using Ordering.API.Application.IntegrationCommands.Commands;
10+
using Ordering.API.Application.IntegrationEvents.Events;
1011
using Ordering.Domain.Exceptions;
1112
using System;
1213
using System.Threading.Tasks;
@@ -22,7 +23,7 @@ namespace Ordering.API.Application.Sagas
2223
/// with the validations.
2324
/// </summary>
2425
public class OrderProcessSaga : Saga<Order>,
25-
IIntegrationEventHandler<SubmitOrderCommandMsg>,
26+
IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>,
2627
IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>,
2728
IAsyncRequestHandler<CancelOrderCommand, bool>
2829
{
@@ -48,10 +49,10 @@ public OrderProcessSaga(
4849
/// order items.
4950
/// </param>
5051
/// <returns></returns>
51-
public async Task Handle(SubmitOrderCommandMsg command)
52+
public async Task Handle(UserCheckoutAcceptedIntegrationEvent command)
5253
{
53-
var orderSaga = FindSagaById(command.OrderNumber);
54-
CheckValidSagaId(orderSaga);
54+
55+
var commanda = command;
5556

5657
// TODO: This handler should change to Integration command handler type once command bus is implemented
5758

0 commit comments

Comments
 (0)