mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-14 15:42:02 +02:00
Return a delete count from the delete-all response helpers
`response delete` had to run its own list first just to report how many it removed, which duplicated the query the helper already does. Both helpers now return the count instead. `cmd_delete_all_http_responses` was returning the helper's value directly, so it keeps its `()` result explicitly and the frontend contract is unchanged.
This commit is contained in:
@@ -117,13 +117,8 @@ fn delete(ctx: &CliContext, id: &str, yes: bool) -> CommandResult {
|
||||
println!("Aborted");
|
||||
return Ok(());
|
||||
}
|
||||
// The delete helpers return no count, so take one first to report honestly.
|
||||
let count = ctx
|
||||
.db()
|
||||
.list_http_responses_for_request(id, None)
|
||||
.map_err(|e| format!("Failed to list responses: {e}"))?
|
||||
.len();
|
||||
ctx.db()
|
||||
.delete_all_http_responses_for_request(id, &UpdateSource::Sync)
|
||||
.map_err(|e| format!("Failed to delete responses: {e}"))?;
|
||||
println!("Deleted {count} responses for request {id}");
|
||||
@@ -137,10 +132,6 @@ fn delete(ctx: &CliContext, id: &str, yes: bool) -> CommandResult {
|
||||
}
|
||||
let count = ctx
|
||||
.db()
|
||||
.list_http_responses(&workspace_id, None)
|
||||
.map_err(|e| format!("Failed to list responses: {e}"))?
|
||||
.len();
|
||||
ctx.db()
|
||||
.delete_all_http_responses_for_workspace(&workspace_id, &UpdateSource::Sync)
|
||||
.map_err(|e| format!("Failed to delete responses: {e}"))?;
|
||||
println!("Deleted {count} responses for workspace {workspace_id}");
|
||||
|
||||
@@ -1630,10 +1630,11 @@ async fn cmd_delete_all_http_responses<R: Runtime>(
|
||||
app_handle: AppHandle<R>,
|
||||
window: WebviewWindow<R>,
|
||||
) -> YaakResult<()> {
|
||||
Ok(app_handle.db().delete_all_http_responses_for_request(
|
||||
app_handle.db().delete_all_http_responses_for_request(
|
||||
request_id,
|
||||
&UpdateSource::from_window_label(window.label()),
|
||||
)?)
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -30,29 +30,33 @@ impl<'a> ClientDb<'a> {
|
||||
self.find_many(HttpResponseIden::WorkspaceId, workspace_id, limit)
|
||||
}
|
||||
|
||||
/// Returns the number of responses deleted.
|
||||
pub fn delete_all_http_responses_for_request(
|
||||
&self,
|
||||
request_id: &str,
|
||||
source: &UpdateSource,
|
||||
) -> Result<()> {
|
||||
) -> Result<usize> {
|
||||
let responses = self.list_http_responses_for_request(request_id, None)?;
|
||||
let count = responses.len();
|
||||
for m in responses {
|
||||
self.delete(&m, source)?;
|
||||
}
|
||||
Ok(())
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
/// Returns the number of responses deleted.
|
||||
pub fn delete_all_http_responses_for_workspace(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
source: &UpdateSource,
|
||||
) -> Result<()> {
|
||||
) -> Result<usize> {
|
||||
let responses =
|
||||
self.find_many::<HttpResponse>(HttpResponseIden::WorkspaceId, workspace_id, None)?;
|
||||
let count = responses.len();
|
||||
for m in responses {
|
||||
self.delete(&m, source)?;
|
||||
}
|
||||
Ok(())
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
pub fn delete_http_response(
|
||||
|
||||
Reference in New Issue
Block a user