Browse Source

Fix query with new model. Add missing properties into migration. Work on github issues

pull/49/merge
Unai Zorrilla Castro 8 years ago
parent
commit
607d1ca2fa
12 changed files with 76 additions and 62 deletions
  1. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  2. +1
    -0
      src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs
  3. +0
    -2
      src/Services/Ordering/Ordering.API/Infrastructure/Auth/AuthorizationHeaderParameterOperationFilter.cs
  4. +14
    -9
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs
  5. +17
    -15
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.cs
  6. +13
    -8
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs
  7. +7
    -7
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs
  8. +3
    -3
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Payment.cs
  9. +1
    -2
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs
  10. +4
    -5
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  11. +14
    -9
      src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs
  12. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs

+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -39,7 +39,7 @@
buyer = new Buyer(message.BuyerFullName);
}
var payment = buyer.AddPayment(message.CardTypeId,
var payment = buyer.AddPaymentMethod(message.CardTypeId,
$"Payment Method on {DateTime.UtcNow}",
message.CardNumber,
message.CardSecurityNumber,


+ 1
- 0
src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs View File

@ -1,4 +1,5 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;


+ 0
- 2
src/Services/Ordering/Ordering.API/Infrastructure/Auth/AuthorizationHeaderParameterOperationFilter.cs View File

@ -1,10 +1,8 @@
using Microsoft.AspNetCore.Mvc.Authorization;
using Swashbuckle.Swagger.Model;
using Swashbuckle.SwaggerGen.Generator;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Auth
{


src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170125143653_Initial.Designer.cs → src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs View File

@ -8,7 +8,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
namespace Ordering.API.Migrations
{
[DbContext(typeof(OrderingContext))]
[Migration("20170125143653_Initial")]
[Migration("20170127103457_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -55,7 +55,7 @@ namespace Ordering.API.Migrations
b.ToTable("cardtypes","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -87,7 +87,7 @@ namespace Ordering.API.Migrations
b.HasIndex("CardTypeId");
b.ToTable("payments","ordering");
b.ToTable("paymentmethods","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
@ -103,11 +103,14 @@ namespace Ordering.API.Migrations
b.Property<string>("City")
.IsRequired();
b.Property<string>("Country")
.IsRequired();
b.Property<DateTime>("OrderDate");
b.Property<int>("OrderStatusId");
b.Property<int>("PaymentId");
b.Property<int>("PaymentMethodId");
b.Property<string>("State")
.IsRequired();
@ -124,7 +127,7 @@ namespace Ordering.API.Migrations
b.HasIndex("OrderStatusId");
b.HasIndex("PaymentId");
b.HasIndex("PaymentMethodId");
b.ToTable("orders","ordering");
});
@ -140,6 +143,8 @@ namespace Ordering.API.Migrations
b.Property<int>("OrderId");
b.Property<string>("PictureUrl");
b.Property<int>("ProductId");
b.Property<string>("ProductName")
@ -170,10 +175,10 @@ namespace Ordering.API.Migrations
b.ToTable("orderstatus","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
.WithMany("Payments")
.WithMany("PaymentMethods")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
@ -195,9 +200,9 @@ namespace Ordering.API.Migrations
.HasForeignKey("OrderStatusId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", "PaymentMethod")
.WithMany()
.HasForeignKey("PaymentId");
.HasForeignKey("PaymentMethodId");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>

src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170125143653_Initial.cs → src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.cs View File

@ -70,7 +70,7 @@ namespace Ordering.API.Migrations
});
migrationBuilder.CreateTable(
name: "payments",
name: "paymentmethods",
schema: "ordering",
columns: table => new
{
@ -84,16 +84,16 @@ namespace Ordering.API.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_payments", x => x.Id);
table.PrimaryKey("PK_paymentmethods", x => x.Id);
table.ForeignKey(
name: "FK_payments_buyers_BuyerId",
name: "FK_paymentmethods_buyers_BuyerId",
column: x => x.BuyerId,
principalSchema: "ordering",
principalTable: "buyers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_payments_cardtypes_CardTypeId",
name: "FK_paymentmethods_cardtypes_CardTypeId",
column: x => x.CardTypeId,
principalSchema: "ordering",
principalTable: "cardtypes",
@ -109,9 +109,10 @@ namespace Ordering.API.Migrations
Id = table.Column<int>(nullable: false),
BuyerId = table.Column<int>(nullable: false),
City = table.Column<string>(nullable: false),
Country = table.Column<string>(nullable: false),
OrderDate = table.Column<DateTime>(nullable: false),
OrderStatusId = table.Column<int>(nullable: false),
PaymentId = table.Column<int>(nullable: false),
PaymentMethodId = table.Column<int>(nullable: false),
State = table.Column<string>(nullable: false),
Street = table.Column<string>(nullable: false),
ZipCode = table.Column<string>(nullable: false)
@ -134,10 +135,10 @@ namespace Ordering.API.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_orders_payments_PaymentId",
column: x => x.PaymentId,
name: "FK_orders_paymentmethods_PaymentMethodId",
column: x => x.PaymentMethodId,
principalSchema: "ordering",
principalTable: "payments",
principalTable: "paymentmethods",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
@ -150,6 +151,7 @@ namespace Ordering.API.Migrations
Id = table.Column<int>(nullable: false),
Discount = table.Column<decimal>(nullable: false),
OrderId = table.Column<int>(nullable: false),
PictureUrl = table.Column<string>(nullable: true),
ProductId = table.Column<int>(nullable: false),
ProductName = table.Column<string>(nullable: false),
UnitPrice = table.Column<decimal>(nullable: false),
@ -175,15 +177,15 @@ namespace Ordering.API.Migrations
unique: true);
migrationBuilder.CreateIndex(
name: "IX_payments_BuyerId",
name: "IX_paymentmethods_BuyerId",
schema: "ordering",
table: "payments",
table: "paymentmethods",
column: "BuyerId");
migrationBuilder.CreateIndex(
name: "IX_payments_CardTypeId",
name: "IX_paymentmethods_CardTypeId",
schema: "ordering",
table: "payments",
table: "paymentmethods",
column: "CardTypeId");
migrationBuilder.CreateIndex(
@ -199,10 +201,10 @@ namespace Ordering.API.Migrations
column: "OrderStatusId");
migrationBuilder.CreateIndex(
name: "IX_orders_PaymentId",
name: "IX_orders_PaymentMethodId",
schema: "ordering",
table: "orders",
column: "PaymentId");
column: "PaymentMethodId");
migrationBuilder.CreateIndex(
name: "IX_orderItems_OrderId",
@ -226,7 +228,7 @@ namespace Ordering.API.Migrations
schema: "ordering");
migrationBuilder.DropTable(
name: "payments",
name: "paymentmethods",
schema: "ordering");
migrationBuilder.DropTable(

+ 13
- 8
src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs View File

@ -54,7 +54,7 @@ namespace Ordering.API.Migrations
b.ToTable("cardtypes","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -86,7 +86,7 @@ namespace Ordering.API.Migrations
b.HasIndex("CardTypeId");
b.ToTable("payments","ordering");
b.ToTable("paymentmethods","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
@ -102,11 +102,14 @@ namespace Ordering.API.Migrations
b.Property<string>("City")
.IsRequired();
b.Property<string>("Country")
.IsRequired();
b.Property<DateTime>("OrderDate");
b.Property<int>("OrderStatusId");
b.Property<int>("PaymentId");
b.Property<int>("PaymentMethodId");
b.Property<string>("State")
.IsRequired();
@ -123,7 +126,7 @@ namespace Ordering.API.Migrations
b.HasIndex("OrderStatusId");
b.HasIndex("PaymentId");
b.HasIndex("PaymentMethodId");
b.ToTable("orders","ordering");
});
@ -139,6 +142,8 @@ namespace Ordering.API.Migrations
b.Property<int>("OrderId");
b.Property<string>("PictureUrl");
b.Property<int>("ProductId");
b.Property<string>("ProductName")
@ -169,10 +174,10 @@ namespace Ordering.API.Migrations
b.ToTable("orderstatus","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
.WithMany("Payments")
.WithMany("PaymentMethods")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
@ -194,9 +199,9 @@ namespace Ordering.API.Migrations
.HasForeignKey("OrderStatusId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", "PaymentMethod")
.WithMany()
.HasForeignKey("PaymentId");
.HasForeignKey("PaymentMethodId");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>


+ 7
- 7
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs View File

@ -10,9 +10,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
{
public string FullName { get; private set; }
private HashSet<Payment> _payments;
private HashSet<PaymentMethod> _paymentMethods;
public IEnumerable<Payment> Payments => _payments?.ToList().AsEnumerable();
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods?.ToList().AsEnumerable();
protected Buyer() { }
@ -25,12 +25,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
FullName = identity;
_payments = new HashSet<Payment>();
_paymentMethods = new HashSet<PaymentMethod>();
}
public Payment AddPayment(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
public PaymentMethod AddPaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
{
var existingPayment = Payments.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
var existingPayment = _paymentMethods.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
.SingleOrDefault();
if (existingPayment != null)
@ -39,9 +39,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
}
else
{
var payment = new Payment(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
var payment = new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
_payments.Add(payment);
_paymentMethods.Add(payment);
return payment;
}


+ 3
- 3
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Payment.cs View File

@ -3,7 +3,7 @@ using System;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
{
public class Payment
public class PaymentMethod
: Entity
{
private int _buyerId;
@ -17,9 +17,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
public CardType CardType { get; private set; }
protected Payment() { }
protected PaymentMethod() { }
public Payment(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
{
if (String.IsNullOrWhiteSpace(cardNumber))
{


+ 1
- 2
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs View File

@ -1,8 +1,7 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
{
{
//This is just the RepositoryContracts or Interface defined at the Domain Layer
//as requisite for the Order Aggregate
public interface IOrderRepository


+ 4
- 5
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -9,7 +9,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
public class Order
: Entity
{
private string _street;
private string _city;
private string _state;
@ -26,16 +25,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
HashSet<OrderItem> _orderItems;
public IEnumerable<OrderItem> OrderItems => _orderItems.ToList().AsEnumerable();
public Payment Payment { get; private set; }
int _paymentId;
public PaymentMethod PaymentMethod { get; private set; }
int _paymentMethodId;
protected Order() { }
public Order(int buyerId, int paymentId, Address address)
public Order(int buyerId, int paymentMethodId, Address address)
{
_buyerId = buyerId;
_paymentId = paymentId;
_paymentMethodId = paymentMethodId;
_orderStatusId = OrderStatus.InProcess.Id;
_orderDate = DateTime.UtcNow;
_street = address.Street;


+ 14
- 9
src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs View File

@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
public DbSet<OrderItem> OrderItems { get; set; }
public DbSet<Payment> Payments { get; set; }
public DbSet<PaymentMethod> Payments { get; set; }
public DbSet<Buyer> Buyers { get; set; }
@ -31,7 +31,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Buyer>(ConfigureBuyer);
modelBuilder.Entity<Payment>(ConfigurePayment);
modelBuilder.Entity<PaymentMethod>(ConfigurePayment);
modelBuilder.Entity<Order>(ConfigureOrder);
modelBuilder.Entity<OrderItem>(ConfigureOrderItems);
modelBuilder.Entity<CardType>(ConfigureCardTypes);
@ -54,18 +54,19 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
buyerConfiguration.HasIndex("FullName")
.IsUnique(true);
buyerConfiguration.HasMany(b => b.Payments)
buyerConfiguration.HasMany(b => b.PaymentMethods)
.WithOne()
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.Payments));
var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.PaymentMethods));
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
}
void ConfigurePayment(EntityTypeBuilder<Payment> paymentConfiguration)
void ConfigurePayment(EntityTypeBuilder<PaymentMethod> paymentConfiguration)
{
paymentConfiguration.ToTable("payments", DEFAULT_SCHEMA);
paymentConfiguration.ToTable("paymentmethods", DEFAULT_SCHEMA);
paymentConfiguration.HasKey(b => b.Id);
@ -112,17 +113,18 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
orderConfiguration.Property<string>("State").IsRequired();
orderConfiguration.Property<string>("City").IsRequired();
orderConfiguration.Property<string>("ZipCode").IsRequired();
orderConfiguration.Property<string>("Country").IsRequired();
orderConfiguration.Property<int>("BuyerId").IsRequired();
orderConfiguration.Property<int>("OrderStatusId").IsRequired();
orderConfiguration.Property<int>("PaymentId").IsRequired();
orderConfiguration.Property<int>("PaymentMethodId").IsRequired();
var navigation = orderConfiguration.Metadata.FindNavigation(nameof(Order.OrderItems));
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
orderConfiguration.HasOne(o => o.Payment)
orderConfiguration.HasOne(o => o.PaymentMethod)
.WithMany()
.HasForeignKey("PaymentId")
.HasForeignKey("PaymentMethodId")
.OnDelete(DeleteBehavior.Restrict);
orderConfiguration.HasOne(o => o.Buyer)
@ -160,6 +162,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
orderItemConfiguration.Property<int>("Units")
.IsRequired();
orderItemConfiguration.Property<string>("PictureUrl")
.IsRequired(false);
}
void ConfigureOrderStatus(EntityTypeBuilder<OrderStatus> orderStatusConfiguration)


+ 1
- 1
src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs View File

@ -48,7 +48,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
public async Task<Buyer> FindAsync(string identity)
{
var buyer = await _context.Buyers
.Include(b => b.Payments)
.Include(b => b.PaymentMethods)
.Where(b => b.FullName == identity)
.SingleOrDefaultAsync();


Loading…
Cancel
Save