From 965b6b52d2b0fbdb0f09c2d8c6baf972650e7808 Mon Sep 17 00:00:00 2001 From: Frederic Henrichs Date: Tue, 15 Oct 2024 09:32:01 +0200 Subject: [PATCH] backend: add api documentation for new delete_user route. --- backend/src/api_docs.rs | 2 ++ backend/src/routes/user/delete.rs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/src/api_docs.rs b/backend/src/api_docs.rs index fcea7d7..ff27ab1 100644 --- a/backend/src/api_docs.rs +++ b/backend/src/api_docs.rs @@ -97,6 +97,7 @@ async fn main() { routes::user::update_password::update_password, routes::user::update_user::update_user, routes::user::get_secret::get_secret, + routes::user::delete::delete_user, routes::management::management, ), components(schemas( @@ -114,6 +115,7 @@ async fn main() { routes::charger::get_key::GetWgKeysResponseSchema, routes::user::update_password::PasswordUpdateSchema, routes::user::get_secret::GetSecretResponse, + routes::user::delete::DeleteUserSchema, routes::management::ManagementSchema, routes::management::ManagementResponseSchema, routes::management::ManagementDataVersion, diff --git a/backend/src/routes/user/delete.rs b/backend/src/routes/user/delete.rs index 58adf29..e963bf3 100644 --- a/backend/src/routes/user/delete.rs +++ b/backend/src/routes/user/delete.rs @@ -7,7 +7,7 @@ use utoipa::ToSchema; use crate::{error::Error, routes::{auth::login::{validate_password, FindBy}, charger::remove::{delete_all_allowed_users, delete_all_keys, delete_charger}, user::logout::delete_all_refresh_tokens}, utils::{get_connection, web_block_unpacked}, AppState}; #[derive(ToSchema, Serialize, Deserialize)] -pub struct DeleteSchema { +pub struct DeleteUserSchema { #[schema(value_type = Vec)] pub login_key: Vec } @@ -37,8 +37,17 @@ async fn get_all_chargers_for_user(user_id: uuid::Uuid, state: &web::Data, user_id: crate::models::uuid::Uuid, payload: web::Json) -> actix_web::Result { +pub async fn delete_user(state: web::Data, user_id: crate::models::uuid::Uuid, payload: web::Json) -> actix_web::Result { let user_id = user_id.into(); let conn = get_connection(&state)?; @@ -77,7 +86,7 @@ mod tests { use crate::{middleware::jwt::JwtMiddleware, routes::{auth::get_login_salt::tests::get_test_login_salt, user::tests::{get_test_uuid, hash_test_key, TestUser}}, tests::configure, utils::generate_random_bytes}; - use super::{delete_user, DeleteSchema}; + use super::{delete_user, DeleteUserSchema}; //TODO: add test for shared charger once it is merged @@ -100,7 +109,7 @@ mod tests { let login_salt = get_test_login_salt(&user1_mail).await; let login_key = hash_test_key(&user1.password, &login_salt, None); - let schema = DeleteSchema { + let schema = DeleteUserSchema { login_key }; let req = test::TestRequest::delete() @@ -170,7 +179,7 @@ mod tests { .service(delete_user); let app = test::init_service(app).await; - let schema = DeleteSchema { + let schema = DeleteUserSchema { login_key: generate_random_bytes() }; let req = test::TestRequest::delete()