From 6aea4349a39f00dac7e17d0c49c3219c781c27b9 Mon Sep 17 00:00:00 2001 From: dal Date: Wed, 15 Jan 2025 11:17:24 -0700 Subject: [PATCH] Update user route to use ID parameter for updates - Changed the user update route to require a user ID in the URL, enhancing RESTful practices. - Updated the `update_user` function to extract the user ID from the path, ensuring the correct user is updated based on the provided ID. These changes improve the clarity and functionality of the user update endpoint, aligning it with standard REST conventions. --- api/src/routes/rest/routes/users/mod.rs | 2 +- api/src/routes/rest/routes/users/update_user.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/api/src/routes/rest/routes/users/mod.rs b/api/src/routes/rest/routes/users/mod.rs index e3eaeb3af..4de5bba16 100644 --- a/api/src/routes/rest/routes/users/mod.rs +++ b/api/src/routes/rest/routes/users/mod.rs @@ -10,6 +10,6 @@ mod update_user; pub fn router() -> Router { Router::new() .route("/", get(get_user::get_user)) - .route("/", put(update_user::update_user)) + .route("/:id", put(update_user::update_user)) .route("/:id", get(get_user_by_id::get_user_by_id)) } diff --git a/api/src/routes/rest/routes/users/update_user.rs b/api/src/routes/rest/routes/users/update_user.rs index abbeaabd4..1c998c666 100644 --- a/api/src/routes/rest/routes/users/update_user.rs +++ b/api/src/routes/rest/routes/users/update_user.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use axum::extract::Path; use axum::{Extension, Json}; use crate::database::enums::UserOrganizationStatus; @@ -30,9 +31,10 @@ pub struct UpdateUserRequest { pub async fn update_user( Extension(user): Extension, + Path(id): Path, Json(body): Json, ) -> Result, (StatusCode, &'static str)> { - match update_user_handler(&user.id, body).await { + match update_user_handler(&id, body).await { Ok(_) => (), Err(e) => { tracing::error!("Error getting user information: {:?}", e);