chore: tidy up code

This commit is contained in:
CyberL1 2024-04-16 08:16:25 +02:00
parent b390a9105f
commit c5594b3460
9 changed files with 35 additions and 49 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34511.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Minecraft-Realms-Emulator", "Minecraft-Realms-Emulator\Minecraft-Realms-Emulator.csproj", "{A9A21AAF-EF1B-4723-9407-51FD6B831B98}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minecraft-Realms-Emulator", "Minecraft-Realms-Emulator\Minecraft-Realms-Emulator.csproj", "{A9A21AAF-EF1B-4723-9407-51FD6B831B98}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Requests;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Controllers
{
@ -19,7 +21,7 @@ namespace Minecraft_Realms_Emulator.Controllers
}
[HttpGet]
public async Task<ActionResult<ServersArray>> GetWorlds()
public async Task<ActionResult<ServersResponse>> GetWorlds()
{
string cookie = Request.Headers.Cookie;
@ -39,8 +41,8 @@ namespace Minecraft_Realms_Emulator.Controllers
OwnerUUID = playerUUID,
Name = null,
Motd = null,
State = State.UNINITIALIZED.ToString(),
WorldType = WorldType.NORMAL.ToString(),
State = "UNINITIALIZED",
WorldType = "NORMAL",
MaxPlayers = 10,
MinigameId = null,
MinigameName = null,
@ -111,7 +113,7 @@ namespace Minecraft_Realms_Emulator.Controllers
allWorlds.Add(response);
}
ServersArray servers = new()
ServersResponse servers = new()
{
Servers = allWorlds
};
@ -151,14 +153,14 @@ namespace Minecraft_Realms_Emulator.Controllers
}
[HttpPost("{id}/initialize")]
public async Task<ActionResult<World>> Initialize(int id, WorldCreate body)
public async Task<ActionResult<World>> Initialize(int id, WorldCreateRequest body)
{
var worlds = await _context.Worlds.ToListAsync();
var world = worlds.Find(w => w.Id == id);
if (world == null) return NotFound("World not found");
if (world.State != State.UNINITIALIZED.ToString()) return NotFound("World already initialized");
if (world.State != "UNINITIALIZED") return NotFound("World already initialized");
var subscription = new Subscription
{
@ -168,7 +170,7 @@ namespace Minecraft_Realms_Emulator.Controllers
world.Name = body.Name;
world.Motd = body.Description;
world.State = State.OPEN.ToString();
world.State = "OPEN";
world.Subscription = subscription;
var connection = new Connection
@ -203,7 +205,7 @@ namespace Minecraft_Realms_Emulator.Controllers
if (world == null) return NotFound("World not found");
world.State = State.OPEN.ToString();
world.State = "OPEN";
_context.SaveChanges();
@ -219,7 +221,7 @@ namespace Minecraft_Realms_Emulator.Controllers
if (world == null) return NotFound("World not found");
world.State = State.CLOSED.ToString();
world.State = "CLOSED";
_context.SaveChanges();
@ -227,7 +229,7 @@ namespace Minecraft_Realms_Emulator.Controllers
}
[HttpPost("{id}")]
public async Task<ActionResult<bool>> UpdateWorld(int id, WorldCreate body)
public async Task<ActionResult<bool>> UpdateWorld(int id, WorldCreateRequest body)
{
var worlds = await _context.Worlds.ToListAsync();
@ -251,11 +253,11 @@ namespace Minecraft_Realms_Emulator.Controllers
}
[HttpGet("{Id}/backups")]
public async Task<ActionResult<BackupList>> GetBackups(int id)
public async Task<ActionResult<BackupsResponse>> GetBackups(int id)
{
var backups = await _context.Backups.Where(b => b.World.Id == id).ToListAsync();
BackupList worldBackups = new()
BackupsResponse worldBackups = new()
{
Backups = backups
};

View File

@ -1,7 +0,0 @@
namespace Minecraft_Realms_Emulator.Entities
{
public class BackupList
{
public List<Backup> Backups { get; set; }
}
}

View File

@ -1,7 +0,0 @@
namespace Minecraft_Realms_Emulator.Entities
{
public class ServersArray
{
public List<WorldResponse>? Servers { get; set; }
}
}

View File

@ -1,10 +0,0 @@
namespace Minecraft_Realms_Emulator.Entities
{
public enum State
{
OPEN,
CLOSED,
ADMIN_LOCK,
UNINITIALIZED
}
}

View File

@ -1,10 +0,0 @@
namespace Minecraft_Realms_Emulator.Entities
{
public enum WorldType
{
NORMAL,
SUPERFLAT,
LARGEBIOMES,
AMPLIFIED
}
}

View File

@ -1,6 +1,6 @@
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Requests
{
public class WorldCreate
public class WorldCreateRequest
{
public string? Name { get; set; }
public string? Description { get; set; }

View File

@ -0,0 +1,9 @@
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Responses
{
public class BackupsResponse
{
public List<Backup> Backups { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Responses
{
public class ServersResponse
{
public List<WorldResponse>? Servers { get; set; }
}
}