diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs index a8ab002d..8f882808 100644 --- a/ProjectLighthouse/Database.cs +++ b/ProjectLighthouse/Database.cs @@ -5,6 +5,7 @@ using Kettu; using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; +using LBPUnion.ProjectLighthouse.Types.Categories; using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Profiles; using LBPUnion.ProjectLighthouse.Types.Reviews; @@ -35,6 +36,7 @@ namespace LBPUnion.ProjectLighthouse public DbSet Reviews { get; set; } public DbSet RatedReviews { get; set; } public DbSet UserApprovedIpAddresses { get; set; } + public DbSet CustomCategories { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseMySql(ServerSettings.Instance.DbConnectionString, MySqlServerVersion.LatestSupportedServerVersion); diff --git a/ProjectLighthouse/Helpers/CollectionHelper.cs b/ProjectLighthouse/Helpers/CollectionHelper.cs index 08ac6e36..6d950409 100644 --- a/ProjectLighthouse/Helpers/CollectionHelper.cs +++ b/ProjectLighthouse/Helpers/CollectionHelper.cs @@ -13,6 +13,9 @@ namespace LBPUnion.ProjectLighthouse.Helpers Categories.Add(new NewestLevelsCategory()); Categories.Add(new QueueCategory()); Categories.Add(new HeartedCategory()); + + using Database database = new(); + foreach (DatabaseCategory category in database.CustomCategories) Categories.Add(new CustomCategory(category)); } } } \ No newline at end of file diff --git a/ProjectLighthouse/Migrations/20220113125615_AddDatabaseCustomCategories.cs b/ProjectLighthouse/Migrations/20220113125615_AddDatabaseCustomCategories.cs new file mode 100644 index 00000000..b7b06c3e --- /dev/null +++ b/ProjectLighthouse/Migrations/20220113125615_AddDatabaseCustomCategories.cs @@ -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(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Name = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + IconHash = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Endpoint = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + SlotIdsCollection = table.Column(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"); + } + } +} diff --git a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index b29e1cc0..07d95074 100644 --- a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -43,6 +43,32 @@ namespace ProjectLighthouse.Migrations b.ToTable("AuthenticationAttempts"); }); + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Categories.DatabaseCategory", b => + { + b.Property("CategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("Endpoint") + .HasColumnType("longtext"); + + b.Property("IconHash") + .HasColumnType("longtext"); + + b.Property("Name") + .HasColumnType("longtext"); + + b.Property("SlotIdsCollection") + .HasColumnType("longtext"); + + b.HasKey("CategoryId"); + + b.ToTable("CustomCategories"); + }); + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.GameToken", b => { b.Property("TokenId") diff --git a/ProjectLighthouse/Types/Categories/CustomCategory.cs b/ProjectLighthouse/Types/Categories/CustomCategory.cs index 1a2feeae..cd655844 100644 --- a/ProjectLighthouse/Types/Categories/CustomCategory.cs +++ b/ProjectLighthouse/Types/Categories/CustomCategory.cs @@ -17,6 +17,16 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories 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 SlotIds; public sealed override string Name { get; set; } diff --git a/ProjectLighthouse/Types/Categories/DatabaseCategory.cs b/ProjectLighthouse/Types/Categories/DatabaseCategory.cs new file mode 100644 index 00000000..2f728d8f --- /dev/null +++ b/ProjectLighthouse/Types/Categories/DatabaseCategory.cs @@ -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); + } + } +} \ No newline at end of file