update_user

Function update_user 

Source
pub async fn update_user(
    __arg0: Path<i16>,
    __arg1: State<Arc<AppState>>,
    __arg2: Json<UserUpdateScheme>,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)>
Expand description

Updates an existing user’s information.

This endpoint allows administrators to modify a User’s first_name, last_name, username, is_admin status, and optionally their password. If new_pwd in the request body is an empty string, the user’s password remains unchanged.

§Arguments

  • Path(id): The ID of the User to update, extracted from the URL path.
  • State(data): Application state containing AppState for database access.
  • Json(body): UserUpdateScheme containing the fields to update.

§Returns

  • 200 OK with the FilteredUser object of the updated user (converted via filter_user).
  • 404 Not Found if a user with the given ID does not exist.
  • 500 Internal Server Error if a database query or password hashing error occurs.

§Security Note

  • Passwords are hashed using Argon2 before storage.
  • This endpoint requires admin privileges (enforced by middleware via validate_admin).