split request_handler by unimplementend blocks

This commit is contained in:
Horhik 2021-03-26 21:49:08 +03:00
parent cc92837d64
commit ce8f6e3b96
2 changed files with 85 additions and 48 deletions

View file

@ -1,9 +1,42 @@
use rusqlite;
use crate::chat::types::SP; use crate::chat::types::SP;
use rusqlite;
use super::request::*;
use async_std::io::Result; use async_std::io::Result;
use rusqlite::Connection; use rusqlite::Connection;
use serde_json::from_str;
use serde_json::json;
// server_sender sending data to server thread; // server_sender sending data to server thread;
pub async fn request_handler(json: String, server_sender: &SP, conn: &Connection) -> Result<()> { pub async fn request_handler(json: String, server_sender: &SP, conn: &Connection) -> Result<()> {
unimplemented!() // 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();
} }

View file

@ -1,63 +1,67 @@
use fcpv2::types::SSK; use fcpv2::types::SSK;
use serde_json::Result;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use serde_json::Result;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Address { pub struct CreateInstance;
street: String,
city: String, #[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct SendMessage;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct LoadUsers;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct LoadMessages;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct AddUser;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct StartApp;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct StopApp;
#[derive(Deserialize, Debug)]
pub struct CreateInstanceReq {
pub req_type: CreateInstance,
pub name: String,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Deserialize, Debug, PartialEq)]
pub enum RequestType { pub struct StartAppReq {
CreateInstance, pub req_type: StartApp,
StartApp, }
StopApp,
SendMessage, #[derive(Deserialize, Debug, PartialEq)]
LoadUsers, pub struct StopAppReq {
LoadMessages, pub(crate) req_type: StopApp,
AddUser,
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct CreateInstance { pub struct LoadUsersReq {
req_type: RequestType, pub req_type: LoadUsers,
name: String,
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct StartApp { pub struct SendMessageReq {
req_type: RequestType, pub req_type: SendMessage,
pub user_id: u32,
pub message: String,
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct StopApp { pub struct LoadMessagesReq {
req_type: RequestType, pub req_type: LoadMessages,
} pub user_id: u32,
#[derive(Deserialize, Debug)] pub count: u8,
struct SendMessage { pub start_index: u8,
req_type: RequestType,
user_id: u32,
message: String,
}
#[derive(Deserialize, Debug)]
struct LoadUsers {
req_type: RequestType,
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct LoadMessages { pub struct AddUserReq {
req_type: RequestType, pub req_type: AddUser,
user_id: u32, pub sign_key: String,
count: u8, pub insert_key: String,
start_index: u8,
} }
#[derive(Deserialize, Debug)]
struct AddUser {
req_type: RequestType,
sign_key: String,
insert_key: String,
}