From f4a508489fce7f410189f6f63bcd9ea82e870103 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Wed, 14 Feb 2024 16:49:19 +0100 Subject: [PATCH] feat: backups --- .../Controllers/WorldsController.cs | 13 ++ Minecraft-Realms-Emulator/Data/DataContext.cs | 1 + Minecraft-Realms-Emulator/Entities/Backup.cs | 14 ++ .../Entities/BackupList.cs | 7 + .../20240214154708_Backups.Designer.cs | 211 ++++++++++++++++++ .../Migrations/20240214154708_Backups.cs | 51 +++++ .../Migrations/DataContextModelSnapshot.cs | 43 ++++ 7 files changed, 340 insertions(+) create mode 100644 Minecraft-Realms-Emulator/Entities/Backup.cs create mode 100644 Minecraft-Realms-Emulator/Entities/BackupList.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.Designer.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.cs diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index 559be38..8b30cdb 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -166,5 +166,18 @@ namespace Minecraft_Realms_Emulator.Controllers Console.WriteLine(o); return true; } + + [HttpGet("{Id}/backups")] + public async Task> GetBackups(int id) + { + var backups = await _context.Backups.Where(b => b.World.Id == id).ToListAsync(); + + BackupList worldBackups = new() + { + Backups = backups + }; + + return Ok(worldBackups); + } } } diff --git a/Minecraft-Realms-Emulator/Data/DataContext.cs b/Minecraft-Realms-Emulator/Data/DataContext.cs index 4f71f2c..417bbf4 100644 --- a/Minecraft-Realms-Emulator/Data/DataContext.cs +++ b/Minecraft-Realms-Emulator/Data/DataContext.cs @@ -8,5 +8,6 @@ namespace Minecraft_Realms_Emulator.Data public DbSet Worlds { get; set; } public DbSet Subscriptions { get; set; } public DbSet Connections { get; set; } + public DbSet Backups { get; set; } } } diff --git a/Minecraft-Realms-Emulator/Entities/Backup.cs b/Minecraft-Realms-Emulator/Entities/Backup.cs new file mode 100644 index 0000000..fc2eb8d --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Backup.cs @@ -0,0 +1,14 @@ +using System.Text.Json; + +namespace Minecraft_Realms_Emulator.Entities +{ + public class Backup + { + public int Id { get; set; } + public World World { get; set; } + public string BackupId { get; set; } + public long LastModifiedDate { get; set; } + public int Size { get; set; } + public JsonDocument Metadata { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/BackupList.cs b/Minecraft-Realms-Emulator/Entities/BackupList.cs new file mode 100644 index 0000000..9ce2935 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/BackupList.cs @@ -0,0 +1,7 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class BackupList + { + public List Backups { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.Designer.cs new file mode 100644 index 0000000..6881576 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.Designer.cs @@ -0,0 +1,211 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240214154708_Backups")] + partial class Backups + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.cs b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.cs new file mode 100644 index 0000000..34e563a --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.cs @@ -0,0 +1,51 @@ +using System.Text.Json; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Backups : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Backups", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + WorldId = table.Column(type: "integer", nullable: false), + BackupId = table.Column(type: "text", nullable: false), + LastModifiedDate = table.Column(type: "bigint", nullable: false), + Size = table.Column(type: "integer", nullable: false), + Metadata = table.Column(type: "jsonb", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Backups", x => x.Id); + table.ForeignKey( + name: "FK_Backups_Worlds_WorldId", + column: x => x.WorldId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Backups_WorldId", + table: "Backups", + column: "WorldId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Backups"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index c4fa217..a55261b 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -23,6 +23,38 @@ namespace Minecraft_Realms_Emulator.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => { b.Property("Address") @@ -138,6 +170,17 @@ namespace Minecraft_Realms_Emulator.Migrations b.ToTable("Worlds"); }); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => { b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")