diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-04-26 18:02:07 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-04-26 18:02:07 -0500 |
| commit | 976fcca2e6dfa0b5f5c8872ac3c6ec8f24b54a29 (patch) | |
| tree | db799aed286ee3bb9c344d902727cd49c9d38db2 /src | |
| parent | c4ed5c09f5d07e9b5b837590686c4b9e96f9a869 (diff) | |
| download | slskd-976fcca2e6dfa0b5f5c8872ac3c6ec8f24b54a29.tar.gz | |
add endpoints to stop/cancel a search and delete a search record
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Search/API/Controllers/SearchesController.cs | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/src/slskd/Search/API/Controllers/SearchesController.cs b/src/slskd/Search/API/Controllers/SearchesController.cs index 5f740044..ae0f6570 100644 --- a/src/slskd/Search/API/Controllers/SearchesController.cs +++ b/src/slskd/Search/API/Controllers/SearchesController.cs @@ -129,7 +129,60 @@ namespace slskd.Search.API [Authorize] public async Task<IActionResult> GetAll() { - return Ok(await Searches.ListAsync()); + var searches = await Searches.ListAsync(); + return Ok(searches); + } + + /// <summary> + /// Stops the search corresponding to the specified <paramref name="id"/>. + /// </summary> + /// <param name="id">The unique id of the search.</param> + /// <response code="200">The search was stopped.</response> + /// <response code="304">The search was not in progress.</response> + /// <returns></returns> + [HttpPut("{id}")] + [Authorize] + [ProducesResponseType(200)] + [ProducesResponseType(304)] + public async Task<IActionResult> Cancel([FromRoute] Guid id) + { + var search = await Searches.FindAsync(search => search.Id == id); + + if (search == default) + { + return NotFound(); + } + + if (Searches.TryCancel(id)) + { + return Ok(); + } + + return StatusCode(304); + } + + /// <summary> + /// Deletes the search corresponding to the specified <paramref name="id"/>. + /// </summary> + /// <param name="id">The unique id of the search.</param> + /// <response code="204">The search was deleted.</response> + /// <response code="404">A search with the specified id could not be found.</response> + /// <returns></returns> + [HttpDelete("{id}")] + [Authorize] + [ProducesResponseType(204)] + [ProducesResponseType(404)] + public async Task<IActionResult> Delete([FromRoute] Guid id) + { + var search = await Searches.FindAsync(search => search.Id == id, includeResponses: true); + + if (search == default) + { + return NotFound(); + } + + await Searches.DeleteAsync(search); + return NoContent(); } } } |
