From 540e43b5f523a6216781bcde26d9199eafaf3c11 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Sun, 17 Mar 2024 16:10:58 +0100 Subject: [PATCH] feat: `subscription` field in worlds table --- .../Controllers/SubscriptionsController.cs | 13 +- .../Controllers/WorldsController.cs | 110 ++++-- .../Entities/ServersArray.cs | 2 +- .../Entities/Subscription.cs | 3 +- Minecraft-Realms-Emulator/Entities/World.cs | 5 +- ...0329_Worlds_Subscription_field.Designer.cs | 313 ++++++++++++++++++ ...0240317120329_Worlds_Subscription_field.cs | 81 +++++ .../Migrations/DataContextModelSnapshot.cs | 36 +- .../Responses/WorldResponse.cs | 10 + 9 files changed, 517 insertions(+), 56 deletions(-) create mode 100644 Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.Designer.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.cs create mode 100644 Minecraft-Realms-Emulator/Responses/WorldResponse.cs diff --git a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs index 384fc34..ec6c542 100644 --- a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs @@ -18,18 +18,15 @@ namespace Minecraft_Realms_Emulator.Controllers [HttpGet("{id}")] public async Task> Get(int id) { - var world = await _context.Worlds.FindAsync(id); - var subscriptions = await _context.Subscriptions.ToListAsync(); + var world = await _context.Worlds.Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == id); - if (world == null) return NotFound("Subscription not found"); - - var subscription = subscriptions.Find(s => s.World.RemoteSubscriptionId == world.RemoteSubscriptionId); + if (world?.Subscription == null) return NotFound("Subscription not found"); var sub = new Subscription { - StartDate = ((DateTimeOffset) subscription.StartDate).ToUnixTimeMilliseconds(), - DaysLeft = ((DateTimeOffset) subscription.StartDate.AddDays(30) - DateTime.Today).Days, - SubscriptionType = subscription.SubscriptionType + StartDate = ((DateTimeOffset)world.Subscription.StartDate).ToUnixTimeMilliseconds(), + DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days, + SubscriptionType = world.Subscription.SubscriptionType }; return Ok(sub); diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index d2cd56b..f1cbe94 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -2,6 +2,8 @@ using Microsoft.EntityFrameworkCore; using Minecraft_Realms_Emulator.Data; using Minecraft_Realms_Emulator.Entities; +using System.Collections.Generic; +using System.Diagnostics.Eventing.Reader; namespace Minecraft_Realms_Emulator.Controllers { @@ -24,22 +26,20 @@ namespace Minecraft_Realms_Emulator.Controllers string playerUUID = cookie.Split(";")[0].Split(":")[2]; string playerName = cookie.Split(";")[1].Split("=")[1]; - var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).ToListAsync(); - var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Select(p => p.World).ToListAsync(); + var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).Include(w => w.Subscription).ToListAsync(); + var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Select(p => p.World).ToListAsync(); + + List allWorlds = []; if (ownedWorlds.ToArray().Length == 0) { var world = new World { - RemoteSubscriptionId = Guid.NewGuid().ToString(), Owner = playerName, OwnerUUID = playerUUID, Name = null, Motd = null, State = State.UNINITIALIZED.ToString(), - DaysLeft = 30, - Expired = false, - ExpiredTrial = false, WorldType = WorldType.NORMAL.ToString(), MaxPlayers = 10, MinigameId = null, @@ -55,10 +55,61 @@ namespace Minecraft_Realms_Emulator.Controllers _context.SaveChanges(); } - List allWorlds = []; + foreach (var world in ownedWorlds) + { + WorldResponse response = new() + { + Id = world.Id, + Owner = world.Owner, + OwnerUUID = world.OwnerUUID, + Name = world.Name, + Motd = world.Motd, + State = world.State, + WorldType = world.WorldType, + MaxPlayers = world.MaxPlayers, + MinigameId = world.MinigameId, + MinigameName = world.MinigameName, + MinigameImage = world.MinigameImage, + ActiveSlot = world.ActiveSlot, + Member = world.Member, + Players = world.Players + }; - allWorlds.AddRange(ownedWorlds); - allWorlds.AddRange(memberWorlds); + if (world.Subscription != null) + { + response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; + response.Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0; + response.ExpiredTrial = false; + } + + allWorlds.Add(response); + } + + foreach (var world in memberWorlds) + { + WorldResponse response = new() + { + Id = world.Id, + Owner = world.Owner, + OwnerUUID = world.OwnerUUID, + Name = world.Name, + Motd = world.Motd, + State = world.State, + WorldType = world.WorldType, + MaxPlayers = world.MaxPlayers, + MinigameId = world.MinigameId, + MinigameName = world.MinigameName, + MinigameImage = world.MinigameImage, + ActiveSlot = world.ActiveSlot, + Member = world.Member, + Players = world.Players, + DaysLeft = 0, + Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0, + ExpiredTrial = false + }; + + allWorlds.Add(response); + } ServersArray servers = new() { @@ -69,13 +120,34 @@ namespace Minecraft_Realms_Emulator.Controllers } [HttpGet("{id}")] - public async Task> GetWorldById(int id) + public async Task> GetWorldById(int id) { - var world = await _context.Worlds.Include(w => w.Players).FirstOrDefaultAsync(w => w.Id == id); + var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == id); - if (world == null) return NotFound("World not found"); + if (world?.Subscription == null) return NotFound("World not found"); - return world; + WorldResponse response = new() + { + Id = world.Id, + Owner = world.Owner, + OwnerUUID = world.OwnerUUID, + Name = world.Name, + Motd = world.Motd, + State = world.State, + WorldType = world.WorldType, + MaxPlayers = world.MaxPlayers, + MinigameId = world.MinigameId, + MinigameName = world.MinigameName, + MinigameImage = world.MinigameImage, + ActiveSlot = world.ActiveSlot, + Member = world.Member, + Players = world.Players, + DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days, + Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0, + ExpiredTrial = false + }; + + return response; } [HttpPost("{id}/initialize")] @@ -88,17 +160,17 @@ namespace Minecraft_Realms_Emulator.Controllers if (world == null) return NotFound("World not found"); if (world.State != State.UNINITIALIZED.ToString()) return NotFound("World already initialized"); - world.Name = body.Name; - world.Motd = body.Description; - world.State = State.OPEN.ToString(); - var subscription = new Subscription { - World = world, StartDate = DateTime.UtcNow, SubscriptionType = SubscriptionType.NORMAL.ToString() }; + world.Name = body.Name; + world.Motd = body.Description; + world.State = State.OPEN.ToString(); + world.Subscription = subscription; + var connection = new Connection { World = world, @@ -143,7 +215,7 @@ namespace Minecraft_Realms_Emulator.Controllers { var worlds = await _context.Worlds.ToListAsync(); - var world = worlds.Find(w => w.Id == id); + var world = worlds.FirstOrDefault(w => w.Id == id); if (world == null) return NotFound("World not found"); diff --git a/Minecraft-Realms-Emulator/Entities/ServersArray.cs b/Minecraft-Realms-Emulator/Entities/ServersArray.cs index 471e056..acbf11b 100644 --- a/Minecraft-Realms-Emulator/Entities/ServersArray.cs +++ b/Minecraft-Realms-Emulator/Entities/ServersArray.cs @@ -2,6 +2,6 @@ { public class ServersArray { - public List? Servers { get; set; } + public List? Servers { get; set; } } } diff --git a/Minecraft-Realms-Emulator/Entities/Subscription.cs b/Minecraft-Realms-Emulator/Entities/Subscription.cs index fdd1c0b..dfdc03f 100644 --- a/Minecraft-Realms-Emulator/Entities/Subscription.cs +++ b/Minecraft-Realms-Emulator/Entities/Subscription.cs @@ -3,7 +3,8 @@ public class Subscription { public int Id { get; set; } - public World World { get; set; } + public int WorldId { get; set; } + public World World { get; set; } = null!; public DateTime StartDate { get; set; } = DateTime.Now; public string SubscriptionType { get; set; } = "NORMAL"; } diff --git a/Minecraft-Realms-Emulator/Entities/World.cs b/Minecraft-Realms-Emulator/Entities/World.cs index 6290f6b..cbee5ca 100644 --- a/Minecraft-Realms-Emulator/Entities/World.cs +++ b/Minecraft-Realms-Emulator/Entities/World.cs @@ -5,15 +5,12 @@ namespace Minecraft_Realms_Emulator.Entities public class World { public int Id { get; set; } - public string RemoteSubscriptionId { get; set; } = Guid.NewGuid().ToString(); + public Subscription? Subscription { get; set; } public string? Owner { get; set; } public string? OwnerUUID { get; set; } public string? Name { get; set; } public string? Motd { get; set; } public string State { get; set; } = "OPEN"; - public int DaysLeft { get; set; } = 30; - public bool Expired { get; set; } = false; - public bool ExpiredTrial { get; set; } = false; public string WorldType { get; set; } = "NORMAL"; public List Players { get; set; } = []; public int MaxPlayers { get; set; } = 10; diff --git a/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.Designer.cs new file mode 100644 index 0000000..1ec7ffa --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.Designer.cs @@ -0,0 +1,313 @@ +// +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("20240317120329_Worlds_Subscription_field")] + partial class Worlds_Subscription_field + { + /// + 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.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId") + .IsUnique(); + + 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("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("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.Invite", 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.Player", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Players") + .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") + .WithOne("Subscription") + .HasForeignKey("Minecraft_Realms_Emulator.Entities.Subscription", "WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + + b.Navigation("Subscription"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.cs b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.cs new file mode 100644 index 0000000..6813e98 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.cs @@ -0,0 +1,81 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Worlds_Subscription_field : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions"); + + migrationBuilder.DropColumn( + name: "DaysLeft", + table: "Worlds"); + + migrationBuilder.DropColumn( + name: "Expired", + table: "Worlds"); + + migrationBuilder.DropColumn( + name: "ExpiredTrial", + table: "Worlds"); + + migrationBuilder.DropColumn( + name: "RemoteSubscriptionId", + table: "Worlds"); + + migrationBuilder.CreateIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions", + column: "WorldId", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions"); + + migrationBuilder.AddColumn( + name: "DaysLeft", + table: "Worlds", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Expired", + table: "Worlds", + type: "boolean", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "ExpiredTrial", + table: "Worlds", + type: "boolean", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "RemoteSubscriptionId", + table: "Worlds", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.CreateIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions", + column: "WorldId"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index 1620085..ec88393 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -52,7 +52,7 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasIndex("WorldId"); - b.ToTable("Backups"); + b.ToTable("Backups", (string)null); }); modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b => @@ -66,7 +66,7 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasKey("Key"); - b.ToTable("Configuration"); + b.ToTable("Configuration", (string)null); }); modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => @@ -91,7 +91,7 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasIndex("WorldId"); - b.ToTable("Connections"); + b.ToTable("Connections", (string)null); }); modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => @@ -120,7 +120,7 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasIndex("WorldId"); - b.ToTable("Invites"); + b.ToTable("Invites", (string)null); }); modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => @@ -159,7 +159,7 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasIndex("WorldId"); - b.ToTable("Players"); + b.ToTable("Players", (string)null); }); modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => @@ -182,9 +182,10 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasKey("Id"); - b.HasIndex("WorldId"); + b.HasIndex("WorldId") + .IsUnique(); - b.ToTable("Subscriptions"); + b.ToTable("Subscriptions", (string)null); }); modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => @@ -198,15 +199,6 @@ namespace Minecraft_Realms_Emulator.Migrations 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"); @@ -234,10 +226,6 @@ namespace Minecraft_Realms_Emulator.Migrations b.Property("OwnerUUID") .HasColumnType("text"); - b.Property("RemoteSubscriptionId") - .IsRequired() - .HasColumnType("text"); - b.Property("Slots") .IsRequired() .HasColumnType("jsonb[]"); @@ -252,7 +240,7 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasKey("Id"); - b.ToTable("Worlds"); + b.ToTable("Worlds", (string)null); }); modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => @@ -302,8 +290,8 @@ namespace Minecraft_Realms_Emulator.Migrations modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => { b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") - .WithMany() - .HasForeignKey("WorldId") + .WithOne("Subscription") + .HasForeignKey("Minecraft_Realms_Emulator.Entities.Subscription", "WorldId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -313,6 +301,8 @@ namespace Minecraft_Realms_Emulator.Migrations modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => { b.Navigation("Players"); + + b.Navigation("Subscription"); }); #pragma warning restore 612, 618 } diff --git a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs new file mode 100644 index 0000000..233f340 --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs @@ -0,0 +1,10 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class WorldResponse : World + { + public string RemoteSubscriptionId { get; set; } = Guid.NewGuid().ToString(); + public int DaysLeft { get; set; } = 30; + public bool Expired { get; set; } = false; + public bool ExpiredTrial { get; set; } = false; + } +} \ No newline at end of file