zonegift/src/commands.rs

55 lines
1.2 KiB
Rust

use std::collections::HashMap;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Query {
pub command: Command,
pub method: Method,
pub args: Option<Args>,
pub params: Option<HashMap<String, String>>,
pub body: Option<String>
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum Args {
List(Vec<String>),
Map(HashMap<String, String>)
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all(serialize = "lowercase", deserialize = "lowercase"))]
pub enum Command {
Zone,
Profile,
Version,
Stats
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all(serialize = "UPPERCASE", deserialize = "UPPERCASE"))]
pub enum Method {
Get,
Post,
Put,
Delete,
}
pub fn version(query: Query) -> String {
"0.0.1".into()
}
pub fn zone(query: Query) -> String {
let target = query.args;
match query.method {
Method::Get => {
match target {
Some(z) => format!("TODO: Check if zone exists..."),
None => format!("TODO: list zones for the user")
}
},
_ => format!("unimplemented method for zone command")
}
}