mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-07 03:50:36 +00:00
refactor: user details
This commit is contained in:
parent
e7f97ebd2c
commit
b6783c6de4
2 changed files with 12 additions and 12 deletions
|
|
@ -4,7 +4,7 @@ extern crate rocket;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use guards::request::auth::{CandidateAuth, AdminAuth};
|
use guards::request::auth::{CandidateAuth, AdminAuth};
|
||||||
use portfolio_core::services::candidate_service::{CandidateService, AddUserDetailsForm};
|
use portfolio_core::services::candidate_service::{CandidateService, UserDetails};
|
||||||
use requests::{LoginRequest, RegisterRequest};
|
use requests::{LoginRequest, RegisterRequest};
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
use rocket::{Rocket, Build};
|
use rocket::{Rocket, Build};
|
||||||
|
|
@ -58,7 +58,7 @@ async fn admin(session: AdminAuth) -> Result<String, Custom<String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/details", data = "<details>")]
|
#[put("/details", data = "<details>")]
|
||||||
async fn fill_details(conn: Connection<'_, Db>, details: Json<AddUserDetailsForm>, session: CandidateAuth) -> Result<String, Custom<String>> {
|
async fn fill_details(conn: Connection<'_, Db>, details: Json<UserDetails>, session: CandidateAuth) -> Result<String, Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
let form = details.into_inner();
|
let form = details.into_inner();
|
||||||
let candidate: entity::candidate::Model = session.into();
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub(crate) struct EncryptedAddUserData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedAddUserData {
|
impl EncryptedAddUserData {
|
||||||
pub async fn encrypt_form(form: AddUserDetailsForm, recipients: Vec<&str>) -> EncryptedAddUserData {
|
pub async fn encrypt_form(form: UserDetails, recipients: Vec<&str>) -> EncryptedAddUserData {
|
||||||
let (
|
let (
|
||||||
Ok(name),
|
Ok(name),
|
||||||
Ok(surname),
|
Ok(surname),
|
||||||
|
|
@ -67,7 +67,7 @@ impl EncryptedAddUserData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_enc_candidate_details(candidate: candidate::Model) -> Result<AddUserDetailsForm, ServiceError> {
|
fn extract_enc_candidate_details(candidate: candidate::Model) -> Result<UserDetails, ServiceError> {
|
||||||
let ( // TODO: simplify??
|
let ( // TODO: simplify??
|
||||||
Some(name),
|
Some(name),
|
||||||
Some(surname),
|
Some(surname),
|
||||||
|
|
@ -94,7 +94,7 @@ impl EncryptedAddUserData {
|
||||||
return Err(ServiceError::CandidateDetailsNotSet);
|
return Err(ServiceError::CandidateDetailsNotSet);
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(AddUserDetailsForm {
|
Ok(UserDetails {
|
||||||
name,
|
name,
|
||||||
surname,
|
surname,
|
||||||
birthplace,
|
birthplace,
|
||||||
|
|
@ -126,7 +126,7 @@ impl EncryptedAddUserData {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn decrypt(self, priv_key: String) -> Result<AddUserDetailsForm, ServiceError> {
|
pub async fn decrypt(self, priv_key: String) -> Result<UserDetails, ServiceError> {
|
||||||
let (
|
let (
|
||||||
Ok(name),
|
Ok(name),
|
||||||
Ok(surname),
|
Ok(surname),
|
||||||
|
|
@ -153,7 +153,7 @@ impl EncryptedAddUserData {
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
AddUserDetailsForm {
|
UserDetails {
|
||||||
name,
|
name,
|
||||||
surname,
|
surname,
|
||||||
birthplace,
|
birthplace,
|
||||||
|
|
@ -170,7 +170,7 @@ impl EncryptedAddUserData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct AddUserDetailsForm {
|
pub struct UserDetails {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub surname: String,
|
pub surname: String,
|
||||||
pub birthplace: String,
|
pub birthplace: String,
|
||||||
|
|
@ -244,7 +244,7 @@ impl CandidateService {
|
||||||
pub async fn add_user_details(
|
pub async fn add_user_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
user: candidate::Model,
|
user: candidate::Model,
|
||||||
form: AddUserDetailsForm,
|
form: UserDetails,
|
||||||
) -> Result<entity::candidate::Model, ServiceError> {
|
) -> Result<entity::candidate::Model, ServiceError> {
|
||||||
let Ok(admin_public_keys) = Query::get_all_admin_public_keys(db).await else {
|
let Ok(admin_public_keys) = Query::get_all_admin_public_keys(db).await else {
|
||||||
return Err(ServiceError::DbError);
|
return Err(ServiceError::DbError);
|
||||||
|
|
@ -272,7 +272,7 @@ impl CandidateService {
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
candidate_id: i32,
|
candidate_id: i32,
|
||||||
password: String,
|
password: String,
|
||||||
) -> Result<AddUserDetailsForm, ServiceError> {
|
) -> Result<UserDetails, ServiceError> {
|
||||||
// compare passwords // TODO: login in api?? // TODO: dedicated function
|
// compare passwords // TODO: login in api?? // TODO: dedicated function
|
||||||
let candidate = Query::find_candidate_by_id(db, candidate_id)
|
let candidate = Query::find_candidate_by_id(db, candidate_id)
|
||||||
.await
|
.await
|
||||||
|
|
@ -329,7 +329,7 @@ mod tests {
|
||||||
use sea_orm::{Database, DbConn};
|
use sea_orm::{Database, DbConn};
|
||||||
use entity::candidate::Model;
|
use entity::candidate::Model;
|
||||||
|
|
||||||
use crate::{crypto, services::candidate_service::{CandidateService, AddUserDetailsForm}};
|
use crate::{crypto, services::candidate_service::{CandidateService, UserDetails}};
|
||||||
|
|
||||||
use super::EncryptedAddUserData;
|
use super::EncryptedAddUserData;
|
||||||
|
|
||||||
|
|
@ -407,7 +407,7 @@ mod tests {
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let form = AddUserDetailsForm {
|
let form = UserDetails {
|
||||||
name: "test".to_string(),
|
name: "test".to_string(),
|
||||||
surname: "a".to_string(),
|
surname: "a".to_string(),
|
||||||
birthplace: "b".to_string(),
|
birthplace: "b".to_string(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue