@@ -4,80 +4,63 @@ use diesel::prelude::*;
4
4
5
5
/// Remove a key value pair from the tags.
6
6
pub fn delete ( args : Args ) -> Result < ( ) , Error > {
7
- if api:: is_wg_and_teams ( & args) ? {
8
- let conn = DB . get ( ) ?;
9
- let key = args
10
- . params
11
- . get ( "key" )
12
- . ok_or ( "Unable to retrieve param: key" ) ?;
13
-
14
- match diesel:: delete ( tags:: table. filter ( tags:: key. eq ( key) ) ) . execute ( & conn) {
15
- Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
16
- Err ( _) => api:: send_reply ( & args, "A database error occurred when deleting the tag." ) ?,
17
- }
7
+ let conn = DB . get ( ) ?;
8
+ let key = args
9
+ . params
10
+ . get ( "key" )
11
+ . ok_or ( "Unable to retrieve param: key" ) ?;
12
+
13
+ match diesel:: delete ( tags:: table. filter ( tags:: key. eq ( key) ) ) . execute ( & conn) {
14
+ Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
15
+ Err ( _) => api:: send_reply ( & args, "A database error occurred when deleting the tag." ) ?,
18
16
}
19
17
Ok ( ( ) )
20
18
}
21
19
22
20
/// Add a key value pair to the tags.
23
21
pub fn post ( args : Args ) -> Result < ( ) , Error > {
24
- if api:: is_wg_and_teams ( & args) ? {
25
- let conn = DB . get ( ) ?;
26
-
27
- let key = args
28
- . params
29
- . get ( "key" )
30
- . ok_or ( "Unable to retrieve param: key" ) ?;
31
-
32
- let value = args
33
- . params
34
- . get ( "value" )
35
- . ok_or ( "Unable to retrieve param: value" ) ?;
36
-
37
- match diesel:: insert_into ( tags:: table)
38
- . values ( ( tags:: key. eq ( key) , tags:: value. eq ( value) ) )
39
- . execute ( & conn)
40
- {
41
- Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
42
- Err ( _) => api:: send_reply ( & args, "A database error occurred when creating the tag." ) ?,
43
- }
44
- } else {
45
- api:: send_reply (
46
- & args,
47
- "Please reach out to a Rust team/WG member to create a tag." ,
48
- ) ?;
49
- }
22
+ let conn = DB . get ( ) ?;
50
23
24
+ let key = args
25
+ . params
26
+ . get ( "key" )
27
+ . ok_or ( "Unable to retrieve param: key" ) ?;
28
+
29
+ let value = args
30
+ . params
31
+ . get ( "value" )
32
+ . ok_or ( "Unable to retrieve param: value" ) ?;
33
+
34
+ match diesel:: insert_into ( tags:: table)
35
+ . values ( ( tags:: key. eq ( key) , tags:: value. eq ( value) ) )
36
+ . execute ( & conn)
37
+ {
38
+ Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
39
+ Err ( _) => api:: send_reply ( & args, "A database error occurred when creating the tag." ) ?,
40
+ }
51
41
Ok ( ( ) )
52
42
}
53
43
54
44
/// Update an existing tag.
55
45
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
- ) ?;
46
+ let conn = DB . get ( ) ?;
47
+
48
+ let key = args
49
+ . params
50
+ . get ( "key" )
51
+ . ok_or ( "Unable to retrieve param: key" ) ?;
52
+
53
+ let value = args
54
+ . params
55
+ . get ( "value" )
56
+ . ok_or ( "Unable to retrieve param: value" ) ?;
57
+
58
+ match diesel:: update ( tags:: table. filter ( tags:: key. eq ( key) ) )
59
+ . set ( tags:: value. eq ( value) )
60
+ . execute ( & conn)
61
+ {
62
+ Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
63
+ Err ( _) => api:: send_reply ( & args, "A database error occurred when updating the tag." ) ?,
81
64
}
82
65
83
66
Ok ( ( ) )
0 commit comments