aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Controllers/UserController.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-02-13 07:58:15 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-02-13 07:58:15 -0600
commit936ed099a6e5258f9fd5a5ac026afc0630359b98 (patch)
treef406e1f1b9fc29391e471c65b708ba6d94b72027 /src/slskd/Controllers/UserController.cs
parent87f024fa2561f751fc26c129bfaa373a966f1c67 (diff)
downloadslskd-936ed099a6e5258f9fd5a5ac026afc0630359b98.tar.gz
move controllers and DTOs to API namespace
Diffstat (limited to 'src/slskd/Controllers/UserController.cs')
-rw-r--r--src/slskd/Controllers/UserController.cs151
1 files changed, 0 insertions, 151 deletions
diff --git a/src/slskd/Controllers/UserController.cs b/src/slskd/Controllers/UserController.cs
deleted file mode 100644
index e4a0859f..00000000
--- a/src/slskd/Controllers/UserController.cs
+++ /dev/null
@@ -1,151 +0,0 @@
-namespace slskd.Controllers
-{
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Soulseek;
- using slskd.DTO;
- using slskd.Trackers;
-
- /// <summary>
- /// Users
- /// </summary>
- [Route("api/v{version:apiVersion}/[controller]")]
- [ApiVersion("0")]
- [ApiController]
- [Produces("application/json")]
- [Consumes("application/json")]
- public class UserController : ControllerBase
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="UserController"/> class.
- /// </summary>
- /// <param name="client"></param>
- /// <param name="browseTracker"></param>
- public UserController(ISoulseekClient client, IBrowseTracker browseTracker)
- {
- Client = client;
- BrowseTracker = browseTracker;
- }
-
- private ISoulseekClient Client { get; }
- private IBrowseTracker BrowseTracker { get; }
-
- /// <summary>
- /// Retrieves the address of the specified <paramref name="username"/>.
- /// </summary>
- /// <param name="username">The username of the user.</param>
- /// <returns></returns>
- /// <response code="200">The request completed successfully.</response>
- [HttpGet("{username}/address")]
- [Authorize]
- [ProducesResponseType(typeof(UserAddress), 200)]
- [ProducesResponseType(404)]
- public async Task<IActionResult> Address([FromRoute, Required]string username)
- {
- try
- {
- var endpoint = await Client.GetUserEndPointAsync(username);
- return Ok(new UserAddress() { IPAddress = endpoint.Address.ToString(), Port = endpoint.Port });
- }
- catch (UserOfflineException ex)
- {
- return NotFound(ex.Message);
- }
- }
-
- /// <summary>
- /// Retrieves the files shared by the specified <paramref name="username"/>.
- /// </summary>
- /// <param name="username">The username of the user.</param>
- /// <returns></returns>
- [HttpGet("{username}/browse")]
- [Authorize]
- [ProducesResponseType(typeof(IEnumerable<Directory>), 200)]
- [ProducesResponseType(404)]
- public async Task<IActionResult> Browse([FromRoute, Required]string username)
- {
- try
- {
- var result = await Client.BrowseAsync(username);
-
- _ = Task.Run(async () =>
- {
- await Task.Delay(5000);
- BrowseTracker.TryRemove(username);
- });
-
- return Ok(result);
- }
- catch (UserOfflineException ex)
- {
- return NotFound(ex.Message);
- }
- }
-
- /// <summary>
- /// Retrieves the status of the current browse operation for the specified <paramref name="username"/>, if any.
- /// </summary>
- /// <param name="username">The username of the user.</param>
- /// <returns></returns>
- [HttpGet("{username}/browse/status")]
- [Authorize]
- [ProducesResponseType(typeof(decimal), 200)]
- [ProducesResponseType(404)]
- public IActionResult BrowseStatus([FromRoute, Required]string username)
- {
- if (BrowseTracker.TryGet(username, out var progress))
- {
- return Ok(progress);
- }
-
- return NotFound();
- }
-
- /// <summary>
- /// Retrieves information about the specified <paramref name="username"/>.
- /// </summary>
- /// <param name="username">The username of the user.</param>
- /// <returns></returns>
- [HttpGet("{username}/info")]
- [Authorize]
- [ProducesResponseType(typeof(UserInfo), 200)]
- [ProducesResponseType(404)]
- public async Task<IActionResult> Info([FromRoute, Required]string username)
- {
- try
- {
- var response = await Client.GetUserInfoAsync(username);
- return Ok(response);
- }
- catch (UserOfflineException ex)
- {
- return NotFound(ex.Message);
- }
- }
-
- /// <summary>
- /// Retrieves status for the specified <paramref name="username"/>.
- /// </summary>
- /// <param name="username">The username of the user.</param>
- /// <returns></returns>
- [HttpGet("{username}/status")]
- [Authorize]
- [ProducesResponseType(typeof(UserStatus), 200)]
- [ProducesResponseType(404)]
- public async Task<IActionResult> Status([FromRoute, Required]string username)
- {
- try
- {
- var response = await Client.GetUserStatusAsync(username);
- return Ok(response);
- }
- catch (UserOfflineException ex)
- {
- return NotFound(ex.Message);
- }
- }
- }
-} \ No newline at end of file