mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-06 19:40:49 +00:00
refactor: base candidate response
This commit is contained in:
parent
1a7d95fb3d
commit
6a3158d958
3 changed files with 12 additions and 12 deletions
|
|
@ -2,7 +2,7 @@ use std::net::{SocketAddr, IpAddr, Ipv4Addr};
|
||||||
|
|
||||||
use portfolio_core::{
|
use portfolio_core::{
|
||||||
crypto::random_8_char_string,
|
crypto::random_8_char_string,
|
||||||
services::{admin_service::AdminService, candidate_service::CandidateService, application_service::ApplicationService, portfolio_service::PortfolioService}, responses::CandidateResponse, candidate_details::ApplicationDetails, sea_orm::prelude::Uuid,
|
services::{admin_service::AdminService, candidate_service::CandidateService, application_service::ApplicationService, portfolio_service::PortfolioService}, responses::BaseCandidateResponse, candidate_details::ApplicationDetails, sea_orm::prelude::Uuid,
|
||||||
};
|
};
|
||||||
use requests::{AdminLoginRequest, RegisterRequest};
|
use requests::{AdminLoginRequest, RegisterRequest};
|
||||||
use rocket::http::{Cookie, Status, CookieJar};
|
use rocket::http::{Cookie, Status, CookieJar};
|
||||||
|
|
@ -11,7 +11,7 @@ use rocket::serde::json::Json;
|
||||||
|
|
||||||
use sea_orm_rocket::Connection;
|
use sea_orm_rocket::Connection;
|
||||||
|
|
||||||
use crate::{guards::request::auth::AdminAuth, pool::Db, requests};
|
use crate::{guards::request::{auth::AdminAuth, self}, pool::Db, requests};
|
||||||
|
|
||||||
#[post("/login", data = "<login_form>")]
|
#[post("/login", data = "<login_form>")]
|
||||||
pub async fn login(
|
pub async fn login(
|
||||||
|
|
@ -82,14 +82,14 @@ pub async fn hello(_session: AdminAuth) -> Result<String, Custom<String>> {
|
||||||
Ok("Hello admin".to_string())
|
Ok("Hello admin".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/create", data = "<post_form>")]
|
#[post("/create", data = "<request>")]
|
||||||
pub async fn create_candidate(
|
pub async fn create_candidate(
|
||||||
conn: Connection<'_, Db>,
|
conn: Connection<'_, Db>,
|
||||||
_session: AdminAuth,
|
_session: AdminAuth,
|
||||||
post_form: Json<RegisterRequest>,
|
request: Json<RegisterRequest>,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<String, Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
let form = post_form.into_inner();
|
let form = request.into_inner();
|
||||||
|
|
||||||
let plain_text_password = random_8_char_string();
|
let plain_text_password = random_8_char_string();
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ pub async fn list_candidates(
|
||||||
session: AdminAuth,
|
session: AdminAuth,
|
||||||
field: Option<String>,
|
field: Option<String>,
|
||||||
page: Option<u64>,
|
page: Option<u64>,
|
||||||
) -> Result<Json<Vec<CandidateResponse>>, Custom<String>> {
|
) -> Result<Json<Vec<BaseCandidateResponse>>, Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
let private_key = session.get_private_key();
|
let private_key = session.get_private_key();
|
||||||
if let Some(field) = field.clone() {
|
if let Some(field) = field.clone() {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use serde::Serialize;
|
||||||
use crate::{candidate_details::EncryptedString, error::ServiceError};
|
use crate::{candidate_details::EncryptedString, error::ServiceError};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct CandidateResponse {
|
pub struct BaseCandidateResponse {
|
||||||
pub application_id: i32,
|
pub application_id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub surname: String,
|
pub surname: String,
|
||||||
|
|
@ -11,7 +11,7 @@ pub struct CandidateResponse {
|
||||||
pub submitted: bool,
|
pub submitted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CandidateResponse {
|
impl BaseCandidateResponse {
|
||||||
pub async fn from_encrypted(
|
pub async fn from_encrypted(
|
||||||
private_key: &String,
|
private_key: &String,
|
||||||
application_id: i32,
|
application_id: i32,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
candidate_details::{EncryptedApplicationDetails},
|
candidate_details::{EncryptedApplicationDetails},
|
||||||
crypto::{self, hash_password},
|
crypto::{self, hash_password},
|
||||||
error::ServiceError,
|
error::ServiceError,
|
||||||
Mutation, Query, responses::CandidateResponse,
|
Mutation, Query, responses::BaseCandidateResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{session_service::{AdminUser, SessionService}, application_service::ApplicationService};
|
use super::{session_service::{AdminUser, SessionService}, application_service::ApplicationService};
|
||||||
|
|
@ -150,7 +150,7 @@ impl CandidateService {
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
field_of_study: Option<String>,
|
field_of_study: Option<String>,
|
||||||
page: Option<u64>,
|
page: Option<u64>,
|
||||||
) -> Result<Vec<CandidateResponse>, ServiceError> {
|
) -> Result<Vec<BaseCandidateResponse>, ServiceError> {
|
||||||
|
|
||||||
let candidates = Query::list_candidates(
|
let candidates = Query::list_candidates(
|
||||||
db,
|
db,
|
||||||
|
|
@ -158,11 +158,11 @@ impl CandidateService {
|
||||||
page
|
page
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
let mut result: Vec<CandidateResponse> = vec![];
|
let mut result: Vec<BaseCandidateResponse> = vec![];
|
||||||
|
|
||||||
for candidate in candidates {
|
for candidate in candidates {
|
||||||
result.push(
|
result.push(
|
||||||
CandidateResponse::from_encrypted(
|
BaseCandidateResponse::from_encrypted(
|
||||||
&private_key,
|
&private_key,
|
||||||
candidate.application,
|
candidate.application,
|
||||||
candidate.name,
|
candidate.name,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue