mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2024-11-22 06:08:22 -05:00
feat: daysLeft calculation
This commit is contained in:
parent
89025e31b2
commit
deabd84257
@ -16,7 +16,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
_context = context;
|
||||
}
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Subscription>> Get(int id)
|
||||
public async Task<ActionResult<SubscriptionResponse>> 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 Subscription
|
||||
var sub = new SubscriptionResponse
|
||||
{
|
||||
StartDate = subscription.StartDate,
|
||||
DaysLeft = subscription.World.DaysLeft,
|
||||
StartDate = ((DateTimeOffset) subscription.StartDate).ToUnixTimeMilliseconds(),
|
||||
DaysLeft = (subscription.StartDate.AddDays(30) - DateTime.UtcNow).Days,
|
||||
SubscriptionType = subscription.SubscriptionType
|
||||
};
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Entities;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
@ -17,7 +18,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<ServersArray>> GetWorlds()
|
||||
public async Task<ActionResult<ServersResponse>> GetWorlds()
|
||||
{
|
||||
string cookie = Request.Headers.Cookie;
|
||||
|
||||
@ -37,7 +38,6 @@ 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);
|
||||
|
||||
ServersArray servers = new()
|
||||
ServersResponse servers = new()
|
||||
{
|
||||
Servers = allWorlds
|
||||
};
|
||||
@ -95,7 +95,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
var subscription = new Subscription
|
||||
{
|
||||
World = world,
|
||||
StartDate = ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds().ToString(),
|
||||
StartDate = DateTime.UtcNow,
|
||||
SubscriptionType = SubscriptionType.NORMAL.ToString()
|
||||
};
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace Minecraft_Realms_Emulator.Entities
|
||||
{
|
||||
public class ServersArray
|
||||
{
|
||||
public List<World>? Servers { get; set; }
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public World World { get; set; }
|
||||
public string StartDate { get; set; } = ((DateTimeOffset) DateTime.Now).ToUnixTimeMilliseconds().ToString();
|
||||
public DateTime StartDate { get; set; } = DateTime.Now;
|
||||
public string SubscriptionType { get; set; } = "NORMAL";
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ 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";
|
||||
|
320
Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs
generated
Normal file
320
Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs
generated
Normal file
@ -0,0 +1,320 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BackupId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long>("LastModifiedDate")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<JsonDocument>("Metadata")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<int>("Size")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorldId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorldId");
|
||||
|
||||
b.ToTable("Backups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
|
||||
{
|
||||
b.Property<string>("Key")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Key");
|
||||
|
||||
b.ToTable("Configuration");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("PendingUpdate")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("WorldId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorldId");
|
||||
|
||||
b.ToTable("Connections");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("InvitationId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("RecipeintUUID")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("WorldId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorldId");
|
||||
|
||||
b.ToTable("Invites");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("Accepted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("Online")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("Operator")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Permission")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Uuid")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("WorldId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorldId");
|
||||
|
||||
b.ToTable("Players");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SubscriptionType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("WorldId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorldId");
|
||||
|
||||
b.ToTable("Subscriptions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ActiveSlot")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("Expired")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("ExpiredTrial")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("MaxPlayers")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("Member")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("MinigameId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("MinigameImage")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("MinigameName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Motd")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Owner")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OwnerUUID")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("RemoteSubscriptionId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<JsonDocument[]>("Slots")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb[]");
|
||||
|
||||
b.Property<string>("State")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("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
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Calculate_daysLeft : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "DaysLeft",
|
||||
table: "Worlds",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE text USING \"StartDate\"::text");
|
||||
}
|
||||
}
|
||||
}
|
@ -170,9 +170,8 @@ namespace Minecraft_Realms_Emulator.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("StartDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SubscriptionType")
|
||||
.IsRequired()
|
||||
@ -199,9 +198,6 @@ namespace Minecraft_Realms_Emulator.Migrations
|
||||
b.Property<int>("ActiveSlot")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("DaysLeft")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("Expired")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
|
9
Minecraft-Realms-Emulator/Responses/ServersResponse.cs
Normal file
9
Minecraft-Realms-Emulator/Responses/ServersResponse.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Minecraft_Realms_Emulator.Entities;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Responses
|
||||
{
|
||||
public class ServersResponse
|
||||
{
|
||||
public List<World>? Servers { get; set; }
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
namespace Minecraft_Realms_Emulator.Responses
|
||||
{
|
||||
public class Subscription
|
||||
public class SubscriptionResponse
|
||||
{
|
||||
public string StartDate { get; set; }
|
||||
public long StartDate { get; set; }
|
||||
public int DaysLeft { get; set; }
|
||||
public string SubscriptionType { get; set; }
|
||||
}
|
27
Minecraft-Realms-Emulator/Responses/WorldResponse.cs
Normal file
27
Minecraft-Realms-Emulator/Responses/WorldResponse.cs
Normal file
@ -0,0 +1,27 @@
|
||||
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<Player> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user