Skip to content

Commit

Permalink
bin/tau: rename update() to modify()
Browse files Browse the repository at this point in the history
  • Loading branch information
Dastan-glitch committed Sep 22, 2023
1 parent a13b5f3 commit 343c319
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/tau/tau-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ fn main() -> Result<()> {
let base_task = task_from_cli(values)?;
for id in ids_clone {
let task = tasks_local_id.get(&(id as usize)).unwrap();
let res = tau.update(&task.ref_id, base_task.clone()).await?;
let res = tau.modify(&task.ref_id, base_task.clone()).await?;
if res {
let tsk = tau.get_task_by_ref_id(&task.ref_id).await?;
print_task_info(id as usize, tsk)?;
Expand Down
6 changes: 3 additions & 3 deletions bin/tau/tau-cli/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl Tau {
Ok(ret)
}

/// Update existing task given it's ID and some params.
pub async fn update(&self, ref_id: &str, task: BaseTask) -> Result<bool> {
/// modify existing task given it's ID and some params.
pub async fn modify(&self, ref_id: &str, task: BaseTask) -> Result<bool> {
let mut params = HashMap::new();

let map = |x: &String| JsonValue::String(x.clone().to_owned());
Expand All @@ -98,7 +98,7 @@ impl Tau {
params.insert("rank".into(), rank);

let req = JsonRequest::new(
"update",
"modify",
vec![JsonValue::String(ref_id.into()), JsonValue::Object(params)],
);
let rep = self.rpc_client.request(req).await?;
Expand Down
14 changes: 7 additions & 7 deletions bin/tau/taud/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl RequestHandler for JsonRpcInterface {
let rep = match req.method.as_str() {
"add" => self.add(req.params).await,
"get_ref_ids" => self.get_ref_ids(req.params).await,
"update" => self.update(req.params).await,
"modify" => self.modify(req.params).await,
"set_state" => self.set_state(req.params).await,
"set_comment" => self.set_comment(req.params).await,
"get_task_by_ref_id" => self.get_task_by_ref_id(req.params).await,
Expand Down Expand Up @@ -279,20 +279,20 @@ impl JsonRpcInterface {
}

// RPCAPI:
// Update task and returns `true` upon success.
// --> {"jsonrpc": "2.0", "method": "update", "params": [task_id, {"title": "new title"} ], "id": 1}
// Modify task and returns `true` upon success.
// --> {"jsonrpc": "2.0", "method": "modify", "params": [task_id, {"title": "new title"} ], "id": 1}
// <-- {"jsonrpc": "2.0", "result": true, "id": 1}
async fn update(&self, params: JsonValue) -> TaudResult<JsonValue> {
async fn modify(&self, params: JsonValue) -> TaudResult<JsonValue> {
let params = params.get::<Vec<JsonValue>>().unwrap();
debug!(target: "tau", "JsonRpc::update() params {:?}", params);
debug!(target: "tau", "JsonRpc::modify() params {:?}", params);

if params.len() != 2 || !params[0].is_string() || !params[1].is_object() {
return Err(TaudError::InvalidData("len of params should be 2".into()))
}

let ws = self.workspace.lock().await.clone();

let task = self.check_params_for_update(
let task = self.check_params_for_modify(
params[0].get::<String>().unwrap(),
params[1].get::<HashMap<String, JsonValue>>().unwrap(),
ws,
Expand Down Expand Up @@ -524,7 +524,7 @@ impl JsonRpcInterface {
task.ok_or(TaudError::InvalidId)
}

fn check_params_for_update(
fn check_params_for_modify(
&self,
task_ref_id: &str,
fields: &HashMap<String, JsonValue>,
Expand Down

0 comments on commit 343c319

Please sign in to comment.