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.
This commit is contained in:
dal 2025-01-15 11:17:24 -07:00
parent 24c8efdc6e
commit 6aea4349a3
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 4 additions and 2 deletions

View File

@ -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))
}

View File

@ -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<User>,
Path(id): Path<Uuid>,
Json(body): Json<UpdateUserRequest>,
) -> Result<ApiResponse<()>, (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);