Skip to content

Commit 607d1ca

Browse files
Unai Zorrilla CastroUnai Zorrilla Castro
authored andcommitted
Fix query with new model. Add missing properties into migration. Work on github issues
1 parent 9d2d152 commit 607d1ca

12 files changed

Lines changed: 76 additions & 62 deletions

File tree

src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task<bool> Handle(CreateOrderCommand message)
3939
buyer = new Buyer(message.BuyerFullName);
4040
}
4141

42-
var payment = buyer.AddPayment(message.CardTypeId,
42+
var payment = buyer.AddPaymentMethod(message.CardTypeId,
4343
$"Payment Method on {DateTime.UtcNow}",
4444
message.CardNumber,
4545
message.CardSecurityNumber,

src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MediatR;
2+
using Microsoft.AspNetCore.Authorization;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
45
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;

src/Services/Ordering/Ordering.API/Infrastructure/Auth/AuthorizationHeaderParameterOperationFilter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using Microsoft.AspNetCore.Mvc.Authorization;
22
using Swashbuckle.Swagger.Model;
33
using Swashbuckle.SwaggerGen.Generator;
4-
using System;
54
using System.Collections.Generic;
65
using System.Linq;
7-
using System.Threading.Tasks;
86

97
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Auth
108
{

src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170125143653_Initial.Designer.cs renamed to src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs

Lines changed: 14 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170125143653_Initial.cs renamed to src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
7070
});
7171

7272
migrationBuilder.CreateTable(
73-
name: "payments",
73+
name: "paymentmethods",
7474
schema: "ordering",
7575
columns: table => new
7676
{
@@ -84,16 +84,16 @@ protected override void Up(MigrationBuilder migrationBuilder)
8484
},
8585
constraints: table =>
8686
{
87-
table.PrimaryKey("PK_payments", x => x.Id);
87+
table.PrimaryKey("PK_paymentmethods", x => x.Id);
8888
table.ForeignKey(
89-
name: "FK_payments_buyers_BuyerId",
89+
name: "FK_paymentmethods_buyers_BuyerId",
9090
column: x => x.BuyerId,
9191
principalSchema: "ordering",
9292
principalTable: "buyers",
9393
principalColumn: "Id",
9494
onDelete: ReferentialAction.Cascade);
9595
table.ForeignKey(
96-
name: "FK_payments_cardtypes_CardTypeId",
96+
name: "FK_paymentmethods_cardtypes_CardTypeId",
9797
column: x => x.CardTypeId,
9898
principalSchema: "ordering",
9999
principalTable: "cardtypes",
@@ -109,9 +109,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
109109
Id = table.Column<int>(nullable: false),
110110
BuyerId = table.Column<int>(nullable: false),
111111
City = table.Column<string>(nullable: false),
112+
Country = table.Column<string>(nullable: false),
112113
OrderDate = table.Column<DateTime>(nullable: false),
113114
OrderStatusId = table.Column<int>(nullable: false),
114-
PaymentId = table.Column<int>(nullable: false),
115+
PaymentMethodId = table.Column<int>(nullable: false),
115116
State = table.Column<string>(nullable: false),
116117
Street = table.Column<string>(nullable: false),
117118
ZipCode = table.Column<string>(nullable: false)
@@ -134,10 +135,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
134135
principalColumn: "Id",
135136
onDelete: ReferentialAction.Cascade);
136137
table.ForeignKey(
137-
name: "FK_orders_payments_PaymentId",
138-
column: x => x.PaymentId,
138+
name: "FK_orders_paymentmethods_PaymentMethodId",
139+
column: x => x.PaymentMethodId,
139140
principalSchema: "ordering",
140-
principalTable: "payments",
141+
principalTable: "paymentmethods",
141142
principalColumn: "Id",
142143
onDelete: ReferentialAction.Restrict);
143144
});
@@ -150,6 +151,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
150151
Id = table.Column<int>(nullable: false),
151152
Discount = table.Column<decimal>(nullable: false),
152153
OrderId = table.Column<int>(nullable: false),
154+
PictureUrl = table.Column<string>(nullable: true),
153155
ProductId = table.Column<int>(nullable: false),
154156
ProductName = table.Column<string>(nullable: false),
155157
UnitPrice = table.Column<decimal>(nullable: false),
@@ -175,15 +177,15 @@ protected override void Up(MigrationBuilder migrationBuilder)
175177
unique: true);
176178

177179
migrationBuilder.CreateIndex(
178-
name: "IX_payments_BuyerId",
180+
name: "IX_paymentmethods_BuyerId",
179181
schema: "ordering",
180-
table: "payments",
182+
table: "paymentmethods",
181183
column: "BuyerId");
182184

183185
migrationBuilder.CreateIndex(
184-
name: "IX_payments_CardTypeId",
186+
name: "IX_paymentmethods_CardTypeId",
185187
schema: "ordering",
186-
table: "payments",
188+
table: "paymentmethods",
187189
column: "CardTypeId");
188190

189191
migrationBuilder.CreateIndex(
@@ -199,10 +201,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
199201
column: "OrderStatusId");
200202

201203
migrationBuilder.CreateIndex(
202-
name: "IX_orders_PaymentId",
204+
name: "IX_orders_PaymentMethodId",
203205
schema: "ordering",
204206
table: "orders",
205-
column: "PaymentId");
207+
column: "PaymentMethodId");
206208

