mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-19 22:41:13 +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::{
|
||||
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 rocket::http::{Cookie, Status, CookieJar};
|
||||
|
|
@ -11,7 +11,7 @@ use rocket::serde::json::Json;
|
|||
|
||||
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>")]
|
||||
pub async fn login(
|
||||
|
|
@ -82,14 +82,14 @@ pub async fn hello(_session: AdminAuth) -> Result<String, Custom<String>> {
|
|||
Ok("Hello admin".to_string())
|
||||
}
|
||||
|
||||
#[post("/create", data = "<post_form>")]
|
||||
#[post("/create", data = "<request>")]
|
||||
pub async fn create_candidate(
|
||||
conn: Connection<'_, Db>,
|
||||
_session: AdminAuth,
|
||||
post_form: Json<RegisterRequest>,
|
||||
request: Json<RegisterRequest>,
|
||||
) -> Result<String, Custom<String>> {
|
||||
let db = conn.into_inner();
|
||||
let form = post_form.into_inner();
|
||||
let form = request.into_inner();
|
||||
|
||||
let plain_text_password = random_8_char_string();
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ pub async fn list_candidates(
|
|||
session: AdminAuth,
|
||||
field: Option<String>,
|
||||
page: Option<u64>,
|
||||
) -> Result<Json<Vec<CandidateResponse>>, Custom<String>> {
|
||||
) -> Result<Json<Vec<BaseCandidateResponse>>, Custom<String>> {
|
||||
let db = conn.into_inner();
|
||||
let private_key = session.get_private_key();
|
||||
if let Some(field) = field.clone() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use serde::Serialize;
|
|||
use crate::{candidate_details::EncryptedString, error::ServiceError};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CandidateResponse {
|
||||
pub struct BaseCandidateResponse {
|
||||
pub application_id: i32,
|
||||
pub name: String,
|
||||
pub surname: String,
|
||||
|
|
@ -11,7 +11,7 @@ pub struct CandidateResponse {
|
|||
pub submitted: bool,
|
||||
}
|
||||
|
||||
impl CandidateResponse {
|
||||
impl BaseCandidateResponse {
|
||||
pub async fn from_encrypted(
|
||||
private_key: &String,
|
||||
application_id: i32,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
candidate_details::{EncryptedApplicationDetails},
|
||||
crypto::{self, hash_password},
|
||||
error::ServiceError,
|
||||
Mutation, Query, responses::CandidateResponse,
|
||||
Mutation, Query, responses::BaseCandidateResponse,
|
||||
};
|
||||
|
||||
use super::{session_service::{AdminUser, SessionService}, application_service::ApplicationService};
|
||||
|
|
@ -150,7 +150,7 @@ impl CandidateService {
|
|||
db: &DbConn,
|
||||
field_of_study: Option<String>,
|
||||
page: Option<u64>,
|
||||
) -> Result<Vec<CandidateResponse>, ServiceError> {
|
||||
) -> Result<Vec<BaseCandidateResponse>, ServiceError> {
|
||||
|
||||
let candidates = Query::list_candidates(
|
||||
db,
|
||||
|
|
@ -158,11 +158,11 @@ impl CandidateService {
|
|||
page
|
||||
).await?;
|
||||
|
||||
let mut result: Vec<CandidateResponse> = vec![];
|
||||
let mut result: Vec<BaseCandidateResponse> = vec![];
|
||||
|
||||
for candidate in candidates {
|
||||
result.push(
|
||||
CandidateResponse::from_encrypted(
|
||||
BaseCandidateResponse::from_encrypted(
|
||||
&private_key,
|
||||
candidate.application,
|
||||
candidate.name,
|
||||
|
|
|
|||
Loading…
Reference in a new issue