Added node server sync and delete sync. Cleaned up codebase and extracted calls to apis to services

This commit is contained in:
2025-03-02 19:24:24 +01:00
parent ef7f866ded
commit 30390dab71
25 changed files with 751 additions and 282 deletions

View File

@@ -0,0 +1,84 @@
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonCore.Models;
using MoonlightServers.Shared.Http.Responses.Users.Servers;
namespace MoonlightServers.Frontend.Services;
[Scoped]
public class ServerService
{
private readonly HttpApiClient HttpApiClient;
public ServerService(HttpApiClient httpApiClient)
{
HttpApiClient = httpApiClient;
}
public async Task<PagedData<ServerDetailResponse>> GetServers(int page, int perPage)
{
return await HttpApiClient.GetJson<PagedData<ServerDetailResponse>>(
$"api/client/servers?page={page}&pageSize={perPage}"
);
}
public async Task<ServerDetailResponse> GetServer(int serverId)
{
return await HttpApiClient.GetJson<ServerDetailResponse>(
$"api/client/servers/{serverId}"
);
}
public async Task<ServerStatusResponse> GetStatus(int serverId)
{
return await HttpApiClient.GetJson<ServerStatusResponse>(
$"api/client/servers/{serverId}/status"
);
}
public async Task<ServerLogsResponse> GetLogs(int serverId)
{
return await HttpApiClient.GetJson<ServerLogsResponse>(
$"api/client/servers/{serverId}/logs"
);
}
public async Task<ServerWebSocketResponse> GetWebSocket(int serverId)
{
return await HttpApiClient.GetJson<ServerWebSocketResponse>(
$"api/client/servers/{serverId}/ws"
);
}
public async Task Install(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/install"
);
}
#region Power actions
public async Task Start(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/start"
);
}
public async Task Stop(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/stop"
);
}
public async Task Kill(int serverId)
{
await HttpApiClient.Post(
$"api/client/servers/{serverId}/kill"
);
}
#endregion
}