207209
migrationBuilder.CreateIndex(
208210
name: "IX_orderItems_OrderId",
@@ -226,7 +228,7 @@ protected override void Down(MigrationBuilder migrationBuilder)
226228
schema: "ordering");
227229

228230
migrationBuilder.DropTable(
229-
name: "payments",
231+
name: "paymentmethods",
230232
schema: "ordering");
231233

232234
migrationBuilder.DropTable(

src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
5454
b.ToTable("cardtypes","ordering");
5555
});
5656

57-
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
57+
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
5858
{
5959
b.Property<int>("Id")
6060
.ValueGeneratedOnAdd()
@@ -86,7 +86,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
8686

8787
b.HasIndex("CardTypeId");
8888

89-
b.ToTable("payments","ordering");
89+
b.ToTable("paymentmethods","ordering");
9090
});
9191

9292
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
@@ -102,11 +102,14 @@ protected override void BuildModel(ModelBuilder modelBuilder)
102102
b.Property<string>("City")
103103
.IsRequired();
104104

105+
b.Property<string>("Country")
106+
.IsRequired();
107+
105108
b.Property<DateTime>("OrderDate");
106109

107110
b.Property<int>("OrderStatusId");
108111

109-
b.Property<int>("PaymentId");
112+
b.Property<int>("PaymentMethodId");
110113

111114
b.Property<string>("State")
112115
.IsRequired();
@@ -123,7 +126,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
123126

124127
b.HasIndex("OrderStatusId");
125128

126-
b.HasIndex("PaymentId");
129+
b.HasIndex("PaymentMethodId");
127130

128131
b.ToTable("orders","ordering");
129132
});
@@ -139,6 +142,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
139142

140143
b.Property<int>("OrderId");
141144

145+
b.Property<string>("PictureUrl");
146+
142147
b.Property<int>("ProductId");
143148

144149
b.Property<string>("ProductName")
@@ -169,10 +174,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
169174
b.ToTable("orderstatus","ordering");
170175
});
171176

172-
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
177+
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
173178
{
174179
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
175-
.WithMany("Payments")
180+
.WithMany("PaymentMethods")
176181
.HasForeignKey("BuyerId")
177182
.OnDelete(DeleteBehavior.Cascade);
178183

@@ -194,9 +199,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
194199
.HasForeignKey("OrderStatusId")
195200
.OnDelete(DeleteBehavior.Cascade);
196201

197-
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
202+
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", "PaymentMethod")
198203
.WithMany()
199-
.HasForeignKey("PaymentId");
204+
.HasForeignKey("PaymentMethodId");
200205
});
201206

202207
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>

src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class Buyer
1010
{
1111
public string FullName { get; private set; }
1212

13-
private HashSet<Payment> _payments;
13+
private HashSet<PaymentMethod> _paymentMethods;
1414

15-
public IEnumerable<Payment> Payments => _payments?.ToList().AsEnumerable();
15+
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods?.ToList().AsEnumerable();
1616

1717
protected Buyer() { }
1818

@@ -25,12 +25,12 @@ public Buyer(string identity)
2525

2626
FullName = identity;
2727

28-
_payments = new HashSet<Payment>();
28+
_paymentMethods = new HashSet<PaymentMethod>();
2929
}
3030

31-
public Payment AddPayment(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
31+
public PaymentMethod AddPaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
3232
{
33-
var existingPayment = Payments.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
33+
var existingPayment = _paymentMethods.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
3434
.SingleOrDefault();
3535

3636
if (existingPayment != null)
@@ -39,9 +39,9 @@ public Payment AddPayment(int cardTypeId, string alias, string cardNumber, strin
3939
}
4040
else
4141
{
42-
var payment = new Payment(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
42+
var payment = new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
4343

44-
_payments.Add(payment);
44+
_paymentMethods.Add(payment);
4545

4646
return payment;
4747
}

src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Payment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
55
{
6-
public class Payment
6+
public class PaymentMethod
77
: Entity
88
{
99
private int _buyerId;
@@ -17,9 +17,9 @@ public class Payment
1717
public CardType CardType { get; private set; }
1818

1919

20-
protected Payment() { }
20+
protected PaymentMethod() { }
2121

22-
public Payment(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
22+
public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
2323
{
2424
if (String.IsNullOrWhiteSpace(cardNumber))
2525
{

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
22

33
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
4-
{
5-
4+
{
65
//This is just the RepositoryContracts or Interface defined at the Domain Layer
76
//as requisite for the Order Aggregate
87
public interface IOrderRepository

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
99
public class Order
1010
: Entity
1111
{
12-
1312
private string _street;
1413
private string _city;
1514
private string _state;
@@ -26,16 +25,16 @@ public class Order
2625
HashSet<OrderItem> _orderItems;
2726
public IEnumerable<OrderItem> OrderItems => _orderItems.ToList().AsEnumerable();
2827

29-
public Payment Payment { get; private set; }
30-
int _paymentId;
28+
public PaymentMethod PaymentMethod { get; private set; }
29+
int _paymentMethodId;
3130

3231
protected Order() { }
3332

34-
public Order(int buyerId, int paymentId, Address address)
33+
public Order(int buyerId, int paymentMethodId, Address address)
3534
{
3635

3736
_buyerId = buyerId;
38-
_paymentId = paymentId;
37+
_paymentMethodId = paymentMethodId;
3938
_orderStatusId = OrderStatus.InProcess.Id;
4039
_orderDate = DateTime.UtcNow;
4140
_street = address.Street;

0 commit comments

Comments
 (0)