From c38f0ecc3c8e98d178af7113841485dcbd2506d9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 19 Jun 2021 21:57:04 -0500 Subject: use ManagementService, remove args for connect method --- .../Management/API/Controllers/ServerController.cs | 32 ++++++---------------- 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'src/slskd/Application/Management/API/Controllers/ServerController.cs') diff --git a/src/slskd/Application/Management/API/Controllers/ServerController.cs b/src/slskd/Application/Management/API/Controllers/ServerController.cs index ed911a13..da4a0182 100644 --- a/src/slskd/Application/Management/API/Controllers/ServerController.cs +++ b/src/slskd/Application/Management/API/Controllers/ServerController.cs @@ -20,7 +20,6 @@ namespace slskd.Management.API using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; - using Soulseek; /// /// Server. @@ -32,12 +31,13 @@ namespace slskd.Management.API [Consumes("application/json")] public class ServerController : ControllerBase { - public ServerController(ISoulseekClient client) + public ServerController( + IManagementService managementService) { - Client = client; + Management = managementService; } - private ISoulseekClient Client { get; } + private IManagementService Management { get; } /// /// Connects the client. @@ -46,26 +46,10 @@ namespace slskd.Management.API /// [HttpPost] [Authorize] - public async Task Connect([FromBody] ConnectRequest req) + public async Task Connect() { - var addr = !string.IsNullOrEmpty(req.Address); - var port = req.Port.HasValue; - var un = !string.IsNullOrEmpty(req.Username); - var pw = !string.IsNullOrEmpty(req.Password); - - if (addr && port && un && pw) - { - await Client.ConnectAsync(req.Address, req.Port.Value, req.Username, req.Password); - return Ok(); - } - - if (!addr && !port && un && pw) - { - await Client.ConnectAsync(req.Username, req.Password); - return Ok(); - } - - return BadRequest("Provide one of the following: address and port, username and password, or address, port, username and password"); + await Management.ConnectClientAsync(); + return Ok(); } /// @@ -77,7 +61,7 @@ namespace slskd.Management.API [Authorize] public IActionResult Disconnect([FromBody] string message) { - Client.Disconnect(message); + Management.DisconnectClient(message); return NoContent(); } } -- cgit v1.2.3 From f11272fb90650215eb0cc672dc1e79834e71ecf0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 20 Jun 2021 13:55:19 -0500 Subject: add GET for server state --- .../Management/API/Controllers/ServerController.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/slskd/Application/Management/API/Controllers/ServerController.cs') diff --git a/src/slskd/Application/Management/API/Controllers/ServerController.cs b/src/slskd/Application/Management/API/Controllers/ServerController.cs index da4a0182..5826d36a 100644 --- a/src/slskd/Application/Management/API/Controllers/ServerController.cs +++ b/src/slskd/Application/Management/API/Controllers/ServerController.cs @@ -48,7 +48,7 @@ namespace slskd.Management.API [Authorize] public async Task Connect() { - await Management.ConnectClientAsync(); + await Management.ConnectServerAsync(); return Ok(); } @@ -61,8 +61,15 @@ namespace slskd.Management.API [Authorize] public IActionResult Disconnect([FromBody] string message) { - Management.DisconnectClient(message); + Management.DisconnectServer(message); return NoContent(); } + + [HttpGet] + [Authorize] + public IActionResult Get() + { + return Ok(Management.GetServerState()); + } } } \ No newline at end of file -- cgit v1.2.3 From ad6e6cc996c1cf2d42d063443b4dc4efa6048e2f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 22 Jun 2021 09:43:37 -0500 Subject: don't connect or disconnect if the client is already in that state --- .../Management/API/Controllers/ServerController.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/slskd/Application/Management/API/Controllers/ServerController.cs') diff --git a/src/slskd/Application/Management/API/Controllers/ServerController.cs b/src/slskd/Application/Management/API/Controllers/ServerController.cs index 5826d36a..0fc18e9e 100644 --- a/src/slskd/Application/Management/API/Controllers/ServerController.cs +++ b/src/slskd/Application/Management/API/Controllers/ServerController.cs @@ -44,11 +44,15 @@ namespace slskd.Management.API /// /// /// - [HttpPost] + [HttpPut] [Authorize] public async Task Connect() { - await Management.ConnectServerAsync(); + if (!Management.GetServerState().IsConnected) + { + await Management.ConnectServerAsync(); + } + return Ok(); } @@ -61,10 +65,18 @@ namespace slskd.Management.API [Authorize] public IActionResult Disconnect([FromBody] string message) { - Management.DisconnectServer(message); + if (Management.GetServerState().IsConnected) + { + Management.DisconnectServer(message); + } + return NoContent(); } + /// + /// Retrieves the current state of the server. + /// + /// [HttpGet] [Authorize] public IActionResult Get() -- cgit v1.2.3 From d170ab0f1ba323b55001c0bfa5a0eef23c30551f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 22 Jun 2021 09:58:10 -0500 Subject: docs --- .../Management/API/Controllers/ServerController.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/slskd/Application/Management/API/Controllers/ServerController.cs') diff --git a/src/slskd/Application/Management/API/Controllers/ServerController.cs b/src/slskd/Application/Management/API/Controllers/ServerController.cs index 0fc18e9e..6468063c 100644 --- a/src/slskd/Application/Management/API/Controllers/ServerController.cs +++ b/src/slskd/Application/Management/API/Controllers/ServerController.cs @@ -42,10 +42,12 @@ namespace slskd.Management.API /// /// Connects the client. /// - /// /// [HttpPut] + [Route("")] [Authorize] + [ProducesResponseType(200)] + [ProducesResponseType(403)] public async Task Connect() { if (!Management.GetServerState().IsConnected) @@ -62,7 +64,10 @@ namespace slskd.Management.API /// /// [HttpDelete] + [Route("")] [Authorize] + [ProducesResponseType(204)] + [ProducesResponseType(403)] public IActionResult Disconnect([FromBody] string message) { if (Management.GetServerState().IsConnected) @@ -77,8 +82,12 @@ namespace slskd.Management.API /// Retrieves the current state of the server. /// /// + /// [HttpGet] + [Route("")] [Authorize] + [ProducesResponseType(typeof(ServerState), 200)] + [ProducesResponseType(403)] public IActionResult Get() { return Ok(Management.GetServerState()); -- cgit v1.2.3