CouponConfiguration.cs 1.4 KB

12345678910111213141516171819202122232425262728293031
  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 CouponConfiguration : IEntityTypeConfiguration<Coupon>
  6. {
  7. public void Configure(EntityTypeBuilder<Coupon> builder)
  8. {
  9. builder.ToTable(nameof(Coupon), t => t.HasComment("쿠폰 메타 (코드 풀의 상위)"));
  10. builder.HasKey(x => x.ID);
  11. builder.HasOne(x => x.Product).WithMany().HasForeignKey(x => x.ProductID).OnDelete(DeleteBehavior.Restrict);
  12. builder.HasOne(x => x.Game).WithMany().HasForeignKey(x => x.GameID).OnDelete(DeleteBehavior.Restrict);
  13. builder.Property(x => x.ProductID).IsRequired();
  14. builder.Property(x => x.GameID).IsRequired().HasComment("게임 ID (필수)");
  15. builder.Property(x => x.Name).HasMaxLength(200).IsRequired();
  16. builder.Property(x => x.ExpiresAt);
  17. builder.Property(x => x.UsagePolicy).HasConversion<int>().IsRequired();
  18. builder.Property(x => x.GeneratedCount).IsRequired();
  19. builder.Property(x => x.UsedCount).IsRequired();
  20. builder.Property(x => x.LowStockThreshold).IsRequired().HasDefaultValue(10);
  21. builder.Property(x => x.CreatedAt).IsRequired();
  22. builder.Property(x => x.UpdatedAt);
  23. builder.HasIndex(x => x.ProductID);
  24. builder.HasIndex(x => x.GameID);
  25. }
  26. }