mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-08 12:30:56 +00:00
refactor: use from trait for type conversion
This commit is contained in:
parent
4d97173176
commit
06553679fb
2 changed files with 8 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use entity::candidate::Model;
|
use entity::candidate::Model as Candidate;
|
||||||
use portfolio_core::sea_orm::prelude::Uuid;
|
use portfolio_core::sea_orm::prelude::Uuid;
|
||||||
use portfolio_core::services::candidate_service::CandidateService;
|
use portfolio_core::services::candidate_service::CandidateService;
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
|
|
@ -7,12 +7,11 @@ use rocket::request::{FromRequest, Request};
|
||||||
|
|
||||||
use crate::pool::Db;
|
use crate::pool::Db;
|
||||||
|
|
||||||
|
pub struct SessionAuth(Candidate);
|
||||||
|
|
||||||
pub struct SessionAuth(Model);
|
impl From<SessionAuth> for Candidate {
|
||||||
|
fn from(src: SessionAuth) -> Candidate {
|
||||||
impl SessionAuth {
|
src.0
|
||||||
pub fn model(self) -> Model { // TODO: use into_inner instead?
|
|
||||||
self.0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ async fn create(conn: Connection<'_, Db>, post_form: Json<RegisterRequest>) -> R
|
||||||
|
|
||||||
#[get("/whoami")]
|
#[get("/whoami")]
|
||||||
async fn validate(session: SessionAuth) -> Result<String, Custom<String>> {
|
async fn validate(session: SessionAuth) -> Result<String, Custom<String>> {
|
||||||
Ok(session.model().application.to_string())
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
Ok(candidate.application.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/login", data = "<login_form>")]
|
#[post("/login", data = "<login_form>")]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue