WalletTransactionConfiguration.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Domain.Entities.Wallets;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Wallets;
  5. public sealed class WalletTransactionConfiguration : IEntityTypeConfiguration<WalletTransaction>
  6. {
  7. public void Configure(EntityTypeBuilder<WalletTransaction> builder)
  8. {
  9. builder.HasIndex(x => x.WalletKey);
  10. builder.HasIndex(x => x.CreatedAt);
  11. builder.HasIndex(x => new { x.WalletKey, x.CreatedAt });
  12. builder.ToTable(nameof(WalletTransaction), t => t.HasComment("회원 거래 장부"));
  13. builder.HasKey(x => x.ID);
  14. builder.Property(x => x.WalletKey).IsRequired();
  15. builder.Property(x => x.BalanceType).HasConversion<int>().IsRequired();
  16. builder.Property(x => x.TxType).HasConversion<int>().IsRequired();
  17. builder.Property(x => x.Reason).HasMaxLength(1000).IsRequired();
  18. builder.Property(x => x.RefID).HasMaxLength(100);
  19. builder.Property(x => x.UserID).HasMaxLength(100);
  20. builder.Property(x => x.Memo).HasMaxLength(500);
  21. builder.Property(x => x.CreatedAt).IsRequired();
  22. builder.OwnsOne(x => x.Amount, money =>
  23. {
  24. money.Property(p => p.Value).HasPrecision(18, 0).HasColumnName("Amount").IsRequired();
  25. money.Property(p => p.Currency).HasColumnName("Currency").HasMaxLength(10).IsRequired();
  26. });
  27. builder.OwnsOne(x => x.BalanceAfter, money =>
  28. {
  29. money.Property(p => p.Value).HasPrecision(18, 0).HasColumnName("BalanceAfter").IsRequired();
  30. money.Property(p => p.Currency).HasColumnName("BalanceAfterCurrency").HasMaxLength(10).IsRequired();
  31. });
  32. }
  33. }