Skip to content

Commit

Permalink
bool flags instead of enum OperationType in LogDTO (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdenHide authored Dec 30, 2024
1 parent 0e83b6b commit 4b27808
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 19 deletions.
5 changes: 0 additions & 5 deletions src/DispenserProvider.DataBase/DispenserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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 @@ -102,9 +100,6 @@ 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
9 changes: 5 additions & 4 deletions src/DispenserProvider.DataBase/Models/LogDTO.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DispenserProvider.DataBase.Models.Types;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations.Schema;

namespace DispenserProvider.DataBase.Models;

Expand All @@ -11,8 +10,10 @@ public class LogDTO
[Column(TypeName = "datetime2(0)")]
public DateTime CreationTime { get; set; }

[Column(TypeName = "nvarchar(32)")]
public OperationType Operation { get; set; }
public bool IsCreation { get; set; }

[NotMapped]
public bool IsDeletion => !IsCreation;

public virtual List<DispenserDTO> CreationDispensers { get; set; } = [];
public virtual List<DispenserDTO> DeletionDispensers { get; set; } = [];
Expand Down
7 changes: 0 additions & 7 deletions src/DispenserProvider.DataBase/Models/Types/OperationType.cs

This file was deleted.

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,40 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DispenserProvider.DataBase.Migrations
{
/// <inheritdoc />
public partial class UpdateOperationToIsCreationInLogs : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Operation",
table: "Logs");

migrationBuilder.AddColumn<bool>(
name: "IsCreation",
table: "Logs",
type: "bit",
nullable: false,
defaultValue: false);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsCreation",
table: "Logs");

migrationBuilder.AddColumn<string>(
name: "Operation",
table: "Logs",
type: "nvarchar(32)",
nullable: false,
defaultValue: "");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2(0)");

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

b.HasKey("Signature");

Expand Down

0 comments on commit 4b27808

Please sign in to comment.