ShipmentConfiguration.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Domain.Entities.Store;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Store;
  5. public sealed class ShipmentConfiguration : IEntityTypeConfiguration<Shipment>
  6. {
  7. public void Configure(EntityTypeBuilder<Shipment> builder)
  8. {
  9. builder.ToTable(nameof(Shipment), t => t.HasComment("배송 (주문 시점 주소 스냅샷, 암호화)"));
  10. builder.HasKey(x => x.ID);
  11. builder.HasOne(x => x.Order).WithOne().HasForeignKey<Shipment>(x => x.OrderID).OnDelete(DeleteBehavior.Cascade);
  12. builder.Property(x => x.OrderID).IsRequired();
  13. builder.Property(x => x.RecipientName_Encrypted).IsRequired();
  14. builder.Property(x => x.Phone_Encrypted).IsRequired();
  15. builder.Property(x => x.ZipCode).HasMaxLength(10).IsRequired();
  16. builder.Property(x => x.Address1_Encrypted).IsRequired();
  17. builder.Property(x => x.Address2_Encrypted).IsRequired();
  18. builder.Property(x => x.KeyVersion).IsRequired();
  19. builder.Property(x => x.Status).HasConversion<int>().IsRequired();
  20. builder.Property(x => x.Carrier).HasMaxLength(50);
  21. builder.Property(x => x.TrackingNumber).HasMaxLength(50);
  22. builder.Property(x => x.ShippingFee).HasDefaultValue(0).IsRequired();
  23. builder.Property(x => x.AdminMemo).HasMaxLength(500);
  24. builder.Property(x => x.CreatedAt).IsRequired();
  25. builder.Property(x => x.ShippedAt);
  26. builder.Property(x => x.DeliveredAt);
  27. builder.HasIndex(x => x.OrderID).IsUnique();
  28. builder.HasIndex(x => x.Status);
  29. builder.HasIndex(x => x.TrackingNumber);
  30. }
  31. }