Add project files.
This commit is contained in:
18
Database/ConnectionsContext.cs
Normal file
18
Database/ConnectionsContext.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using ConnectionsAPI.Database.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ConnectionsAPI.Database
|
||||
{
|
||||
public class ConnectionsContext(DbContextOptions<ConnectionsContext> dbContextOptions) : DbContext(dbContextOptions)
|
||||
{
|
||||
public DbSet<Puzzle> Puzzles { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Puzzle>()
|
||||
.HasIndex(x => x.PrintDate).IsUnique();
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Database/Entities/Puzzle.cs
Normal file
40
Database/Entities/Puzzle.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
namespace ConnectionsAPI.Database.Entities
|
||||
{
|
||||
public class Puzzle
|
||||
{
|
||||
/// <summary>
|
||||
/// Primary key of the entity
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the entity was created (is the sync date)
|
||||
/// </summary>
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the puzzle was "printed" online
|
||||
/// </summary>
|
||||
public string PrintDate { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the editor for the puzzle
|
||||
/// </summary>
|
||||
public string EditorName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The actual count of the puzzle
|
||||
/// </summary>
|
||||
public int Index { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The MD5 hash for the source content used to sync this puzzle
|
||||
/// </summary>
|
||||
public string ContentMD5 { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The categories associated with this puzzle
|
||||
/// </summary>
|
||||
public virtual ICollection<PuzzleCategory> Categories { get; set; } = [];
|
||||
}
|
||||
}
|
||||
30
Database/Entities/PuzzleCard.cs
Normal file
30
Database/Entities/PuzzleCard.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace ConnectionsAPI.Database.Entities
|
||||
{
|
||||
public class PuzzleCard
|
||||
{
|
||||
/// <summary>
|
||||
/// Primary key of the entity
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The contents of this card (the word)
|
||||
/// </summary>
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The initial position of this card on the grid
|
||||
/// </summary>
|
||||
public int Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the associated Connections category
|
||||
/// </summary>
|
||||
public int PuzzleCategoryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The associated category instance
|
||||
/// </summary>
|
||||
public virtual PuzzleCategory? PuzzleCategory { get; set; }
|
||||
}
|
||||
}
|
||||
35
Database/Entities/PuzzleCategory.cs
Normal file
35
Database/Entities/PuzzleCategory.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace ConnectionsAPI.Database.Entities
|
||||
{
|
||||
public class PuzzleCategory
|
||||
{
|
||||
/// <summary>
|
||||
/// Primary key of the entity
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the category in this Connections puzzle
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The color of the category in this Connections puzzle; Also used for sorting
|
||||
/// </summary>
|
||||
public PuzzleCategoryColor Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the associated Connections puzzle
|
||||
/// </summary>
|
||||
public int PuzzleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The associated puzzle instance
|
||||
/// </summary>
|
||||
public virtual Puzzle? Puzzle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The cards associated with this category
|
||||
/// </summary>
|
||||
public ICollection<PuzzleCard> PuzzleCards { get; set; } = [];
|
||||
}
|
||||
}
|
||||
10
Database/Entities/PuzzleCategoryColor.cs
Normal file
10
Database/Entities/PuzzleCategoryColor.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ConnectionsAPI.Database.Entities
|
||||
{
|
||||
public enum PuzzleCategoryColor
|
||||
{
|
||||
Yellow = 1,
|
||||
Green = 2,
|
||||
Blue = 3,
|
||||
Purple = 4,
|
||||
}
|
||||
}
|
||||
135
Database/Migrations/20240416121538_Initial.Designer.cs
generated
Normal file
135
Database/Migrations/20240416121538_Initial.Designer.cs
generated
Normal file
@@ -0,0 +1,135 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ConnectionsAPI.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ConnectionsAPI.Database.Migrations
|
||||
{
|
||||
[DbContext(typeof(ConnectionsContext))]
|
||||
[Migration("20240416121538_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.Puzzle", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContentMD5")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("EditorName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Index")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PrintDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PrintDate")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Puzzles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCard", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Position")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PuzzleCategoryId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PuzzleCategoryId");
|
||||
|
||||
b.ToTable("PuzzleCard");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCategory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Color")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("PuzzleId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PuzzleId");
|
||||
|
||||
b.ToTable("PuzzleCategory");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCard", b =>
|
||||
{
|
||||
b.HasOne("ConnectionsAPI.Database.Entities.PuzzleCategory", "PuzzleCategory")
|
||||
.WithMany("PuzzleCards")
|
||||
.HasForeignKey("PuzzleCategoryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PuzzleCategory");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCategory", b =>
|
||||
{
|
||||
b.HasOne("ConnectionsAPI.Database.Entities.Puzzle", "Puzzle")
|
||||
.WithMany("Categories")
|
||||
.HasForeignKey("PuzzleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Puzzle");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.Puzzle", b =>
|
||||
{
|
||||
b.Navigation("Categories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCategory", b =>
|
||||
{
|
||||
b.Navigation("PuzzleCards");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
103
Database/Migrations/20240416121538_Initial.cs
Normal file
103
Database/Migrations/20240416121538_Initial.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ConnectionsAPI.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Puzzles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
CreatedDate = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
PrintDate = table.Column<string>(type: "TEXT", nullable: false),
|
||||
EditorName = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Index = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ContentMD5 = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Puzzles", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PuzzleCategory",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Color = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PuzzleId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PuzzleCategory", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PuzzleCategory_Puzzles_PuzzleId",
|
||||
column: x => x.PuzzleId,
|
||||
principalTable: "Puzzles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PuzzleCard",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Content = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Position = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PuzzleCategoryId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PuzzleCard", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PuzzleCard_PuzzleCategory_PuzzleCategoryId",
|
||||
column: x => x.PuzzleCategoryId,
|
||||
principalTable: "PuzzleCategory",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PuzzleCard_PuzzleCategoryId",
|
||||
table: "PuzzleCard",
|
||||
column: "PuzzleCategoryId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PuzzleCategory_PuzzleId",
|
||||
table: "PuzzleCategory",
|
||||
column: "PuzzleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Puzzles_PrintDate",
|
||||
table: "Puzzles",
|
||||
column: "PrintDate",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PuzzleCard");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PuzzleCategory");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Puzzles");
|
||||
}
|
||||
}
|
||||
}
|
||||
132
Database/Migrations/ConnectionsContextModelSnapshot.cs
Normal file
132
Database/Migrations/ConnectionsContextModelSnapshot.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ConnectionsAPI.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ConnectionsAPI.Database.Migrations
|
||||
{
|
||||
[DbContext(typeof(ConnectionsContext))]
|
||||
partial class ConnectionsContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.Puzzle", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContentMD5")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("EditorName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Index")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PrintDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PrintDate")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Puzzles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCard", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Position")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PuzzleCategoryId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PuzzleCategoryId");
|
||||
|
||||
b.ToTable("PuzzleCard");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCategory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Color")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("PuzzleId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PuzzleId");
|
||||
|
||||
b.ToTable("PuzzleCategory");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCard", b =>
|
||||
{
|
||||
b.HasOne("ConnectionsAPI.Database.Entities.PuzzleCategory", "PuzzleCategory")
|
||||
.WithMany("PuzzleCards")
|
||||
.HasForeignKey("PuzzleCategoryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PuzzleCategory");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCategory", b =>
|
||||
{
|
||||
b.HasOne("ConnectionsAPI.Database.Entities.Puzzle", "Puzzle")
|
||||
.WithMany("Categories")
|
||||
.HasForeignKey("PuzzleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Puzzle");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.Puzzle", b =>
|
||||
{
|
||||
b.Navigation("Categories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ConnectionsAPI.Database.Entities.PuzzleCategory", b =>
|
||||
{
|
||||
b.Navigation("PuzzleCards");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user