Files
Servers/MoonlightServers.Daemon/Http/Controllers/Servers/ServersController.cs

29 lines
768 B
C#

using Microsoft.AspNetCore.Mvc;
using MoonCore.Exceptions;
using MoonlightServers.Daemon.Models;
using MoonlightServers.Daemon.Services;
namespace MoonlightServers.Daemon.Http.Controllers.Servers;
[ApiController]
[Route("api/servers")]
public class ServersController : Controller
{
private readonly ServerService ServerService;
public ServersController(ServerService serverService)
{
ServerService = serverService;
}
[HttpPost("{serverId}/start")]
public async Task Start(int serverId)
{
var server = ServerService.GetServer(serverId);
if (server == null)
throw new HttpApiException("No server with this id found", 404);
await server.StateMachine.TransitionTo(ServerState.Starting);
}
}