diff --git a/src/api/v1/admin/account/delete.rs b/src/api/v1/admin/account/delete.rs index e44eac6..a92086f 100644 --- a/src/api/v1/admin/account/delete.rs +++ b/src/api/v1/admin/account/delete.rs @@ -22,7 +22,7 @@ use super::auth::runners::Password; use crate::errors::*; use crate::AppData; -#[my_codegen::post( +#[actix_web_codegen_const_routes::post( path = "crate::V1_API_ROUTES.admin.account.delete", wrap = "crate::api::v1::admin::get_admin_check_login()" )] diff --git a/src/api/v1/admin/account/email.rs b/src/api/v1/admin/account/email.rs index 16956bf..9c3a43a 100644 --- a/src/api/v1/admin/account/email.rs +++ b/src/api/v1/admin/account/email.rs @@ -29,7 +29,9 @@ pub struct Email { pub email: String, } -#[my_codegen::post(path = "crate::V1_API_ROUTES.admin.account.email_exists")] +#[actix_web_codegen_const_routes::post( + path = "crate::V1_API_ROUTES.admin.account.email_exists" +)] pub async fn email_exists( payload: web::Json, data: AppData, @@ -53,7 +55,7 @@ pub async fn email_exists( } /// update email -#[my_codegen::post( +#[actix_web_codegen_const_routes::post( path = "crate::V1_API_ROUTES.admin.account.update_email", wrap = "crate::api::v1::admin::get_admin_check_login()" )] diff --git a/src/api/v1/admin/account/mod.rs b/src/api/v1/admin/account/mod.rs index beaae9e..bcbbf11 100644 --- a/src/api/v1/admin/account/mod.rs +++ b/src/api/v1/admin/account/mod.rs @@ -28,7 +28,9 @@ pub mod username; pub use super::auth; pub mod routes { + use serde::{Deserialize, Serialize}; + #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] pub struct Account { pub delete: &'static str, pub email_exists: &'static str, diff --git a/src/api/v1/admin/account/password.rs b/src/api/v1/admin/account/password.rs index 121a82f..8873524 100644 --- a/src/api/v1/admin/account/password.rs +++ b/src/api/v1/admin/account/password.rs @@ -68,7 +68,7 @@ async fn update_password_runner( Ok(()) } -#[my_codegen::post( +#[actix_web_codegen_const_routes::post( path = "crate::V1_API_ROUTES.admin.account.update_password", wrap = "crate::api::v1::admin::get_admin_check_login()" )] @@ -118,7 +118,6 @@ mod tests { use actix_web::test; use crate::api::v1::ROUTES; - use crate::data::Data; use crate::tests::*; #[actix_rt::test] @@ -128,7 +127,7 @@ mod tests { const EMAIL: &str = "updatepassuser@a.com"; { - let data = Data::new().await; + let data = get_test_data().await; delete_user(NAME, &data).await; } diff --git a/src/api/v1/admin/account/secret.rs b/src/api/v1/admin/account/secret.rs index 74de63b..b49395b 100644 --- a/src/api/v1/admin/account/secret.rs +++ b/src/api/v1/admin/account/secret.rs @@ -29,7 +29,7 @@ pub struct Secret { pub secret: String, } -#[my_codegen::get( +#[actix_web_codegen_const_routes::get( path = "crate::V1_API_ROUTES.admin.account.get_secret", wrap = "crate::api::v1::admin::get_admin_check_login()" )] @@ -47,7 +47,7 @@ async fn get_secret(id: Identity, data: AppData) -> ServiceResult, data: AppData, @@ -65,7 +67,7 @@ pub struct Username { } /// update username -#[my_codegen::post( +#[actix_web_codegen_const_routes::post( path = "crate::V1_API_ROUTES.admin.account.update_username", wrap = "crate::api::v1::admin::get_admin_check_login()" )] diff --git a/src/api/v1/admin/auth.rs b/src/api/v1/admin/auth.rs index 67a1f6d..2bfb8b0 100644 --- a/src/api/v1/admin/auth.rs +++ b/src/api/v1/admin/auth.rs @@ -26,7 +26,9 @@ use crate::AppData; pub mod routes { use actix_auth_middleware::GetLoginRoute; + use serde::{Deserialize, Serialize}; + #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] pub struct Auth { pub logout: &'static str, pub login: &'static str, @@ -153,7 +155,7 @@ pub mod runners { payload: &Register, data: &AppData, ) -> ServiceResult<()> { - if !crate::SETTINGS.allow_registration { + if !data.settings.allow_registration { return Err(ServiceError::ClosedForRegistration); } @@ -222,7 +224,9 @@ pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(login); cfg.service(signout); } -#[my_codegen::post(path = "crate::V1_API_ROUTES.admin.auth.register")] +#[actix_web_codegen_const_routes::post( + path = "crate::V1_API_ROUTES.admin.auth.register" +)] async fn register( payload: web::Json, data: AppData, @@ -231,7 +235,7 @@ async fn register( Ok(HttpResponse::Ok()) } -#[my_codegen::post(path = "crate::V1_API_ROUTES.admin.auth.login")] +#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.admin.auth.login")] async fn login( id: Identity, payload: web::Json, @@ -250,7 +254,7 @@ async fn login( Ok(HttpResponse::Ok().into()) } } -#[my_codegen::get( +#[actix_web_codegen_const_routes::get( path = "crate::V1_API_ROUTES.admin.auth.logout", wrap = "crate::api::v1::admin::get_admin_check_login()" )] diff --git a/src/api/v1/admin/campaigns.rs b/src/api/v1/admin/campaigns.rs index a8d3eac..02a7181 100644 --- a/src/api/v1/admin/campaigns.rs +++ b/src/api/v1/admin/campaigns.rs @@ -27,6 +27,9 @@ use crate::errors::*; use crate::AppData; pub mod routes { + use serde::{Deserialize, Serialize}; + + #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] pub struct Campaign { pub add: &'static str, pub delete: &'static str, @@ -250,7 +253,7 @@ pub mod runners { } } -#[my_codegen::post( +#[actix_web_codegen_const_routes::post( path = "crate::V1_API_ROUTES.admin.campaign.delete", wrap = "get_admin_check_login()" )] @@ -279,7 +282,7 @@ pub async fn delete( // pub feedbacks: Vec, //} // -//#[my_codegen::post( +//#[actix_web_codegen_const_routes::post( // path = "crate::V1_API_ROUTES.campaign.get_feedback", // wrap = "crate::CheckLogin" //)] @@ -300,7 +303,7 @@ pub struct ListCampaignResp { pub uuid: String, } -#[my_codegen::post( +#[actix_web_codegen_const_routes::post( path = "crate::V1_API_ROUTES.admin.campaign.list", wrap = "get_admin_check_login()" )] @@ -332,7 +335,7 @@ pub fn services(cfg: &mut web::ServiceConfig) { //cfg.service(get_feedback); } -#[my_codegen::post(path = "crate::V1_API_ROUTES.admin.campaign.add")] +#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.admin.campaign.add")] async fn add( payload: web::Json, data: AppData, @@ -350,7 +353,6 @@ async fn add( #[cfg(test)] mod tests { use crate::api::v1::bench::Submission; - use crate::data::Data; use crate::errors::*; use crate::tests::*; use crate::*; @@ -360,7 +362,7 @@ mod tests { #[actix_rt::test] async fn test_bench_register_works() { - let data = Data::new().await; + let data = get_test_data().await; let app = get_app!(data).await; let signin_resp = test::call_service( &app, @@ -400,7 +402,7 @@ mod tests { const THREADS: i32 = 4; { - let data = Data::new().await; + let data = get_test_data().await; delete_user(NAME, &data).await; } diff --git a/src/api/v1/admin/mod.rs b/src/api/v1/admin/mod.rs index 5b74321..3da7527 100644 --- a/src/api/v1/admin/mod.rs +++ b/src/api/v1/admin/mod.rs @@ -24,7 +24,6 @@ pub mod campaigns; mod tests; pub use super::{get_random, get_uuid, RedirectQuery}; -use crate::api::v1::bench::SURVEY_USER_ID; pub fn services(cfg: &mut ServiceConfig) { auth::services(cfg); @@ -40,7 +39,9 @@ pub mod routes { use super::account::routes::Account; use super::auth::routes::Auth; use super::campaigns::routes::Campaign; + use serde::Serialize; + #[derive(Clone, Debug, Eq, PartialEq, Serialize)] pub struct Admin { pub auth: Auth, pub account: Account, diff --git a/src/api/v1/admin/tests/auth.rs b/src/api/v1/admin/tests/auth.rs index a9caf6b..f459229 100644 --- a/src/api/v1/admin/tests/auth.rs +++ b/src/api/v1/admin/tests/auth.rs @@ -20,7 +20,6 @@ use actix_web::test; use crate::api::v1::admin::auth::runners::{Login, Register}; use crate::api::v1::ROUTES; -use crate::data::Data; use crate::errors::*; use crate::*; @@ -28,7 +27,7 @@ use crate::tests::*; #[actix_rt::test] async fn auth_works() { - let data = Data::new().await; + let data = get_test_data().await; const NAME: &str = "testuser"; const PASSWORD: &str = "longpassword"; const EMAIL: &str = "testuser1@a.com"; @@ -146,7 +145,7 @@ async fn serverside_password_validation_works() { const NAME: &str = "testuser542"; const PASSWORD: &str = "longpassword2"; - let data = Data::new().await; + let data = get_test_data().await; delete_user(NAME, &data).await; let app = get_app!(data).await; diff --git a/src/api/v1/admin/tests/protected.rs b/src/api/v1/admin/tests/protected.rs index 21c027f..1edeb88 100644 --- a/src/api/v1/admin/tests/protected.rs +++ b/src/api/v1/admin/tests/protected.rs @@ -18,7 +18,6 @@ use actix_web::http::StatusCode; use actix_web::test; -use crate::data::Data; use crate::*; use crate::tests::*; @@ -32,7 +31,7 @@ async fn protected_routes_work() { let get_protected_urls = [V1_API_ROUTES.admin.auth.logout]; { - let data = Data::new().await; + let data = get_test_data().await; delete_user(NAME, &data).await; } diff --git a/src/api/v1/bench.rs b/src/api/v1/bench.rs index bf29042..2831b54 100644 --- a/src/api/v1/bench.rs +++ b/src/api/v1/bench.rs @@ -33,9 +33,11 @@ use crate::AppData; pub const SURVEY_USER_ID: &str = "survey_user_id"; pub mod routes { + use serde::{Deserialize, Serialize}; use actix_auth_middleware::GetLoginRoute; + #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct Benches { pub submit: &'static str, pub register: &'static str, @@ -125,7 +127,7 @@ pub mod runners { } } -#[my_codegen::get(path = "crate::V1_API_ROUTES.benches.register")] +#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.benches.register")] async fn register( data: AppData, session: Session, @@ -178,7 +180,7 @@ pub struct SubmissionProof { fn is_session_authenticated(r: &HttpRequest, mut pl: &mut Payload) -> bool { use actix_web::FromRequest; matches!( - Session::from_request(&r, &mut pl).into_inner().map(|x| { + Session::from_request(r, pl).into_inner().map(|x| { let val = x.get::(SURVEY_USER_ID); println!("{:#?}", val); val @@ -196,7 +198,7 @@ pub fn get_check_login() -> Authentication { // } //} -#[my_codegen::post( +#[actix_web_codegen_const_routes::post( path = "crate::V1_API_ROUTES.benches.submit", wrap = "get_check_login()" )] @@ -307,7 +309,7 @@ pub struct BenchConfig { pub difficulties: Vec, } -#[my_codegen::get( +#[actix_web_codegen_const_routes::get( path = "crate::V1_API_ROUTES.benches.fetch", wrap = "get_check_login()" )] diff --git a/src/api/v1/meta.rs b/src/api/v1/meta.rs index 274025e..d34101e 100644 --- a/src/api/v1/meta.rs +++ b/src/api/v1/meta.rs @@ -29,6 +29,9 @@ pub struct BuildDetails { } pub mod routes { + use serde::{Deserialize, Serialize}; + + #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct Meta { pub build_details: &'static str, pub health: &'static str, @@ -45,7 +48,7 @@ pub mod routes { } /// emmits build details of the bninary -#[my_codegen::get(path = "crate::V1_API_ROUTES.meta.build_details")] +#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.meta.build_details")] async fn build_details() -> impl Responder { let build = BuildDetails { version: VERSION, @@ -61,7 +64,7 @@ pub struct Health { } /// checks all components of the system -#[my_codegen::get(path = "crate::V1_API_ROUTES.meta.health")] +#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.meta.health")] async fn health(data: AppData) -> impl Responder { use sqlx::Connection; @@ -87,6 +90,7 @@ mod tests { use super::*; use crate::api::v1::services; + use crate::tests::get_test_data; use crate::*; #[actix_rt::test] @@ -106,7 +110,7 @@ mod tests { #[actix_rt::test] async fn health_works() { println!("{}", V1_API_ROUTES.meta.health); - let data = Data::new().await; + let data = get_test_data().await; let app = get_app!(data).await; let resp = test::call_service( diff --git a/src/api/v1/routes.rs b/src/api/v1/routes.rs index ed6fcce..05a0037 100644 --- a/src/api/v1/routes.rs +++ b/src/api/v1/routes.rs @@ -14,12 +14,15 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +use serde::Serialize; + use super::admin::routes::Admin; use super::bench::routes::Benches; use super::meta::routes::Meta; pub const ROUTES: Routes = Routes::new(); +#[derive(Clone, Debug, Eq, PartialEq, Serialize)] pub struct Routes { pub admin: Admin, pub meta: Meta,