User APIs Documentation

The UserController handles user-related actions, such as retrieving user information, managing friendships, and updating user data. See the User Guide for more info.

Controller Route: /api/users

All routes within the UserController are prefixed by /api/users.


Summary of Endpoints

Endpoint Method Description Authorization
/api/users/get GET Fetches user details by user ID. Admin, User, Pass
/api/users/search GET Searches users by username. Admin, User, Pass
/api/users/add-friend POST Adds a user as a friend. Admin, User, Pass
/api/users/remove-friend POST Removes a user from friends. Admin, User, Pass
/api/users/current GET Retrieves the current logged-in user's details. Admin, User, Pass
/api/users/create POST Creates a new user with specified role. Admin, Server
/api/users/delete POST Deletes a user by ID. Admin
/api/users/update PATCH Updates a user's profile information. Admin, User, Pass
/api/users/change-username PATCH Changes the username for a user. Admin, User, Pass
/api/users/change-password PATCH Changes the password for a user. Admin, User, Pass

Get User by ID

Fetches the details of a user by their user ID.

Details:

Parameters:

Responses:

Example Request:

curl -X GET "https://your-api-url.com/api/users/get?id=66bc99b8ab7ba419497e21af" \
             -H "Authorization: Bearer <JWT-token>"
        

Search Users

Searches for users by their username.

Details:

Parameters:

Responses:

Example Request:

curl -X GET "https://your-api-url.com/api/users/search?username=Epsi" \
             -H "Authorization: Bearer <JWT-token>"
        

Add Friend

Adds a user to the current user's friend list.

Details:

Parameters:

Responses:

Example Request:

curl -X POST "https://your-api-url.com/api/users/add-friend?id=66bc99b8ab7ba419497e21af" \
             -H "Authorization: Bearer <JWT-token>"
        

Remove Friend

Removes a user from the current user's friend list.

Details:

Parameters:

Responses:

Example Request:

curl -X POST "https://your-api-url.com/api/users/remove-friend?id=user123" \
             -H "Authorization: Bearer <JWT-token>"
        

Get Current User

Retrieves the details of the currently logged-in user.

Details:

Responses:

Example Request:

curl -X GET "https://your-api-url.com/api/users/current" \
             -H "Authorization: Bearer <JWT-token>"
        

Create User

Creates a new user with a username, password, and role.

Details:

Parameters:

Responses:

Example Request:

curl -X POST "https://your-api-url.com/api/users/create?username=newuser&password=Password123&role=User" \
             -H "Authorization: Bearer <JWT-token>"
        

Delete User

Deletes a user by their user ID.

Details:

Parameters:

Responses:

Example Request:

curl -X POST "https://your-api-url.com/api/users/delete?id=user123" \
             -H "Authorization: Bearer <JWT-token>"
        

Update User

Updates the profile information of a user.

Details:

Parameters:

Responses:

Example Request:

curl -X PATCH "https://your-api-url.com/api/users/update?id=user123&bio=New bio" \
             -H "Authorization: Bearer <JWT-token>"
        

Change Username

Changes the username of a user.

Details:

Parameters:

Responses:

Example Request:

curl -X PATCH "https://your-api-url.com/api/users/change-username?id=user123&username=newusername" \
             -H "Authorization: Bearer <JWT-token>"
        

Change Password

Changes the password of a user.

Details:

Parameters:

Responses:

: If the action is not authorized.

Example Request:

curl -X PATCH "https://your-api-url.com/api/users/change-password?id=user123&password=newpassword" \
             -H "Authorization: Bearer <JWT-token>"