mirror of https://github.com/buster-so/buster.git
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:
parent
24c8efdc6e
commit
6aea4349a3
|
@ -10,6 +10,6 @@ mod update_user;
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(get_user::get_user))
|
.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))
|
.route("/:id", get(get_user_by_id::get_user_by_id))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use axum::extract::Path;
|
||||||
use axum::{Extension, Json};
|
use axum::{Extension, Json};
|
||||||
|
|
||||||
use crate::database::enums::UserOrganizationStatus;
|
use crate::database::enums::UserOrganizationStatus;
|
||||||
|
@ -30,9 +31,10 @@ pub struct UpdateUserRequest {
|
||||||
|
|
||||||
pub async fn update_user(
|
pub async fn update_user(
|
||||||
Extension(user): Extension<User>,
|
Extension(user): Extension<User>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
Json(body): Json<UpdateUserRequest>,
|
Json(body): Json<UpdateUserRequest>,
|
||||||
) -> Result<ApiResponse<()>, (StatusCode, &'static str)> {
|
) -> Result<ApiResponse<()>, (StatusCode, &'static str)> {
|
||||||
match update_user_handler(&user.id, body).await {
|
match update_user_handler(&id, body).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Error getting user information: {:?}", e);
|
tracing::error!("Error getting user information: {:?}", e);
|
||||||
|
|
Loading…
Reference in New Issue