mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
ByondClient
This commit is contained in:
@@ -28,6 +28,11 @@ namespace Tgstation.Server.Api
|
||||
/// </summary>
|
||||
public const string InstanceManager = Root + nameof(Models.Instance);
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Models.Byond"/> controller
|
||||
/// </summary>
|
||||
public const string Byond = Root + nameof(Models.Byond);
|
||||
|
||||
/// <summary>
|
||||
/// Apply an <paramref name="id"/> postfix to a <paramref name="route"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -81,5 +81,35 @@ namespace Tgstation.Server.Client
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<TResult> Create<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<TResult> Read<TResult>(string route, long instanceId, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<TResult> Update<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<TResult> Update<TResult>(string route, long instanceId, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task Update<TBody>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task Delete(string route, long instanceId, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api;
|
||||
using Tgstation.Server.Api.Models;
|
||||
|
||||
namespace Tgstation.Server.Client.Components
|
||||
{
|
||||
/// <inheritdoc />
|
||||
sealed class ByondClient : IByondClient
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IApiClient"/> for the <see cref="ByondClient"/>
|
||||
/// </summary>
|
||||
readonly IApiClient apiClient;
|
||||
/// <summary>
|
||||
/// The <see cref="Instance"/> for the <see cref="ByondClient"/>
|
||||
/// </summary>
|
||||
readonly Instance instance;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="ByondClient"/>
|
||||
/// </summary>
|
||||
/// <param name="apiClient">The value of <see cref="apiClient"/></param>
|
||||
/// <param name="instance"></param>
|
||||
public ByondClient(IApiClient apiClient, Instance instance)
|
||||
{
|
||||
this.apiClient = apiClient;
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Byond> Read(CancellationToken cancellationToken) => apiClient.Read<Byond>(Routes.Byond, instance.Id, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Byond> Update(Byond byond, CancellationToken cancellationToken) => apiClient.Update<Byond, Byond>(Routes.Byond, byond, instance.Id, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace Tgstation.Server.Client.Components
|
||||
public Instance Metadata { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IByondClient Byond => throw new NotImplementedException();
|
||||
public IByondClient Byond { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRepositoryClient Repository => throw new NotImplementedException();
|
||||
@@ -47,6 +47,8 @@ namespace Tgstation.Server.Client.Components
|
||||
{
|
||||
this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
|
||||
Metadata = instance ?? throw new ArgumentNullException(nameof(instance));
|
||||
|
||||
Byond = new ByondClient(apiClient, instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,12 @@ namespace Tgstation.Server.Client
|
||||
Task<TResult> Update<TResult>(string route, CancellationToken cancellationToken);
|
||||
Task Update<TBody>(string route, TBody body, CancellationToken cancellationToken);
|
||||
Task Delete(string route, CancellationToken cancellationToken);
|
||||
|
||||
Task<TResult> Create<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken);
|
||||
Task<TResult> Read<TResult>(string route, long instanceId, CancellationToken cancellationToken);
|
||||
Task<TResult> Update<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken);
|
||||
Task<TResult> Update<TResult>(string route, long instanceId, CancellationToken cancellationToken);
|
||||
Task Update<TBody>(string route, TBody body, long instanceId, CancellationToken cancellationToken);
|
||||
Task Delete(string route, long instanceId, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Tgstation.Server.Client
|
||||
public InstanceManagerClient(IApiClient apiClient)
|
||||
{
|
||||
this.apiClient = apiClient;
|
||||
|
||||
cachedClients = new Dictionary<long, IInstanceClient>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -42,6 +44,14 @@ namespace Tgstation.Server.Client
|
||||
public Task<Instance> Update(Instance instance, CancellationToken cancellationToken) => apiClient.Update<Instance, Instance>(Routes.InstanceManager, instance, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IInstanceClient CreateClient(Instance instance) => new InstanceClient(apiClient, instance);
|
||||
public IInstanceClient CreateClient(Instance instance)
|
||||
{
|
||||
if (!cachedClients.TryGetValue(instance.Id, out var client))
|
||||
{
|
||||
client = new InstanceClient(apiClient, instance);
|
||||
cachedClients.Add(instance.Id, client);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Api.Rights;
|
||||
using Tgstation.Server.Host.Components;
|
||||
@@ -17,7 +18,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <summary>
|
||||
/// Controller for managing <see cref="Api.Models.Byond.Version"/>s
|
||||
/// </summary>
|
||||
[Route("/" + nameof(Byond))]
|
||||
[Route(Routes.Byond)]
|
||||
public sealed class ByondController : ModelController<Api.Models.Byond>
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user