From af348b885a03ac22cad639afb5ca9856c3e1337a Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Fri, 15 Mar 2024 23:52:10 +0100 Subject: [PATCH] Revert "feat: daysLeft calculation" This reverts commit deabd84257b3b3458920577d9c7dea67fc418288. --- .../Controllers/SubscriptionsController.cs | 8 +- .../Controllers/WorldsController.cs | 8 +- .../Entities/ServersArray.cs | 7 + .../Entities/Subscription.cs | 2 +- Minecraft-Realms-Emulator/Entities/World.cs | 1 + ...40315212618_Calculate_daysLeft.Designer.cs | 320 ------------------ .../20240315212618_Calculate_daysLeft.cs | 34 -- .../Migrations/DataContextModelSnapshot.cs | 8 +- .../Responses/ServersResponse.cs | 9 - ...ubscriptionResponse.cs => Subscription.cs} | 4 +- .../Responses/WorldResponse.cs | 27 -- 11 files changed, 25 insertions(+), 403 deletions(-) create mode 100644 Minecraft-Realms-Emulator/Entities/ServersArray.cs delete mode 100644 Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs delete mode 100644 Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.cs delete mode 100644 Minecraft-Realms-Emulator/Responses/ServersResponse.cs rename Minecraft-Realms-Emulator/Responses/{SubscriptionResponse.cs => Subscription.cs} (66%) delete 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 a818832..184a432 100644 --- a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs @@ -16,7 +16,7 @@ namespace Minecraft_Realms_Emulator.Controllers _context = context; } [HttpGet("{id}")] - public async Task> Get(int id) + public async Task> Get(int id) { var world = await _context.Worlds.FindAsync(id); var subscriptions = await _context.Subscriptions.ToListAsync(); @@ -25,10 +25,10 @@ namespace Minecraft_Realms_Emulator.Controllers var subscription = subscriptions.Find(s => s.World.RemoteSubscriptionId == world.RemoteSubscriptionId); - var sub = new SubscriptionResponse + var sub = new Subscription { - StartDate = ((DateTimeOffset) subscription.StartDate).ToUnixTimeMilliseconds(), - DaysLeft = (subscription.StartDate.AddDays(30) - DateTime.UtcNow).Days, + StartDate = subscription.StartDate, + DaysLeft = subscription.World.DaysLeft, SubscriptionType = subscription.SubscriptionType }; diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index 35d6634..0e9302a 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -2,7 +2,6 @@ using Microsoft.EntityFrameworkCore; using Minecraft_Realms_Emulator.Data; using Minecraft_Realms_Emulator.Entities; -using Minecraft_Realms_Emulator.Responses; namespace Minecraft_Realms_Emulator.Controllers { @@ -18,7 +17,7 @@ namespace Minecraft_Realms_Emulator.Controllers } [HttpGet] - public async Task> GetWorlds() + public async Task> GetWorlds() { string cookie = Request.Headers.Cookie; @@ -38,6 +37,7 @@ namespace Minecraft_Realms_Emulator.Controllers Name = null, Motd = null, State = State.UNINITIALIZED.ToString(), + DaysLeft = 30, Expired = false, ExpiredTrial = false, WorldType = WorldType.NORMAL.ToString(), @@ -60,7 +60,7 @@ namespace Minecraft_Realms_Emulator.Controllers allWorlds.AddRange(ownedWorlds); allWorlds.AddRange(memberWorlds); - ServersResponse servers = new() + ServersArray servers = new() { Servers = allWorlds }; @@ -95,7 +95,7 @@ namespace Minecraft_Realms_Emulator.Controllers var subscription = new Subscription { World = world, - StartDate = DateTime.UtcNow, + StartDate = ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds().ToString(), SubscriptionType = SubscriptionType.NORMAL.ToString() }; diff --git a/Minecraft-Realms-Emulator/Entities/ServersArray.cs b/Minecraft-Realms-Emulator/Entities/ServersArray.cs new file mode 100644 index 0000000..471e056 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/ServersArray.cs @@ -0,0 +1,7 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class ServersArray + { + public List? Servers { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Subscription.cs b/Minecraft-Realms-Emulator/Entities/Subscription.cs index fdd1c0b..ed08048 100644 --- a/Minecraft-Realms-Emulator/Entities/Subscription.cs +++ b/Minecraft-Realms-Emulator/Entities/Subscription.cs @@ -4,7 +4,7 @@ { public int Id { get; set; } public World World { get; set; } - public DateTime StartDate { get; set; } = DateTime.Now; + public string StartDate { get; set; } = ((DateTimeOffset) DateTime.Now).ToUnixTimeMilliseconds().ToString(); public string SubscriptionType { get; set; } = "NORMAL"; } } \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Entities/World.cs b/Minecraft-Realms-Emulator/Entities/World.cs index 6ddcb72..6290f6b 100644 --- a/Minecraft-Realms-Emulator/Entities/World.cs +++ b/Minecraft-Realms-Emulator/Entities/World.cs @@ -11,6 +11,7 @@ namespace Minecraft_Realms_Emulator.Entities 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"; diff --git a/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs deleted file mode 100644 index 1a164b4..0000000 --- a/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs +++ /dev/null @@ -1,320 +0,0 @@ -// -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("20240315212618_Calculate_daysLeft")] - partial class Calculate_daysLeft - { - /// - 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"); - - 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("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("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.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") - .WithMany() - .HasForeignKey("WorldId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("World"); - }); - - modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => - { - b.Navigation("Players"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.cs b/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.cs deleted file mode 100644 index 3d94da1..0000000 --- a/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Minecraft_Realms_Emulator.Migrations -{ - /// - public partial class Calculate_daysLeft : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "DaysLeft", - table: "Worlds"); - - migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE timestamptz USING \"StartDate\"::timestamptz"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "DaysLeft", - table: "Worlds", - type: "integer", - nullable: false, - defaultValue: 0); - - migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE text USING \"StartDate\"::text"); - } - } -} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index 1d93cf1..e760e0e 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -170,8 +170,9 @@ namespace Minecraft_Realms_Emulator.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("StartDate") - .HasColumnType("timestamp with time zone"); + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); b.Property("SubscriptionType") .IsRequired() @@ -198,6 +199,9 @@ namespace Minecraft_Realms_Emulator.Migrations b.Property("ActiveSlot") .HasColumnType("integer"); + b.Property("DaysLeft") + .HasColumnType("integer"); + b.Property("Expired") .HasColumnType("boolean"); diff --git a/Minecraft-Realms-Emulator/Responses/ServersResponse.cs b/Minecraft-Realms-Emulator/Responses/ServersResponse.cs deleted file mode 100644 index c74e65f..0000000 --- a/Minecraft-Realms-Emulator/Responses/ServersResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Minecraft_Realms_Emulator.Entities; - -namespace Minecraft_Realms_Emulator.Responses -{ - public class ServersResponse - { - public List? Servers { get; set; } - } -} diff --git a/Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs b/Minecraft-Realms-Emulator/Responses/Subscription.cs similarity index 66% rename from Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs rename to Minecraft-Realms-Emulator/Responses/Subscription.cs index 59fd82f..1307794 100644 --- a/Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs +++ b/Minecraft-Realms-Emulator/Responses/Subscription.cs @@ -1,8 +1,8 @@ namespace Minecraft_Realms_Emulator.Responses { - public class SubscriptionResponse + public class Subscription { - public long StartDate { get; set; } + public string StartDate { get; set; } public int DaysLeft { get; set; } public string SubscriptionType { get; set; } } diff --git a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs deleted file mode 100644 index 2e143e3..0000000 --- a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Text.Json; - -namespace Minecraft_Realms_Emulator.Entities -{ - public class WorldResponse - { - public int Id { get; set; } - public string RemoteSubscriptionId { get; set; } = Guid.NewGuid().ToString(); - 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; - public string? MinigameName { get; set; } - public int? MinigameId { get; set; } - public string? MinigameImage { get; set; } - public int ActiveSlot { get; set; } = 1; - public JsonDocument[] Slots { get; set; } = []; - public bool Member { get; set; } = false; - } -} \ No newline at end of file