diff --git a/src/Tgstation.Server.Api/Routes.cs b/src/Tgstation.Server.Api/Routes.cs index baa11b5859..0890e714d1 100644 --- a/src/Tgstation.Server.Api/Routes.cs +++ b/src/Tgstation.Server.Api/Routes.cs @@ -28,6 +28,11 @@ namespace Tgstation.Server.Api /// public const string InstanceManager = Root + nameof(Models.Instance); + /// + /// The controller + /// + public const string Byond = Root + nameof(Models.Byond); + /// /// Apply an postfix to a /// diff --git a/src/Tgstation.Server.Client/ApiClient.cs b/src/Tgstation.Server.Client/ApiClient.cs index 10b2ff6ecc..dcadaf9698 100644 --- a/src/Tgstation.Server.Client/ApiClient.cs +++ b/src/Tgstation.Server.Client/ApiClient.cs @@ -81,5 +81,35 @@ namespace Tgstation.Server.Client { throw new NotImplementedException(); } + + public Task Create(string route, TBody body, long instanceId, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task Read(string route, long instanceId, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task Update(string route, TBody body, long instanceId, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task Update(string route, long instanceId, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task Update(string route, TBody body, long instanceId, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public Task Delete(string route, long instanceId, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/src/Tgstation.Server.Client/Components/ByondClient.cs b/src/Tgstation.Server.Client/Components/ByondClient.cs new file mode 100644 index 0000000000..e066407afe --- /dev/null +++ b/src/Tgstation.Server.Client/Components/ByondClient.cs @@ -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 +{ + /// + sealed class ByondClient : IByondClient + { + /// + /// The for the + /// + readonly IApiClient apiClient; + /// + /// The for the + /// + readonly Instance instance; + + /// + /// Construct a + /// + /// The value of + /// + public ByondClient(IApiClient apiClient, Instance instance) + { + this.apiClient = apiClient; + this.instance = instance; + } + + /// + public Task Read(CancellationToken cancellationToken) => apiClient.Read(Routes.Byond, instance.Id, cancellationToken); + + /// + public Task Update(Byond byond, CancellationToken cancellationToken) => apiClient.Update(Routes.Byond, byond, instance.Id, cancellationToken); + } +} \ No newline at end of file diff --git a/src/Tgstation.Server.Client/Components/InstanceClient.cs b/src/Tgstation.Server.Client/Components/InstanceClient.cs index 3d7f5f3457..c585d201f5 100644 --- a/src/Tgstation.Server.Client/Components/InstanceClient.cs +++ b/src/Tgstation.Server.Client/Components/InstanceClient.cs @@ -10,7 +10,7 @@ namespace Tgstation.Server.Client.Components public Instance Metadata { get; } /// - public IByondClient Byond => throw new NotImplementedException(); + public IByondClient Byond { get; } /// 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); } } } \ No newline at end of file diff --git a/src/Tgstation.Server.Client/IApiClient.cs b/src/Tgstation.Server.Client/IApiClient.cs index 46fad817a0..89121e40ce 100644 --- a/src/Tgstation.Server.Client/IApiClient.cs +++ b/src/Tgstation.Server.Client/IApiClient.cs @@ -22,5 +22,12 @@ namespace Tgstation.Server.Client Task Update(string route, CancellationToken cancellationToken); Task Update(string route, TBody body, CancellationToken cancellationToken); Task Delete(string route, CancellationToken cancellationToken); + + Task Create(string route, TBody body, long instanceId, CancellationToken cancellationToken); + Task Read(string route, long instanceId, CancellationToken cancellationToken); + Task Update(string route, TBody body, long instanceId, CancellationToken cancellationToken); + Task Update(string route, long instanceId, CancellationToken cancellationToken); + Task Update(string route, TBody body, long instanceId, CancellationToken cancellationToken); + Task Delete(string route, long instanceId, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Client/InstanceManagerClient.cs b/src/Tgstation.Server.Client/InstanceManagerClient.cs index 19c94aa075..b89056b302 100644 --- a/src/Tgstation.Server.Client/InstanceManagerClient.cs +++ b/src/Tgstation.Server.Client/InstanceManagerClient.cs @@ -27,6 +27,8 @@ namespace Tgstation.Server.Client public InstanceManagerClient(IApiClient apiClient) { this.apiClient = apiClient; + + cachedClients = new Dictionary(); } /// @@ -42,6 +44,14 @@ namespace Tgstation.Server.Client public Task Update(Instance instance, CancellationToken cancellationToken) => apiClient.Update(Routes.InstanceManager, instance, cancellationToken); /// - 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; + } } } \ No newline at end of file diff --git a/src/Tgstation.Server.Host/Controllers/ByondController.cs b/src/Tgstation.Server.Host/Controllers/ByondController.cs index 0d89f56d12..e685bc7a9a 100644 --- a/src/Tgstation.Server.Host/Controllers/ByondController.cs +++ b/src/Tgstation.Server.Host/Controllers/ByondController.cs @@ -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 /// /// Controller for managing s /// - [Route("/" + nameof(Byond))] + [Route(Routes.Byond)] public sealed class ByondController : ModelController { ///