From 3001493462645cb95d4279e5349744f7592f1f10 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Fri, 20 Sep 2024 19:35:15 +0200 Subject: [PATCH] Updated CLI deserialization format (closes #360 closes #553) --- crates/cli/src/modules/database.rs | 34 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/crates/cli/src/modules/database.rs b/crates/cli/src/modules/database.rs index 3ba06598..b9ec0846 100644 --- a/crates/cli/src/modules/database.rs +++ b/crates/cli/src/modules/database.rs @@ -14,6 +14,22 @@ use crate::modules::Response; use super::cli::{Client, ServerCommands}; +#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[serde(tag = "type")] +pub enum UpdateSettings { + Delete { + keys: Vec, + }, + Clear { + prefix: String, + }, + Insert { + prefix: Option, + values: Vec<(String, String)>, + assert_empty: bool, + }, +} + impl ServerCommands { pub async fn exec(self, client: Client) { match self { @@ -40,17 +56,23 @@ impl ServerCommands { .http_request::( Method::POST, "/api/settings", - Some(vec![(key.clone(), value.unwrap_or_default())]), + Some(vec![UpdateSettings::Insert { + prefix: None, + values: vec![(key.clone(), value.unwrap_or_default())], + assert_empty: false, + }]), ) .await; eprintln!("Successfully added key {key}."); } ServerCommands::DeleteConfig { key } => { client - .http_request::( - Method::DELETE, - &format!("/api/settings/{key}"), - None, + .http_request::( + Method::POST, + "/api/settings", + Some(vec![UpdateSettings::Delete { + keys: vec![key.clone()], + }]), ) .await; eprintln!("Successfully deleted key {key}."); @@ -59,7 +81,7 @@ impl ServerCommands { let results = client .http_request::>, String>( Method::GET, - &format!("/api/settings/list/{}", prefix.unwrap_or_default()), + &format!("/api/settings/list?prefix={}", prefix.unwrap_or_default()), None, ) .await