rename request_handler to request_selector
This commit is contained in:
parent
ce8f6e3b96
commit
4fa190effa
|
@ -1,42 +0,0 @@
|
|||
use crate::chat::types::SP;
|
||||
use rusqlite;
|
||||
|
||||
use super::request::*;
|
||||
use async_std::io::Result;
|
||||
use rusqlite::Connection;
|
||||
use serde_json::from_str;
|
||||
use serde_json::json;
|
||||
// server_sender sending data to server thread;
|
||||
pub async fn request_handler(json: String, server_sender: &SP, conn: &Connection) -> Result<()> {
|
||||
// if let Ok(res) = from_str::<CreateInstanceReq>(&json) {
|
||||
//TODO v0.3 Add Instances return Ok(());
|
||||
// }
|
||||
|
||||
if let Ok(res) = from_str::<StartAppReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<StopAppReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<LoadUsersReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<SendMessageReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<LoadMessagesReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<AddUserReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
Err(async_std::io::Error::new(
|
||||
async_std::io::ErrorKind::InvalidData,
|
||||
"Wrong request",
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_making_correct_jsons() {
|
||||
let json = from_str::<StopApp>("{\"req_type\":\"StartAppReq\"}").unwrap();
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod request;
|
||||
pub mod response;
|
||||
pub mod handlers;
|
||||
pub mod selector;
|
||||
|
|
42
src/api/selector.rs
Normal file
42
src/api/selector.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use crate::chat::types::SP;
|
||||
use rusqlite;
|
||||
|
||||
use super::request::*;
|
||||
use async_std::io::Result;
|
||||
use rusqlite::Connection;
|
||||
use serde_json::from_str;
|
||||
use serde_json::json;
|
||||
// server_sender sending data to server thread;
|
||||
pub async fn request_selector(json: String, server_sender: &SP, conn: &Connection) -> Result<()> {
|
||||
// if let Ok(res) = from_str::<CreateInstanceReq>(&json) {
|
||||
//TODO v0.3 Add Instances return Ok(());
|
||||
// }
|
||||
|
||||
if let Ok(res) = from_str::<StartAppReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<StopAppReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<LoadUsersReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<SendMessageReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<LoadMessagesReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(res) = from_str::<AddUserReq>(&json) {
|
||||
return Ok(());
|
||||
}
|
||||
Err(async_std::io::Error::new(
|
||||
async_std::io::ErrorKind::InvalidData,
|
||||
"Wrong request",
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_making_correct_jsons() {
|
||||
let json = from_str::<StopApp>("{\"req_type\":\"StartAppReq\"}").unwrap();
|
||||
}
|
|
@ -18,7 +18,7 @@ use super::stay_awake::request_repeater;
|
|||
|
||||
use super::types::{RP, SP};
|
||||
|
||||
use crate::api::handlers::request_handler;
|
||||
use crate::api::selector::request_selector;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct FrontMsg {
|
||||
|
@ -101,7 +101,7 @@ async fn connection_for_sending(
|
|||
loop {
|
||||
if let Some(msg) = new_msg.await {
|
||||
let jsoned = msg.expect("Falied to unwrap gotted message");
|
||||
request_handler(jsoned.to_string(), &server_sender, &conn);
|
||||
request_selector(jsoned.to_string(), &server_sender, &conn);
|
||||
/*
|
||||
let res: serde_json::Result<FrontMsg> =
|
||||
serde_json::from_str(jsoned.to_text().expect("Falied to parse JSON"));
|
||||
|
|
Loading…
Reference in a new issue