-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c035f8
commit 64fd036
Showing
9 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
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,2 +1,5 @@ | ||
pub mod new_session; | ||
pub use new_session::NewSession; | ||
|
||
pub mod session_history; | ||
pub use session_history::SessionHistory; |
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,15 @@ | ||
use chrono::NaiveDateTime; | ||
use serde::{Deserialize, Serialize}; | ||
use uuid::Uuid; | ||
|
||
use crate::data::enums::Country; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct SessionHistory { | ||
pub id: Uuid, | ||
pub device_id: Uuid, | ||
pub opened_at: NaiveDateTime, | ||
pub closed_at: NaiveDateTime, | ||
pub duration: i64, | ||
pub country: Country, | ||
} |
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,12 @@ | ||
use serde::Deserialize; | ||
use uuid::Uuid; | ||
|
||
use crate::data::enums::Country; | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct Params { | ||
pub limit: Option<i64>, | ||
pub offset: Option<i64>, | ||
pub countries: Option<Vec<Country>>, | ||
pub devices: Option<Vec<Uuid>>, | ||
} |
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,2 +1,5 @@ | ||
pub mod create_session; | ||
pub use create_session::CreateSession; | ||
|
||
pub mod get_history; | ||
pub use get_history::Params; |
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,26 @@ | ||
use axum::{extract::State, http::StatusCode}; | ||
use deadpool_diesel::postgres::Pool; | ||
use tracing::info; | ||
|
||
use crate::{ | ||
dto::{ | ||
auth::internal::AccessToken, | ||
response::success::Response, | ||
session::{internal::SessionHistory, request::Params}, | ||
}, | ||
enums::errors::external::ExternalError, | ||
extractors::Json, | ||
services::session_service, | ||
}; | ||
|
||
pub async fn get_history( | ||
claims: AccessToken, | ||
State(pool): State<Pool>, | ||
Json(payload): Json<Params>, | ||
) -> Result<Response<Vec<SessionHistory>>, ExternalError> { | ||
info!("Getting session history"); | ||
|
||
let history = session_service::get_history(&pool, &claims.user_id, &payload).await?; | ||
|
||
Ok(Response::new(StatusCode::OK, "Successfully got session history").with_data(history)) | ||
} |
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,15 +1,16 @@ | ||
use crate::{ | ||
handlers::session::{close_session, create_session}, | ||
handlers::session::{close_session, create_session, get_history}, | ||
AppState, | ||
}; | ||
use axum::{ | ||
routing::{post, put}, | ||
routing::{get, post, put}, | ||
Router, | ||
}; | ||
|
||
pub fn session_router(state: AppState) -> Router<AppState> { | ||
Router::new() | ||
.route("/", post(create_session)) | ||
.route("/", put(close_session)) | ||
.route("/history", get(get_history)) | ||
.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