diff options
Diffstat (limited to 'angelsharkd/src/routes/dtos.rs')
-rw-r--r-- | angelsharkd/src/routes/dtos.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/angelsharkd/src/routes/dtos.rs b/angelsharkd/src/routes/dtos.rs new file mode 100644 index 0000000..fe3f184 --- /dev/null +++ b/angelsharkd/src/routes/dtos.rs @@ -0,0 +1,67 @@ +use libangelshark::Message; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Debug)] +pub struct Error { + pub reason: String, +} + +#[derive(Serialize, Debug)] +pub struct Version { + pub daemon_version: &'static str, +} + +#[derive(Deserialize, Debug)] +pub struct Query { + pub no_cache: Option<bool>, + pub panicky: Option<bool>, +} + +#[derive(Deserialize, Debug)] +pub struct Request { + pub acms: Vec<String>, + pub command: String, + pub fields: Option<Vec<String>>, + pub datas: Option<Vec<Vec<String>>>, +} + +impl From<Request> for Vec<(String, Message)> { + fn from(val: Request) -> Self { + val.acms + .iter() + .map(|name| { + ( + name.to_owned(), + Message { + command: val.command.clone(), + fields: val.fields.clone(), + datas: val.datas.clone(), + error: None, + }, + ) + }) + .collect() + } +} + +#[derive(Debug, Serialize)] +pub struct Response { + pub acm: String, + pub command: String, + pub error: String, + pub fields: Vec<String>, + pub datas: Vec<Vec<String>>, +} + +impl From<(String, Message)> for Response { + fn from(msg: (String, Message)) -> Self { + let (acm, msg) = msg; + Self { + acm, + command: msg.command, + fields: msg.fields.unwrap_or_default(), + datas: msg.datas.unwrap_or_default(), + error: msg.error.unwrap_or_default(), + } + } +} |