-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from Rajdip019/dashboard-setup
Dashboard setup
- Loading branch information
Showing
23 changed files
with
1,264 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ jsonwebtoken = "9.3.0" | |
openssl = "0.10.64" | ||
regex = "1.10.4" | ||
uuid = "1.8.0" | ||
woothee = "0.13.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod auth_handler; | ||
pub mod health_check_handler; | ||
pub mod overview_handler; | ||
pub mod password_handler; | ||
pub mod session_handler; | ||
pub mod user_handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use axum::{extract::State, Json}; | ||
use axum_macros::debug_handler; | ||
use bson::doc; | ||
use bson::DateTime; | ||
use woothee::parser::{Parser, WootheeResult}; | ||
|
||
use crate::core::session::Session; | ||
use crate::errors::Result; | ||
use crate::models::overview_model::OverviewResponse; | ||
use crate::{core::user::User, AppState}; | ||
|
||
#[debug_handler] | ||
pub async fn get_all_overview_handler( | ||
State(state): State<AppState>, | ||
) -> Result<Json<OverviewResponse>> { | ||
println!(">> HANDLER: get_all_overview_handler called"); | ||
|
||
let users = User::get_all(&state.mongo_client).await.unwrap(); | ||
let user_count = users.len(); | ||
let active_user_count = users.iter().filter(|u| u.is_active).count(); | ||
let inactive_user_count = users.iter().filter(|u| !u.is_active).count(); | ||
let blocked_user_count = users | ||
.iter() | ||
.filter(|u| u.blocked_until.map_or(false, |time| time > DateTime::now())) | ||
.count(); | ||
|
||
let all_sessions = Session::get_all(&state.mongo_client).await.unwrap(); | ||
println!(">> all_sessions Length: {:?}", all_sessions.len()); | ||
|
||
let active_session_count = all_sessions.iter().filter(|s| !s.is_revoked).count(); | ||
let revoked_session_count = all_sessions.iter().filter(|s| s.is_revoked).count(); | ||
|
||
// create a user-agent map from all_sessions where is_revoked = false | ||
let user_agents: Vec<String> = all_sessions | ||
.iter() | ||
.filter(|s| !s.is_revoked) | ||
.map(|s| s.user_agent.clone()) | ||
.collect(); | ||
|
||
println!(">> user_agents: {:?}", user_agents); | ||
|
||
let parser = Parser::new(); | ||
|
||
// find out os_types, device_types, browser_types from all_sessions using user-agent-parser | ||
let results: Vec<Option<WootheeResult>> = | ||
user_agents.iter().map(|ua| parser.parse(ua)).collect(); | ||
|
||
// get os_types as a string[] from results | ||
let os_types: Vec<String> = results | ||
.iter() | ||
.map(|r| { | ||
r.as_ref() | ||
.map_or_else(String::new, |result| result.os.to_string()) | ||
}) | ||
.collect(); | ||
|
||
// get device_types as a string[] from results | ||
let device_types: Vec<String> = results | ||
.iter() | ||
.map(|r| { | ||
r.as_ref() | ||
.map_or_else(String::new, |result| result.category.to_string()) | ||
}) | ||
.collect(); | ||
|
||
// get browser_types as a string[] from results | ||
let browser_types: Vec<String> = results | ||
.iter() | ||
.map(|r| { | ||
r.as_ref() | ||
.map_or_else(String::new, |result| result.name.to_string()) | ||
}) | ||
.collect(); | ||
|
||
println!(">> results USER AGENTSSS: {:?}", results); | ||
println!(">> os_types: {:?}", os_types); | ||
println!(">> device_types: {:?}", device_types); | ||
println!(">> browser_types: {:?}", browser_types); | ||
|
||
let response = OverviewResponse { | ||
user_count, | ||
active_user_count, | ||
inactive_user_count, | ||
blocked_user_count, | ||
revoked_session_count, | ||
active_session_count, | ||
os_types, | ||
device_types, | ||
browser_types, | ||
}; | ||
|
||
Ok(Json(response)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod auth_model; | ||
pub mod overview_model; | ||
pub mod password_model; | ||
pub mod session_model; | ||
pub mod user_model; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct OverviewResponse { | ||
pub user_count: usize, | ||
pub active_user_count: usize, | ||
pub inactive_user_count: usize, | ||
pub blocked_user_count: usize, | ||
pub revoked_session_count: usize, | ||
pub active_session_count: usize, | ||
pub os_types: Vec<String>, | ||
pub device_types: Vec<String>, | ||
pub browser_types: Vec<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod auth_routes; | ||
pub mod health_check_routes; | ||
pub mod overview_routes; | ||
pub mod password_routes; | ||
pub mod session_routes; | ||
pub mod user_routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use axum::{extract::State, routing::get, Router}; | ||
|
||
use crate::{handlers::overview_handler::get_all_overview_handler, AppState}; | ||
|
||
pub fn routes(State(state): State<AppState>) -> Router { | ||
let overview_routes = Router::new().route("/get-all", get(get_all_overview_handler)); | ||
|
||
Router::new() | ||
.nest("/overview", overview_routes) | ||
.with_state(state) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export async function GET(req: Request) { | ||
const endPoint: (string | undefined) = `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/overview/get-all` | ||
|
||
if (endPoint) { | ||
try { | ||
const res = await fetch(endPoint, { | ||
headers: { | ||
'Content-Type': 'application/json', // Set the appropriate content type for your request | ||
'x-api-key': process.env.X_API_KEY!, | ||
}, | ||
cache: 'no-cache', | ||
}); | ||
const data = await res.json(); | ||
return Response.json({ data }) | ||
} catch (error) { | ||
console.error('Error during request:', error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.