Skip to content

Commit

Permalink
Create new TakenTrack table (#50)
Browse files Browse the repository at this point in the history
* Create new `TakenTrack` table

* - update model
- create migration

* - remove `TakenTrackId`
- update migration

* - use `bool IsRefunded` instead of `enum TakenType`
- update migration
  • Loading branch information
ArdenHide authored Dec 30, 2024
1 parent b98f831 commit 0e83b6b
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/DispenserProvider.DataBase/DispenserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public DispenserContext(DbContextOptions<DispenserContext> options) : base(optio
public virtual DbSet<SignatureDTO> Signatures { get; set; } = null!;
public virtual DbSet<BuilderDTO> Builders { get; set; } = null!;
public virtual DbSet<LogDTO> Logs { get; set; } = null!;
public virtual DbSet<TakenTrackDTO> TakenTrack { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
Expand Down Expand Up @@ -114,5 +115,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasForeignKey(e => e.DeletionLogSignature)
.OnDelete(DeleteBehavior.Restrict);
});

modelBuilder.Entity<TakenTrackDTO>(entity =>
{
entity.HasKey(e => e.Id);

entity.HasOne(e => e.Dispenser)
.WithOne(e => e.TakenTrack)
.HasForeignKey<TakenTrackDTO>(e => e.DispenserId)
.OnDelete(DeleteBehavior.Restrict);
});
}
}
2 changes: 2 additions & 0 deletions src/DispenserProvider.DataBase/Models/DispenserDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class DispenserDTO

public virtual List<SignatureDTO> UserSignatures { get; set; } = [];

public virtual TakenTrackDTO? TakenTrack { get; set; }

public long WithdrawalDetailId { get; set; }
public virtual TransactionDetailDTO WithdrawalDetail { get; set; } = null!;

Expand Down
18 changes: 18 additions & 0 deletions src/DispenserProvider.DataBase/Models/TakenTrackDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace DispenserProvider.DataBase.Models;

public class TakenTrackDTO
{
public long Id { get; set; }

public bool IsRefunded { get; set; }

[NotMapped]
public bool IsWithdrawn => !IsRefunded;

[Column(TypeName = "nvarchar(64)")]
public string DispenserId { get; set; } = null!;

public virtual DispenserDTO Dispenser { get; set; } = null!;
}

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

#nullable disable

namespace DispenserProvider.DataBase.Migrations
{
/// <inheritdoc />
public partial class CreateTakenTrackTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TakenTrack",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
IsRefunded = table.Column<bool>(type: "bit", nullable: false),
DispenserId = table.Column<string>(type: "nvarchar(64)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TakenTrack", x => x.Id);
table.ForeignKey(
name: "FK_TakenTrack_Dispenser_DispenserId",
column: x => x.DispenserId,
principalTable: "Dispenser",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});

migrationBuilder.CreateIndex(
name: "IX_TakenTrack_DispenserId",
table: "TakenTrack",
column: "DispenserId",
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TakenTrack");
}
}
}
Loading

0 comments on commit 0e83b6b

Please sign in to comment.