diff --git a/src/DispenserProvider.DataBase/DispenserContext.cs b/src/DispenserProvider.DataBase/DispenserContext.cs index 36e36e3..f98bc01 100644 --- a/src/DispenserProvider.DataBase/DispenserContext.cs +++ b/src/DispenserProvider.DataBase/DispenserContext.cs @@ -80,6 +80,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.HasKey(e => e.Id); + entity.Property(x => x.ProviderAddress) + .HasConversion( + x => x.ConvertToChecksumAddress(null), + x => new EthereumAddress(x) + ); + entity.HasOne(e => e.TransactionDetail) .WithMany(e => e.Builders) .HasForeignKey(e => e.TransactionDetailId) diff --git a/src/DispenserProvider.DataBase/Models/BuilderDTO.cs b/src/DispenserProvider.DataBase/Models/BuilderDTO.cs index 98aeba1..60bba87 100644 --- a/src/DispenserProvider.DataBase/Models/BuilderDTO.cs +++ b/src/DispenserProvider.DataBase/Models/BuilderDTO.cs @@ -6,6 +6,9 @@ public class BuilderDTO { public long Id { get; set; } + [Column(TypeName = "nvarchar(42)")] + public string ProviderAddress { get; set; } = null!; + [Column(TypeName = "decimal(36,18)")] public decimal Amount { get; set; } diff --git a/src/DispenserProvider.Migrations/Migrations/20241119100723_Add-ProviderAddress-To-BuilderDTO.Designer.cs b/src/DispenserProvider.Migrations/Migrations/20241119100723_Add-ProviderAddress-To-BuilderDTO.Designer.cs new file mode 100644 index 0000000..9e2c115 --- /dev/null +++ b/src/DispenserProvider.Migrations/Migrations/20241119100723_Add-ProviderAddress-To-BuilderDTO.Designer.cs @@ -0,0 +1,221 @@ +// +using System; +using DispenserProvider.DataBase; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DispenserProvider.DataBase.Migrations +{ + [DbContext(typeof(DispenserContext))] + [Migration("20241119100723_Add-ProviderAddress-To-BuilderDTO")] + partial class AddProviderAddressToBuilderDTO + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.BuilderDTO", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("decimal(36,18)"); + + b.Property("FinishTime") + .HasColumnType("datetime2(0)"); + + b.Property("ProviderAddress") + .IsRequired() + .HasColumnType("nvarchar(42)"); + + b.Property("StartTime") + .HasColumnType("datetime2(0)"); + + b.Property("TransactionDetailId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("TransactionDetailId"); + + b.ToTable("Builders"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.DispenserDTO", b => + { + b.Property("Id") + .HasColumnType("nvarchar(64)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LogSignature") + .IsRequired() + .HasColumnType("nvarchar(132)"); + + b.Property("RefundDetailId") + .HasColumnType("bigint"); + + b.Property("RefundFinishTime") + .HasColumnType("datetime2(0)"); + + b.Property("Signature") + .HasColumnType("nvarchar(132)"); + + b.Property("UserAddress") + .IsRequired() + .HasColumnType("nvarchar(42)"); + + b.Property("WithdrawalDetailId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("LogSignature"); + + b.HasIndex("RefundDetailId") + .IsUnique() + .HasFilter("[RefundDetailId] IS NOT NULL"); + + b.HasIndex("Signature") + .IsUnique() + .HasFilter("[Signature] IS NOT NULL"); + + b.HasIndex("WithdrawalDetailId") + .IsUnique(); + + b.ToTable("Dispenser"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.LogDTO", b => + { + b.Property("Signature") + .HasColumnType("nvarchar(132)"); + + b.Property("CreationTime") + .HasColumnType("datetime2(0)"); + + b.HasKey("Signature"); + + b.ToTable("Logs"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.SignatureDTO", b => + { + b.Property("Signature") + .HasColumnType("nvarchar(132)"); + + b.Property("IsRefund") + .HasColumnType("bit"); + + b.Property("ValidFrom") + .HasColumnType("datetime2(0)"); + + b.Property("ValidUntil") + .HasColumnType("datetime2(0)"); + + b.HasKey("Signature"); + + b.ToTable("Signatures"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.TransactionDetailDTO", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ChainId") + .HasColumnType("bigint"); + + b.Property("PoolId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("TransactionDetails"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.BuilderDTO", b => + { + b.HasOne("DispenserProvider.DataBase.Models.TransactionDetailDTO", "TransactionDetail") + .WithMany("Builders") + .HasForeignKey("TransactionDetailId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TransactionDetail"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.DispenserDTO", b => + { + b.HasOne("DispenserProvider.DataBase.Models.LogDTO", "Log") + .WithMany("Dispenser") + .HasForeignKey("LogSignature") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DispenserProvider.DataBase.Models.TransactionDetailDTO", "RefundDetail") + .WithOne() + .HasForeignKey("DispenserProvider.DataBase.Models.DispenserDTO", "RefundDetailId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("DispenserProvider.DataBase.Models.SignatureDTO", "UserSignature") + .WithOne("Dispenser") + .HasForeignKey("DispenserProvider.DataBase.Models.DispenserDTO", "Signature") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("DispenserProvider.DataBase.Models.TransactionDetailDTO", "WithdrawalDetail") + .WithOne("Dispenser") + .HasForeignKey("DispenserProvider.DataBase.Models.DispenserDTO", "WithdrawalDetailId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Log"); + + b.Navigation("RefundDetail"); + + b.Navigation("UserSignature"); + + b.Navigation("WithdrawalDetail"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.LogDTO", b => + { + b.Navigation("Dispenser"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.SignatureDTO", b => + { + b.Navigation("Dispenser") + .IsRequired(); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.TransactionDetailDTO", b => + { + b.Navigation("Builders"); + + b.Navigation("Dispenser") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DispenserProvider.Migrations/Migrations/20241119100723_Add-ProviderAddress-To-BuilderDTO.cs b/src/DispenserProvider.Migrations/Migrations/20241119100723_Add-ProviderAddress-To-BuilderDTO.cs new file mode 100644 index 0000000..8cf82a5 --- /dev/null +++ b/src/DispenserProvider.Migrations/Migrations/20241119100723_Add-ProviderAddress-To-BuilderDTO.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DispenserProvider.DataBase.Migrations +{ + /// + public partial class AddProviderAddressToBuilderDTO : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ProviderAddress", + table: "Builders", + type: "nvarchar(42)", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ProviderAddress", + table: "Builders"); + } + } +} diff --git a/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs b/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs index df6102b..b42172e 100644 --- a/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs +++ b/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs @@ -36,6 +36,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("FinishTime") .HasColumnType("datetime2(0)"); + b.Property("ProviderAddress") + .IsRequired() + .HasColumnType("nvarchar(42)"); + b.Property("StartTime") .HasColumnType("datetime2(0)");