From 2b1c55d030a5f2e506d0ccd16d85b1e463be7a70 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Fri, 23 Feb 2024 12:43:00 +0100 Subject: [PATCH] fix: show include in world settings --- Minecraft-Realms-Emulator/Controllers/InvitesController.cs | 3 +-- Minecraft-Realms-Emulator/Controllers/WorldsController.cs | 2 +- Minecraft-Realms-Emulator/Program.cs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Minecraft-Realms-Emulator/Controllers/InvitesController.cs b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs index f38d6c0..0443802 100644 --- a/Minecraft-Realms-Emulator/Controllers/InvitesController.cs +++ b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs @@ -99,7 +99,7 @@ namespace Minecraft_Realms_Emulator.Controllers if (body.Name == playerName) return Forbid("You cannot invite yourself"); - var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId); + var world = await _context.Worlds.Include(w => w.Players).FirstOrDefaultAsync(w => w.Id == wId); if (world == null) return NotFound("World not found"); @@ -118,7 +118,6 @@ namespace Minecraft_Realms_Emulator.Controllers }; _context.Players.Add(player); -// world.Players.Add(player); Invite invite = new() { diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index 5385d7d..f756992 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -72,7 +72,7 @@ namespace Minecraft_Realms_Emulator.Controllers [HttpGet("{id}")] public async Task> GetWorldById(int id) { - var world = await _context.Worlds.FindAsync(id); + var world = await _context.Worlds.Include(w => w.Players).FirstOrDefaultAsync(w => w.Id == id); if (world == null) return NotFound("World not found"); diff --git a/Minecraft-Realms-Emulator/Program.cs b/Minecraft-Realms-Emulator/Program.cs index a42223f..0b338aa 100644 --- a/Minecraft-Realms-Emulator/Program.cs +++ b/Minecraft-Realms-Emulator/Program.cs @@ -5,7 +5,7 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddControllers(); +builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen();