Function update_user

Source
pub async fn update_user(
    __arg0: State<AppState>,
    __arg1: Path<i64>,
    __arg2: Json<UpdateUserRequest>,
) -> impl IntoResponse
Expand description

PUT /api/users/{user_id}

Update a user’s information. Only admins can access this endpoint.

§Path Parameters

  • id - The ID of the user to update

§Request Body

{
  "username": "u87654321",  // optional
  "email": "[email protected]",     // optional
  "admin": true                   // optional
}

§Responses

  • 200 OK
{
  "success": true,
  "data": {
    "id": 1,
    "username": "u87654321",
    "email": "[email protected]",
    "admin": true,
    "created_at": "2025-05-23T18:00:00Z",
    "updated_at": "2025-05-23T18:00:00Z"
  },
  "message": "User updated successfully"
}
  • 400 Bad Request (validation error)
{
  "success": false,
  "message": "Student number must be in format u12345678"
}
  • 404 Not Found (user doesn’t exist)
{
  "success": false,
  "message": "User not found"
}
  • 409 Conflict (duplicate email/student number)
{
  "success": false,
  "message": "A user with this email already exists"
}
  • 500 Internal Server Error
{
  "success": false,
  "message": "Database error: detailed error here"
}