File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ use crate :: {
2+ rpc:: { self } ,
3+ Result ,
4+ } ;
5+ use clap:: Args ;
6+ use serde_json:: { json, Map , Value } ;
7+
8+ #[ derive( Args ) ]
9+ pub struct CreateEventArgs {
10+ pub lat : i64 ,
11+ pub lon : i64 ,
12+ pub name : String ,
13+ pub website : String ,
14+ pub starts_at : String ,
15+ pub ends_at : Option < String > ,
16+ }
17+
18+ pub fn create_event ( args : & CreateEventArgs ) -> Result < ( ) > {
19+ let params = json ! ( {
20+ "lat" : args. lat,
21+ "lon" : args. lon,
22+ "name" : args. name,
23+ "website" : args. website,
24+ "starts_at" : args. starts_at,
25+ "ends_at" : args. ends_at
26+ } ) ;
27+ rpc:: call ( "create_event" , params) ?. print ( )
28+ }
29+
30+ pub fn get_events ( ) -> Result < ( ) > {
31+ rpc:: call ( "get_events" , Value :: Object ( Map :: new ( ) ) ) ?. print ( )
32+ }
33+
34+ #[ derive( Args ) ]
35+ pub struct GetEventArgs {
36+ pub id : i64 ,
37+ }
38+
39+ pub fn get_event ( args : & GetEventArgs ) -> Result < ( ) > {
40+ rpc:: call ( "get_event" , json ! ( { "id" : args. id} ) ) ?. print ( )
41+ }
42+
43+ #[ derive( Args ) ]
44+ pub struct DeleteEventArgs {
45+ pub id : i64 ,
46+ }
47+
48+ pub fn delete_event ( args : & DeleteEventArgs ) -> Result < ( ) > {
49+ rpc:: call ( "delete_event" , json ! ( { "id" : args. id} ) ) ?. print ( )
50+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ pub mod admin;
22pub mod area;
33pub mod common;
44pub mod element;
5+ pub mod event;
56pub mod report;
67pub mod setup;
78pub mod user;
Original file line number Diff line number Diff line change @@ -99,6 +99,11 @@ enum Commands {
9999
100100 /// Custom RPC
101101 RPC ( command:: common:: CustomArgs ) ,
102+
103+ CreateEvent ( command:: event:: CreateEventArgs ) ,
104+ GetEvents ,
105+ GetEvent ( command:: event:: GetEventArgs ) ,
106+ DeleteEvent ( command:: event:: DeleteEventArgs ) ,
102107}
103108
104109type Result < T > = std:: result:: Result < T , Box < dyn Error > > ;
@@ -191,6 +196,10 @@ fn main() -> Result<()> {
191196 }
192197 // common
193198 Commands :: RPC ( args) => command:: common:: rpc ( args) ,
199+ Commands :: CreateEvent ( args) => command:: event:: create_event ( args) ,
200+ Commands :: GetEvents => command:: event:: get_events ( ) ,
201+ Commands :: GetEvent ( args) => command:: event:: get_event ( args) ,
202+ Commands :: DeleteEvent ( args) => command:: event:: delete_event ( args) ,
194203 }
195204}
196205
You can’t perform that action at this time.
0 commit comments