Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new TakenTrack table #50

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading