mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-05 11:00:56 +00:00
feat: admin csv endpoint
This commit is contained in:
parent
53be6cb72d
commit
91e411a390
2 changed files with 25 additions and 2 deletions
|
|
@ -152,7 +152,13 @@ pub fn rocket() -> Rocket<Build> {
|
||||||
routes::admin::get_candidate_portfolio,
|
routes::admin::get_candidate_portfolio,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.mount("/admin/list", routes![routes::admin::list_candidates,])
|
.mount(
|
||||||
|
"/admin/list",
|
||||||
|
routes![
|
||||||
|
routes::admin::list_candidates,
|
||||||
|
routes::admin::list_candidates_csv,
|
||||||
|
]
|
||||||
|
)
|
||||||
.register("/", catchers![])
|
.register("/", catchers![])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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}, models::candidate::{BaseCandidateResponse, CreateCandidateResponse, ApplicationDetails}, sea_orm::prelude::Uuid, Query, error::ServiceError,
|
services::{admin_service::AdminService, candidate_service::CandidateService, application_service::ApplicationService, portfolio_service::PortfolioService}, models::candidate::{BaseCandidateResponse, CreateCandidateResponse, ApplicationDetails}, sea_orm::prelude::Uuid, Query, error::ServiceError, utils::csv,
|
||||||
};
|
};
|
||||||
use requests::{AdminLoginRequest, RegisterRequest};
|
use requests::{AdminLoginRequest, RegisterRequest};
|
||||||
use rocket::http::{Cookie, Status, CookieJar};
|
use rocket::http::{Cookie, Status, CookieJar};
|
||||||
|
|
@ -137,6 +137,23 @@ pub async fn list_candidates(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/candidates_csv")]
|
||||||
|
pub async fn list_candidates_csv(
|
||||||
|
conn: Connection<'_, Db>,
|
||||||
|
session: AdminAuth,
|
||||||
|
) -> Result<Vec<u8>, Custom<String>> {
|
||||||
|
let db = conn.into_inner();
|
||||||
|
let private_key = session.get_private_key();
|
||||||
|
|
||||||
|
let candidates = csv::export(db, private_key)
|
||||||
|
.await
|
||||||
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
|
Ok(
|
||||||
|
candidates
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/candidate/<id>")]
|
#[get("/candidate/<id>")]
|
||||||
pub async fn get_candidate(
|
pub async fn get_candidate(
|
||||||
conn: Connection<'_, Db>,
|
conn: Connection<'_, Db>,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue