parent
3c538b44ac
commit
0908660fc9
5 changed files with 100 additions and 13 deletions
@ -0,0 +1,37 @@ |
|||||||
|
use u_lib::contracts::*; |
||||||
|
use warp::{ |
||||||
|
Rejection, |
||||||
|
Reply, |
||||||
|
}; |
||||||
|
|
||||||
|
pub async fn add_client( |
||||||
|
msg: Message<'_, ClientInfo>, |
||||||
|
db: Storage) -> Result<impl Reply, Rejection> |
||||||
|
{ |
||||||
|
let new_cli = msg.item; |
||||||
|
let mut clients = db.lock().await; |
||||||
|
if clients.contains_key(&new_cli.id) { |
||||||
|
Ok(warp::reply::json( |
||||||
|
&RawMsg("Already exist".to_string()).into_message() |
||||||
|
)) |
||||||
|
} else { |
||||||
|
clients.insert( |
||||||
|
new_cli.id.clone(), |
||||||
|
UClient::new(new_cli.into_owned()) |
||||||
|
); |
||||||
|
Ok(warp::reply::json( |
||||||
|
&RawMsg("Added".to_string()).into_message() |
||||||
|
)) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
pub async fn listing(db: Storage) -> Result<impl Reply, Rejection> { |
||||||
|
let clients = db.lock().await; |
||||||
|
let mut result: Vec<ClientInfo> = Vec::with_capacity(clients.len()); |
||||||
|
for cli in clients.values() { |
||||||
|
result.push(cli.client_info.clone()); |
||||||
|
} |
||||||
|
Ok(warp::reply::json( |
||||||
|
&Message::new_owned(result) |
||||||
|
)) |
||||||
|
} |
Loading…
Reference in new issue