mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-15 12:31:23 +00:00
feat: NewCandidateResponse
This commit is contained in:
parent
a59b06d18c
commit
28940e46af
2 changed files with 27 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
|||
|
||||
use portfolio_core::Query;
|
||||
use portfolio_core::models::auth::AuthenticableTrait;
|
||||
use portfolio_core::models::candidate::ApplicationDetails;
|
||||
use portfolio_core::models::candidate::{ApplicationDetails, BaseCandidateResponse, NewCandidateResponse};
|
||||
use portfolio_core::sea_orm::prelude::Uuid;
|
||||
use portfolio_core::services::application_service::ApplicationService;
|
||||
use portfolio_core::services::candidate_service::CandidateService;
|
||||
|
|
@ -72,9 +72,13 @@ pub async fn logout(
|
|||
}
|
||||
|
||||
#[get("/whoami")]
|
||||
pub async fn whoami(session: CandidateAuth) -> Result<String, Custom<String>> {
|
||||
pub async fn whoami(session: CandidateAuth) -> Result<Json<NewCandidateResponse>, Custom<String>> {
|
||||
let private_key = session.get_private_key();
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
Ok(candidate.application.to_string())
|
||||
let response = NewCandidateResponse::from_encrypted(&private_key, candidate).await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
// TODO: use put instead of post???
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use chrono::NaiveDate;
|
||||
use entity::candidate;
|
||||
use sea_orm::FromQueryResult;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
|
|
@ -6,6 +7,13 @@ use crate::{error::ServiceError, database::query::candidate::CandidateResult, se
|
|||
|
||||
use super::candidate_details::decrypt_if_exists;
|
||||
|
||||
/// Minimal candidate response containing database only not null fields
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct NewCandidateResponse {
|
||||
pub application_id: i32,
|
||||
pub personal_id_number: String,
|
||||
}
|
||||
|
||||
/// Create candidate (admin endpoint)
|
||||
/// Password change (admin endpoint)
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
@ -90,6 +98,18 @@ pub struct Row {
|
|||
pub second_parent_email: Option<String>,
|
||||
}
|
||||
|
||||
impl NewCandidateResponse {
|
||||
pub async fn from_encrypted(private_key: &String, c: candidate::Model) -> Result<Self, ServiceError> {
|
||||
let id_number = decrypt_if_exists(private_key, Some(c.personal_identification_number)).await?;
|
||||
Ok(
|
||||
Self {
|
||||
application_id: c.application,
|
||||
personal_id_number: id_number,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseCandidateResponse {
|
||||
pub async fn from_encrypted(
|
||||
private_key: &String,
|
||||
|
|
@ -113,5 +133,4 @@ impl BaseCandidateResponse {
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue