Skip to content

Commit 08f823c

Browse files
committed
Add event RPC mappings
1 parent 248f122 commit 08f823c

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/command/event.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

src/command/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod admin;
22
pub mod area;
33
pub mod common;
44
pub mod element;
5+
pub mod event;
56
pub mod report;
67
pub mod setup;
78
pub mod user;

src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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

104109
type 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

0 commit comments

Comments
 (0)