diff --git a/src/DispenserProvider.DataBase/DispenserContext.cs b/src/DispenserProvider.DataBase/DispenserContext.cs index 51f29fe..0878890 100644 --- a/src/DispenserProvider.DataBase/DispenserContext.cs +++ b/src/DispenserProvider.DataBase/DispenserContext.cs @@ -3,6 +3,8 @@ using DispenserProvider.DataBase.Models; using ConfiguredSqlConnection.Extensions; using Net.Web3.EthereumWallet.Extensions; +using DispenserProvider.DataBase.Models.Types; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace DispenserProvider.DataBase; @@ -100,6 +102,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.HasKey(e => e.Signature); + entity.Property(e => e.Operation) + .HasConversion(new EnumToStringConverter()); + entity.HasMany(e => e.CreationDispensers) .WithOne(e => e.CreationLog) .HasForeignKey(e => e.CreationLogSignature) diff --git a/src/DispenserProvider.DataBase/Models/LogDTO.cs b/src/DispenserProvider.DataBase/Models/LogDTO.cs index b4d018c..c41c463 100644 --- a/src/DispenserProvider.DataBase/Models/LogDTO.cs +++ b/src/DispenserProvider.DataBase/Models/LogDTO.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations.Schema; +using DispenserProvider.DataBase.Models.Types; +using System.ComponentModel.DataAnnotations.Schema; namespace DispenserProvider.DataBase.Models; @@ -10,6 +11,9 @@ public class LogDTO [Column(TypeName = "datetime2(0)")] public DateTime CreationTime { get; set; } + [Column(TypeName = "nvarchar(32)")] + public OperationType Operation { get; set; } + public virtual List CreationDispensers { get; set; } = []; public virtual List DeletionDispensers { get; set; } = []; } \ No newline at end of file diff --git a/src/DispenserProvider.DataBase/Models/Types/OperationType.cs b/src/DispenserProvider.DataBase/Models/Types/OperationType.cs new file mode 100644 index 0000000..2078c98 --- /dev/null +++ b/src/DispenserProvider.DataBase/Models/Types/OperationType.cs @@ -0,0 +1,7 @@ +namespace DispenserProvider.DataBase.Models.Types; + +public enum OperationType +{ + Creation, + Deletion +} \ No newline at end of file diff --git a/src/DispenserProvider.Migrations/Migrations/20241205141433_Create-Operation-Column-In-LogDTO.Designer.cs b/src/DispenserProvider.Migrations/Migrations/20241205141433_Create-Operation-Column-In-LogDTO.Designer.cs new file mode 100644 index 0000000..0dff5a1 --- /dev/null +++ b/src/DispenserProvider.Migrations/Migrations/20241205141433_Create-Operation-Column-In-LogDTO.Designer.cs @@ -0,0 +1,236 @@ +// +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("20241205141433_Create-Operation-Column-In-LogDTO")] + partial class CreateOperationColumnInLogDTO + { + /// + 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("CreationLogSignature") + .IsRequired() + .HasColumnType("nvarchar(132)"); + + b.Property("DeletionLogSignature") + .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("CreationLogSignature"); + + b.HasIndex("DeletionLogSignature"); + + 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.Property("Operation") + .IsRequired() + .HasColumnType("nvarchar(32)"); + + 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", "CreationLog") + .WithMany("CreationDispensers") + .HasForeignKey("CreationLogSignature") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DispenserProvider.DataBase.Models.LogDTO", "DeletionLog") + .WithMany("DeletionDispensers") + .HasForeignKey("DeletionLogSignature") + .OnDelete(DeleteBehavior.Restrict); + + 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("CreationLog"); + + b.Navigation("DeletionLog"); + + b.Navigation("RefundDetail"); + + b.Navigation("UserSignature"); + + b.Navigation("WithdrawalDetail"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.LogDTO", b => + { + b.Navigation("CreationDispensers"); + + b.Navigation("DeletionDispensers"); + }); + + 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/20241205141433_Create-Operation-Column-In-LogDTO.cs b/src/DispenserProvider.Migrations/Migrations/20241205141433_Create-Operation-Column-In-LogDTO.cs new file mode 100644 index 0000000..20777b3 --- /dev/null +++ b/src/DispenserProvider.Migrations/Migrations/20241205141433_Create-Operation-Column-In-LogDTO.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DispenserProvider.DataBase.Migrations +{ + /// + public partial class CreateOperationColumnInLogDTO : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Operation", + table: "Logs", + type: "nvarchar(32)", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Operation", + table: "Logs"); + } + } +} diff --git a/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs b/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs index c96d48c..cc3fbe1 100644 --- a/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs +++ b/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs @@ -109,6 +109,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("CreationTime") .HasColumnType("datetime2(0)"); + b.Property("Operation") + .IsRequired() + .HasColumnType("nvarchar(32)"); + b.HasKey("Signature"); b.ToTable("Logs");