-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e0b318
commit 460381a
Showing
6 changed files
with
101 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
use clap::Parser; | ||
use mindmap::db::get_client; | ||
|
||
#[derive(Parser)] | ||
pub struct Args {} | ||
pub struct Args { | ||
#[clap(long)] | ||
description: String, | ||
} | ||
|
||
pub async fn command(args: &Args) { | ||
|
||
let description = args.description.clone(); | ||
|
||
let client = get_client().await.expect("Failed to fetch client"); | ||
client.execute("DELETE FROM todo WHERE description = $1", &[&description],).await.expect("Failed to delete task"); | ||
|
||
pub fn command(_args: &Args) { | ||
println!("Deleted task successfully!") | ||
println!("Task \"{}\" deleted successfully!", description); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
use chrono::Local; | ||
use clap::Parser; | ||
use mindmap::db::get_client; | ||
|
||
#[derive(Parser)] | ||
pub struct Args {} | ||
|
||
pub fn command(_args: &Args) { | ||
println!("Tasks due today:"); | ||
pub async fn command(_args: &Args) { | ||
|
||
let client = get_client().await.expect("Failed to fetch client"); | ||
let today = Local::now().date_naive(); | ||
let rows = client.query("SELECT description, priority, deadline FROM todo WHERE DATE(deadline) = $1::date", &[&today]).await.expect("Failed to fetch tasks"); | ||
|
||
for row in rows { | ||
let description: String = row.get(0); | ||
let priority: mindmap::Priority = row.get(1); | ||
let deadline: chrono::NaiveDateTime = row.get(2); | ||
|
||
println!("Task: {}", description); | ||
println!("Priority: {:?}", priority); | ||
println!("Deadline: {}", deadline); | ||
println!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
use chrono::NaiveDateTime; | ||
use clap::Parser; | ||
use mindmap::Priority; | ||
|
||
#[derive(Parser)] | ||
pub struct Args {} | ||
pub struct Args { | ||
#[clap(long)] | ||
description: String, | ||
#[clap(long)] | ||
new_description: String, | ||
#[clap(long)] | ||
new_priority: Priority, | ||
#[clap(long, value_parser=mindmap::parse_datetime)] | ||
new_deadline: NaiveDateTime, | ||
} | ||
|
||
pub async fn command(_args: &Args) { | ||
|
||
let client = mindmap::db::get_client().await.expect("Failed to fetch client"); | ||
|
||
let rows = client.query("SELECT description, priority, deadline FROM todo WHERE description = $1", &[&_args.description]).await.expect("Failed to fetch task"); | ||
|
||
if rows.is_empty() { | ||
println!("Task not found!"); | ||
return; | ||
} | ||
|
||
let description = _args.description.clone(); | ||
let new_description = _args.new_description.clone(); | ||
let new_priority = _args.new_priority.clone(); | ||
let new_deadline = _args.new_deadline; | ||
|
||
client.execute( | ||
"UPDATE todo SET description = $1, priority = $2, deadline = $3 WHERE description = $4", | ||
&[&new_description, &new_priority, &new_deadline, &description], | ||
).await.expect("Failed to update task"); | ||
|
||
pub fn command(_args: &Args) { | ||
println!("Updated task successfully!") | ||
println!("Task updated successfully!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters