|
|
@ -21,20 +21,6 @@ use uuid::Uuid; |
|
|
|
|
|
|
|
|
|
|
|
pub struct Paths; |
|
|
|
pub struct Paths; |
|
|
|
|
|
|
|
|
|
|
|
#[macro_export] |
|
|
|
|
|
|
|
macro_rules! get_result { |
|
|
|
|
|
|
|
( () ) => ( |_| async Ok(()) ); |
|
|
|
|
|
|
|
( $result:ty ) => { |
|
|
|
|
|
|
|
|response: Response| async { |
|
|
|
|
|
|
|
response |
|
|
|
|
|
|
|
.json::<BaseMessage<$result>>() |
|
|
|
|
|
|
|
.await |
|
|
|
|
|
|
|
.map(|msg| msg.into_item()) |
|
|
|
|
|
|
|
.map_err(|e| UError::from(e)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[macro_export] |
|
|
|
#[macro_export] |
|
|
|
macro_rules! build_url_by_method { |
|
|
|
macro_rules! build_url_by_method { |
|
|
|
( |
|
|
|
( |
|
|
@ -80,22 +66,27 @@ macro_rules! build_url_by_method { |
|
|
|
macro_rules! build_handler { |
|
|
|
macro_rules! build_handler { |
|
|
|
( |
|
|
|
( |
|
|
|
$method:tt |
|
|
|
$method:tt |
|
|
|
$path:tt( |
|
|
|
$path:tt $( /$url_param:tt )? ( |
|
|
|
$( $param_name:literal: )? |
|
|
|
$( $param_name:literal: )? |
|
|
|
$( $param_type:ty )? |
|
|
|
$( $param_type:ty )? |
|
|
|
$(; $url_param:ty)? |
|
|
|
|
|
|
|
) -> $result:ty |
|
|
|
) -> $result:ty |
|
|
|
) => { |
|
|
|
) => { |
|
|
|
impl ClientHandler { |
|
|
|
impl ClientHandler { |
|
|
|
pub async fn $path( |
|
|
|
pub async fn $path( |
|
|
|
&self $(, param: &$param_type)? $(, url_param: &$url_param)? |
|
|
|
&self $(, param: &$param_type)? // $(, url_param: &$url_param)?
|
|
|
|
) -> UResult<$result> { |
|
|
|
) -> UResult<$result> { |
|
|
|
let request = $crate::build_url_by_method!( |
|
|
|
let request = $crate::build_url_by_method!( |
|
|
|
$method $path, |
|
|
|
$method $path, |
|
|
|
pname = $($param_name)?, ptype = $($param_type)?, urlparam = $($url_param)? |
|
|
|
pname = $($param_name)?, ptype = $($param_type)?, urlparam = $($url_param)? |
|
|
|
)(self $(, param as &$param_type)? ); |
|
|
|
)(self $(, param as &$param_type)? ); |
|
|
|
let response = request.send().await?; |
|
|
|
let response = request.send().await?; |
|
|
|
($crate::get_result!($result)(response)).await |
|
|
|
match response.error_for_status() { |
|
|
|
|
|
|
|
Ok(r) => r.json::<BaseMessage<$result>>() |
|
|
|
|
|
|
|
.await |
|
|
|
|
|
|
|
.map_err(|e| UError::from(e)) |
|
|
|
|
|
|
|
.map(|msg| msg.into_item()), |
|
|
|
|
|
|
|
Err(e) => Err(UError::from(e)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -148,19 +139,21 @@ impl ClientHandler { |
|
|
|
self.set_pwd(rb) |
|
|
|
self.set_pwd(rb) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// method basic_path(json/query param; additional_url_param) -> return value
|
|
|
|
// method basic_path(json/query param; additional_url_param) -> return value
|
|
|
|
// A - admin only
|
|
|
|
// A - admin only
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// client listing (A)
|
|
|
|
// client listing (A)
|
|
|
|
build_handler!(GET ls() -> Vec<Agent>); |
|
|
|
build_handler!(GET get_agents() -> Vec<Agent>); |
|
|
|
// get jobs for client himself (A: id=client_id)
|
|
|
|
// get jobs for client (agent_id=Uuid)
|
|
|
|
build_handler!(GET get_jobs() -> Vec<JobMeta>); |
|
|
|
build_handler!(GET get_jobs("agent_id":Uuid) -> Vec<JobMeta>); |
|
|
|
// add client to server's db
|
|
|
|
// add client to server's db
|
|
|
|
build_handler!(POST init(IAgent) -> RawMsg); |
|
|
|
build_handler!(POST init(IAgent) -> RawMsg); |
|
|
|
// create and upload job (A)
|
|
|
|
// create and upload job (A)
|
|
|
|
//build_handler!(POST upload_jobs)
|
|
|
|
build_handler!(POST add_jobs(Vec<JobMeta>) -> ()); |
|
|
|
// ???
|
|
|
|
// delete something (A)
|
|
|
|
/*build_handler!(POST del() -> ());
|
|
|
|
build_handler!(GET del/Uuid() -> ()); |
|
|
|
|
|
|
|
/* |
|
|
|
// set jobs for client (A)
|
|
|
|
// set jobs for client (A)
|
|
|
|
// POST /set_jobs/Uuid json: JobMetaStorage
|
|
|
|
// POST /set_jobs/Uuid json: JobMetaStorage
|
|
|
|
build_handler!(POST set_jobs(JobMetaStorage; Uuid) -> ()); |
|
|
|
build_handler!(POST set_jobs(JobMetaStorage; Uuid) -> ()); |
|
|
|