Skip to content

Commit

Permalink
feat: removed utils and moved getting path to jarouter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghamza-Jd committed Jan 31, 2024
1 parent 549555b commit 7fe963b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
6 changes: 2 additions & 4 deletions jarust/src/jaconnection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use crate::prelude::*;
use crate::tmanager::TransactionManager;
use crate::transport::trans::Transport;
use crate::transport::trans::TransportProtocol;
use crate::utils::get_route_path_from_request;
use crate::utils::get_route_path_from_response;
use serde_json::json;
use serde_json::Value;
use std::collections::HashMap;
Expand Down Expand Up @@ -86,7 +84,7 @@ impl JaConnection {
}

// Try get the route from the response
if let Some(path) = get_route_path_from_response(message.clone()) {
if let Some(path) = JaRouter::path_from_response(message.clone()) {
router.pub_subroute(&path, message).await?;
continue;
}
Expand Down Expand Up @@ -206,7 +204,7 @@ impl JaConnection {
};

let path =
get_route_path_from_request(&request).unwrap_or(self.shared.config.namespace.clone());
JaRouter::path_from_request(&request).unwrap_or(self.shared.config.namespace.clone());

let mut guard = self.exclusive.lock().await;
guard
Expand Down
24 changes: 24 additions & 0 deletions jarust/src/jarouter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::jaconfig::CHANNEL_BUFFER_SIZE;
use crate::japrotocol::JaResponse;
use crate::prelude::*;
use serde_json::Value;
use std::collections::HashMap;
use std::ops::Deref;
use std::ops::DerefMut;
Expand Down Expand Up @@ -109,6 +110,29 @@ impl JaRouter {
pub fn root_path(&self) -> String {
self.shared.root_path.clone()
}

pub fn path_from_request(request: &Value) -> Option<String> {
if let (Some(session_id), Some(handle_id)) = (
request["session_id"].as_u64(),
request["handle_id"].as_u64(),
) {
Some(format!("{session_id}/{handle_id}"))
} else {
request["session_id"]
.as_u64()
.map(|session_id| format!("{session_id}"))
}
}

pub fn path_from_response(response: JaResponse) -> Option<String> {
let Some(session_id) = response.session_id else {
return None;
};
let Some(sender) = response.sender else {
return Some(format!("{session_id}"));
};
Some(format!("{session_id}/{sender}"))
}
}

#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion jarust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod transport;

mod jarouter;
mod tmanager;
mod utils;

use crate::transport::trans::Transport;
use jaconfig::JaConfig;
Expand Down
25 changes: 0 additions & 25 deletions jarust/src/utils.rs

This file was deleted.

0 comments on commit 7fe963b

Please sign in to comment.