From e94d256fc9fa87530da332dd42e2376347144c0b Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Tue, 13 Feb 2024 13:15:42 +0100 Subject: [PATCH] feat: subscription v2 --- .../Controllers/SubscriptionsController.cs | 15 +- .../Controllers/WorldsController.cs | 3 +- .../Entities/Subscription.cs | 3 +- ...20240213121346_Subscription_v2.Designer.cs | 168 ++++++++++++++++++ .../20240213121346_Subscription_v2.cs | 60 +++++++ .../Migrations/DataContextModelSnapshot.cs | 23 ++- .../Responses/Subscription.cs | 9 + Minecraft-Realms-Emulator/appsettings.json | 2 +- 8 files changed, 267 insertions(+), 16 deletions(-) create mode 100644 Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.Designer.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.cs create mode 100644 Minecraft-Realms-Emulator/Responses/Subscription.cs diff --git a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs index 71b9f57..184a432 100644 --- a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Minecraft_Realms_Emulator.Data; -using Minecraft_Realms_Emulator.Entities; +using Minecraft_Realms_Emulator.Responses; namespace Minecraft_Realms_Emulator.Controllers { @@ -21,11 +21,18 @@ namespace Minecraft_Realms_Emulator.Controllers var world = await _context.Worlds.FindAsync(id); var subscriptions = await _context.Subscriptions.ToListAsync(); - if (world == null) return NotFound("Subscription njot found"); + if (world == null) return NotFound("Subscription not found"); - var subscription = subscriptions.Find(s => s.RemoteId == world.RemoteSubscriptionId); + var subscription = subscriptions.Find(s => s.World.RemoteSubscriptionId == world.RemoteSubscriptionId); - return Ok(subscription); + var sub = new Subscription + { + StartDate = subscription.StartDate, + DaysLeft = subscription.World.DaysLeft, + SubscriptionType = subscription.SubscriptionType + }; + + return Ok(sub); } } } diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index c19fa2b..559be38 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -91,9 +91,8 @@ namespace Minecraft_Realms_Emulator.Controllers var subscription = new Subscription { - RemoteId = world.RemoteSubscriptionId, + World = world, StartDate = ((DateTimeOffset) DateTime.Now).ToUnixTimeMilliseconds().ToString(), - DaysLeft = 30, SubscriptionType = SubscriptionType.NORMAL.ToString() }; diff --git a/Minecraft-Realms-Emulator/Entities/Subscription.cs b/Minecraft-Realms-Emulator/Entities/Subscription.cs index 377b3f5..ed08048 100644 --- a/Minecraft-Realms-Emulator/Entities/Subscription.cs +++ b/Minecraft-Realms-Emulator/Entities/Subscription.cs @@ -3,9 +3,8 @@ public class Subscription { public int Id { get; set; } - public string RemoteId { get; set; } = Guid.NewGuid().ToString(); + public World World { get; set; } public string StartDate { get; set; } = ((DateTimeOffset) DateTime.Now).ToUnixTimeMilliseconds().ToString(); - public int DaysLeft { get; set; } = 30; public string SubscriptionType { get; set; } = "NORMAL"; } } \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.Designer.cs new file mode 100644 index 0000000..0a8858b --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.Designer.cs @@ -0,0 +1,168 @@ +// +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("20240213121346_Subscription_v2")] + partial class Subscription_v2 + { + /// + 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.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.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/20240213121346_Subscription_v2.cs b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.cs new file mode 100644 index 0000000..7a4781a --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.cs @@ -0,0 +1,60 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Subscription_v2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "RemoteId", + table: "Subscriptions"); + + migrationBuilder.RenameColumn( + name: "DaysLeft", + table: "Subscriptions", + newName: "WorldId"); + + migrationBuilder.CreateIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions", + column: "WorldId"); + + migrationBuilder.AddForeignKey( + name: "FK_Subscriptions_Worlds_WorldId", + table: "Subscriptions", + column: "WorldId", + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Subscriptions_Worlds_WorldId", + table: "Subscriptions"); + + migrationBuilder.DropIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions"); + + migrationBuilder.RenameColumn( + name: "WorldId", + table: "Subscriptions", + newName: "DaysLeft"); + + migrationBuilder.AddColumn( + name: "RemoteId", + table: "Subscriptions", + type: "text", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index 5be0406..c4fa217 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -48,13 +48,6 @@ namespace Minecraft_Realms_Emulator.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("DaysLeft") - .HasColumnType("integer"); - - b.Property("RemoteId") - .IsRequired() - .HasColumnType("text"); - b.Property("StartDate") .IsRequired() .HasColumnType("text"); @@ -63,8 +56,13 @@ namespace Minecraft_Realms_Emulator.Migrations .IsRequired() .HasColumnType("text"); + b.Property("WorldId") + .HasColumnType("integer"); + b.HasKey("Id"); + b.HasIndex("WorldId"); + b.ToTable("Subscriptions"); }); @@ -150,6 +148,17 @@ namespace Minecraft_Realms_Emulator.Migrations 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/Responses/Subscription.cs b/Minecraft-Realms-Emulator/Responses/Subscription.cs new file mode 100644 index 0000000..1307794 --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/Subscription.cs @@ -0,0 +1,9 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class Subscription + { + public string StartDate { get; set; } + public int DaysLeft { get; set; } + public string SubscriptionType { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/appsettings.json b/Minecraft-Realms-Emulator/appsettings.json index 282fb22..3ce2bc0 100644 --- a/Minecraft-Realms-Emulator/appsettings.json +++ b/Minecraft-Realms-Emulator/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "User Id=postgres.aquqykciubzfolgrftwa;Password=SNYcLhJsLGiWeB2K;Server=aws-0-us-west-1.pooler.supabase.com;Port=5432;Database=postgres" + "DefaultConnection": "User Id=postgres.aquqykciubzfolgrftwa;Password=z6hmYsiCl0f7HzUr;Server=aws-0-us-west-1.pooler.supabase.com;Port=5432;Database=postgres" }, "Logging": { "LogLevel": {