Skip to content

Commit 1a0ef4a

Browse files
committed
Add update command to tags
1 parent 8e949e6 commit 1a0ef4a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ fn app() -> Result<(), Error> {
101101
tags::post,
102102
api::is_wg_and_teams,
103103
);
104+
cmds.add_protected(
105+
"?tags update {key} value...",
106+
tags::update,
107+
api::is_wg_and_teams,
108+
);
104109
cmds.add("?tag {key}", tags::get);
105110
cmds.add("?tags", tags::get_all);
106111
cmds.help("?tags", "A key value store", tags::help);

src/tags.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ pub fn post(args: Args) -> Result<(), Error> {
5151
Ok(())
5252
}
5353

54+
/// Update an existing tag.
55+
pub fn update(args: Args) -> Result<(), Error> {
56+
if api::is_wg_and_teams(&args)? {
57+
let conn = DB.get()?;
58+
59+
let key = args
60+
.params
61+
.get("key")
62+
.ok_or("Unable to retrieve param: key")?;
63+
64+
let value = args
65+
.params
66+
.get("value")
67+
.ok_or("Unable to retrieve param: value")?;
68+
69+
match diesel::update(tags::table.filter(tags::key.eq(key)))
70+
.set(tags::value.eq(value))
71+
.execute(&conn)
72+
{
73+
Ok(_) => args.msg.react(args.cx, "✅")?,
74+
Err(_) => api::send_reply(&args, "A database error occurred when updating the tag.")?,
75+
}
76+
} else {
77+
api::send_reply(
78+
&args,
79+
"Please reach out to a Rust team/WG member to update a tag.",
80+
)?;
81+
}
82+
83+
Ok(())
84+
}
85+
5486
/// Retrieve a value by key from the tags.
5587
pub fn get(args: Args) -> Result<(), Error> {
5688
let conn = DB.get()?;
@@ -97,6 +129,7 @@ pub fn get_all(args: Args) -> Result<(), Error> {
97129
pub fn help(args: Args) -> Result<(), Error> {
98130
let help_string = "```
99131
?tags create {key} value... Create a tag. Limited to WG & Teams.
132+
?tags update {key} value... Update a tag. Limited to WG & Teams.
100133
?tags delete {key} Delete a tag. Limited to WG & Teams.
101134
?tags help This menu.
102135
?tags Get all the tags.

0 commit comments

Comments
 (0)