Skip to content

Commit

Permalink
LogDTO: Create column Operation (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdenHide authored Dec 5, 2024
1 parent f9812c0 commit 37c54bd
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/DispenserProvider.DataBase/DispenserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -100,6 +102,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
entity.HasKey(e => e.Signature);

entity.Property(e => e.Operation)
.HasConversion(new EnumToStringConverter<OperationType>());

entity.HasMany(e => e.CreationDispensers)
.WithOne(e => e.CreationLog)
.HasForeignKey(e => e.CreationLogSignature)
Expand Down
6 changes: 5 additions & 1 deletion src/DispenserProvider.DataBase/Models/LogDTO.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using DispenserProvider.DataBase.Models.Types;
using System.ComponentModel.DataAnnotations.Schema;

namespace DispenserProvider.DataBase.Models;

Expand All @@ -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<DispenserDTO> CreationDispensers { get; set; } = [];
public virtual List<DispenserDTO> DeletionDispensers { get; set; } = [];
}
7 changes: 7 additions & 0 deletions src/DispenserProvider.DataBase/Models/Types/OperationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DispenserProvider.DataBase.Models.Types;

public enum OperationType
{
Creation,
Deletion
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DispenserProvider.DataBase.Migrations
{
/// <inheritdoc />
public partial class CreateOperationColumnInLogDTO : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Operation",
table: "Logs",
type: "nvarchar(32)",
nullable: false,
defaultValue: "");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Operation",
table: "Logs");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2(0)");

b.Property<string>("Operation")
.IsRequired()
.HasColumnType("nvarchar(32)");

b.HasKey("Signature");

b.ToTable("Logs");
Expand Down

0 comments on commit 37c54bd

Please sign in to comment.