Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sabotack committed Nov 13, 2023
1 parent 6717189 commit fb1536c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
48 changes: 27 additions & 21 deletions src/api/ecdar_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::entities::access;
use crate::entities::session::Model;
use chrono::Local;
use regex::Regex;
use sea_orm::prelude::{TimeTime, Uuid};

Check warning on line 10 in src/api/ecdar_api.rs

View workflow job for this annotation

GitHub Actions / Clippy lint and check

unused imports: `TimeTime`, `Uuid`

warning: unused imports: `TimeTime`, `Uuid` --> src/api/ecdar_api.rs:10:24 | 10 | use sea_orm::prelude::{TimeTime, Uuid}; | ^^^^^^^^ ^^^^

Check warning on line 10 in src/api/ecdar_api.rs

View workflow job for this annotation

GitHub Actions / Clippy lint and check

unused imports: `TimeTime`, `Uuid`

warning: unused imports: `TimeTime`, `Uuid` --> src/api/ecdar_api.rs:10:24 | 10 | use sea_orm::prelude::{TimeTime, Uuid}; | ^^^^^^^^ ^^^^
use sea_orm::SqlErr;
use sea_orm::prelude::{Uuid, TimeTime};
use tonic::{Code, Request, Response, Status};

use crate::api::server::server::{
Expand Down Expand Up @@ -209,23 +209,29 @@ impl EcdarApi for ConcreteEcdarApi {
}

async fn handle_session(
session_context: Arc<dyn SessionContextTrait>,
session_context: Arc<dyn SessionContextTrait>,
request: &Request<GetAuthTokenRequest>,
is_new_session: bool,
access_token: String,
refresh_token: String,
uid: String,
uid: String,
) -> Result<(), Status> {
if is_new_session {
session_context.create(Model {
id: Default::default(),
access_token: access_token.clone(),
refresh_token: refresh_token.clone(),
updated_at: Local::now().naive_local(),
user_id: uid.parse().unwrap(),
}).await.unwrap();
session_context
.create(Model {
id: Default::default(),
access_token: access_token.clone(),
refresh_token: refresh_token.clone(),
updated_at: Local::now().naive_local(),
user_id: uid.parse().unwrap(),
})
.await
.unwrap();
} else {
let mut session = match session_context.get_by_refresh_token(auth::get_token_from_request(request)?).await {
let mut session = match session_context
.get_by_refresh_token(auth::get_token_from_request(request)?)
.await
{
Ok(Some(session)) => session,
Ok(None) => {
return Err(Status::new(
Expand All @@ -245,7 +251,7 @@ async fn handle_session(
Err(err) => return Err(Status::new(Code::Internal, err.to_string())),
};
}
Ok(())
Ok(())
}

#[tonic::async_trait]
Expand Down Expand Up @@ -297,7 +303,6 @@ impl EcdarApiAuth for ConcreteEcdarApi {
uid = user_from_db.id.to_string();

is_new_session = true;

} else {
return Err(Status::new(Code::Internal, "No user provided"));
}
Expand All @@ -317,15 +322,16 @@ impl EcdarApiAuth for ConcreteEcdarApi {
Ok(token) => token.to_owned(),
Err(e) => return Err(Status::new(Code::Internal, e.to_string())),
};

handle_session(
self.session_context.clone(),
&request,
is_new_session,
access_token.clone(),
refresh_token.clone(),
uid
).await?;
self.session_context.clone(),
&request,
is_new_session,
access_token.clone(),
refresh_token.clone(),
uid,
)
.await?;

Ok(Response::new(GetAuthTokenResponse {
access_token,
Expand Down
4 changes: 2 additions & 2 deletions src/database/session_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::fmt::Debug;

use sea_orm::prelude::async_trait::async_trait;
use sea_orm::ActiveValue::{Set, Unchanged};
use sea_orm::{ActiveModelTrait, DbErr, EntityTrait, QueryFilter, ColumnTrait};
use sea_orm::{ActiveModelTrait, ColumnTrait, DbErr, EntityTrait, QueryFilter};

use crate::database::database_context::DatabaseContextTrait;
use crate::database::entity_context::EntityContextTrait;
use crate::entities::prelude::Session as SessionEntity;
use crate::entities::session::{ActiveModel, Model as Session};
use crate::entities::session::Column as SessionColumn;
use crate::entities::session::{ActiveModel, Model as Session};

#[derive(Debug)]
pub struct SessionContext {
Expand Down

0 comments on commit fb1536c

Please sign in to comment.