mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Allow adding CustomCategory instances from database
This commit is contained in:
parent
cce7b4d026
commit
9acbd4b4a5
6 changed files with 112 additions and 0 deletions
|
@ -5,6 +5,7 @@ using Kettu;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Categories;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
||||||
|
@ -35,6 +36,7 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
public DbSet<Review> Reviews { get; set; }
|
public DbSet<Review> Reviews { get; set; }
|
||||||
public DbSet<RatedReview> RatedReviews { get; set; }
|
public DbSet<RatedReview> RatedReviews { get; set; }
|
||||||
public DbSet<UserApprovedIpAddress> UserApprovedIpAddresses { get; set; }
|
public DbSet<UserApprovedIpAddress> UserApprovedIpAddresses { get; set; }
|
||||||
|
public DbSet<DatabaseCategory> CustomCategories { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
=> options.UseMySql(ServerSettings.Instance.DbConnectionString, MySqlServerVersion.LatestSupportedServerVersion);
|
=> options.UseMySql(ServerSettings.Instance.DbConnectionString, MySqlServerVersion.LatestSupportedServerVersion);
|
||||||
|
|
|
@ -13,6 +13,9 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
Categories.Add(new NewestLevelsCategory());
|
Categories.Add(new NewestLevelsCategory());
|
||||||
Categories.Add(new QueueCategory());
|
Categories.Add(new QueueCategory());
|
||||||
Categories.Add(new HeartedCategory());
|
Categories.Add(new HeartedCategory());
|
||||||
|
|
||||||
|
using Database database = new();
|
||||||
|
foreach (DatabaseCategory category in database.CustomCategories) Categories.Add(new CustomCategory(category));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
using LBPUnion.ProjectLighthouse;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ProjectLighthouse.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(Database))]
|
||||||
|
[Migration("20220113125615_AddDatabaseCustomCategories")]
|
||||||
|
public partial class AddDatabaseCustomCategories : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CustomCategories",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
CategoryId = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
Name = table.Column<string>(type: "longtext", nullable: true)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
Description = table.Column<string>(type: "longtext", nullable: true)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
IconHash = table.Column<string>(type: "longtext", nullable: true)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
Endpoint = table.Column<string>(type: "longtext", nullable: true)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
SlotIdsCollection = table.Column<string>(type: "longtext", nullable: true)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4")
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CustomCategories", x => x.CategoryId);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CustomCategories");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,6 +43,32 @@ namespace ProjectLighthouse.Migrations
|
||||||
b.ToTable("AuthenticationAttempts");
|
b.ToTable("AuthenticationAttempts");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Categories.DatabaseCategory", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("CategoryId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Endpoint")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("IconHash")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("SlotIdsCollection")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("CategoryId");
|
||||||
|
|
||||||
|
b.ToTable("CustomCategories");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.GameToken", b =>
|
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.GameToken", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("TokenId")
|
b.Property<int>("TokenId")
|
||||||
|
|
|
@ -17,6 +17,16 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
||||||
this.SlotIds = slotIds.ToList();
|
this.SlotIds = slotIds.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CustomCategory(DatabaseCategory category)
|
||||||
|
{
|
||||||
|
this.Name = category.Name;
|
||||||
|
this.Description = category.Description;
|
||||||
|
this.IconHash = category.IconHash;
|
||||||
|
this.Endpoint = category.Endpoint;
|
||||||
|
|
||||||
|
this.SlotIds = category.SlotIds.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public List<int> SlotIds;
|
public List<int> SlotIds;
|
||||||
|
|
||||||
public sealed override string Name { get; set; }
|
public sealed override string Name { get; set; }
|
||||||
|
|
25
ProjectLighthouse/Types/Categories/DatabaseCategory.cs
Normal file
25
ProjectLighthouse/Types/Categories/DatabaseCategory.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Types.Categories
|
||||||
|
{
|
||||||
|
public class DatabaseCategory
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int CategoryId { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public string IconHash { get; set; }
|
||||||
|
public string Endpoint { get; set; }
|
||||||
|
|
||||||
|
public string SlotIdsCollection { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public int[] SlotIds {
|
||||||
|
get => SlotIdsCollection.Split(",").Select(int.Parse).ToArray();
|
||||||
|
set => SlotIdsCollection = string.Join(",", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue