From 976fcca2e6dfa0b5f5c8872ac3c6ec8f24b54a29 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 26 Apr 2022 18:02:07 -0500 Subject: add endpoints to stop/cancel a search and delete a search record --- .../Search/API/Controllers/SearchesController.cs | 55 +++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'src/slskd/Search/API/Controllers') 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 GetAll() { - return Ok(await Searches.ListAsync()); + var searches = await Searches.ListAsync(); + return Ok(searches); + } + + /// + /// Stops the search corresponding to the specified . + /// + /// The unique id of the search. + /// The search was stopped. + /// The search was not in progress. + /// + [HttpPut("{id}")] + [Authorize] + [ProducesResponseType(200)] + [ProducesResponseType(304)] + public async Task 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); + } + + /// + /// Deletes the search corresponding to the specified . + /// + /// The unique id of the search. + /// The search was deleted. + /// A search with the specified id could not be found. + /// + [HttpDelete("{id}")] + [Authorize] + [ProducesResponseType(204)] + [ProducesResponseType(404)] + public async Task 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(); } } } -- cgit v1.2.3