feat: ops

This commit is contained in:
CyberL1 2024-02-23 13:21:22 +01:00
parent 226a85e054
commit b154d803ae
3 changed files with 82 additions and 1 deletions

View File

@ -2,7 +2,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Data; using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities; using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Migrations;
using Minecraft_Realms_Emulator.Responses; using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Controllers namespace Minecraft_Realms_Emulator.Controllers

View File

@ -0,0 +1,75 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Controllers
{
[Route("[controller]")]
[ApiController]
public class OpsController : ControllerBase
{
private readonly DataContext _context;
public OpsController(DataContext context)
{
_context = context;
}
[HttpPost("{wId}/{uuid}")]
public ActionResult<OpsResponse> OpPlayer(int wId, string uuid)
{
var ops = _context.Players.Where(p => p.World.Id == wId && p.Operator == true).ToList();
var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid);
List<string> opNames = [];
foreach (var op in ops)
{
opNames.Add(op.Name);
}
player.Permission = "OPERATOR";
player.Operator = true;
_context.SaveChanges();
opNames.Add(player.Name);
var opsResponse = new OpsResponse
{
Ops = opNames
};
return Ok(opsResponse);
}
[HttpDelete("{wId}/{uuid}")]
public ActionResult<OpsResponse> DeopPlayer(int wId, string uuid)
{
var ops = _context.Players.Where(p => p.World.Id == wId && p.Operator == true).ToList();
var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid);
List<string> opNames = [];
foreach (var op in ops)
{
opNames.Add(op.Name);
}
player.Permission = "MEMBER";
player.Operator = false;
_context.SaveChanges();
opNames.Remove(player.Name);
var opsResponse = new OpsResponse
{
Ops = opNames
};
return Ok(opsResponse);
}
}
}

View File

@ -0,0 +1,7 @@
namespace Minecraft_Realms_Emulator.Responses
{
public class OpsResponse
{
public List<string> Ops { get; set; }
}
}