User Management API

This is a backend application that provides a REST API for managing departments and users. It allows CRUD operations for departments and users, as well as retrieving the average salary per department. The API is secured with JWT token authentication.

Technologies Used

  • Java
  • Spring Boot
  • PostgreSQL (relational database)
  • Jooq (database query library)
  • Maven

Getting Started

To get started with the User Management API, follow these steps:

  1. Clone the repository from GitHub:

    git clone https://github.com/tolgaaksoy/expatrio-assignment.git
    
  2. Make sure you have PostgreSQL installed and running.

  3. Configure the database connection in the application properties file located at src/main/resources/application.properties.

  4. Build the project using Maven:

    cd user-management-api
    mvn clean package
    
  5. Run the application:

    mvn spring-boot:run
    

    The API will be accessible at http://localhost:8080/api.

API Endpoints

The following API endpoints are available:

Swagger documentation is available at: http://localhost:8080/api/v3/api-docs/swagger-ui/index.html

There is a Postman collection available for the API. You can import the collection from the following link:

Run in Postman

Authentication

  • POST /auth/login: Authenticates a user and returns a JWT token.
  • POST /auth/register: Registers a new user.
  • PUT /auth/authInfo: Updates user fields such as username and password.

Department Endpoints

  • GET /departments: Retrieves all departments.
  • GET /departments/{id}: Retrieves a department by its ID.
  • POST /departments: Creates a new department.
  • PUT /departments/{id}: Updates a department.
  • DELETE /departments/{id}: Deletes a department.

User Endpoints

  • GET /users: Retrieves all users.
  • GET /users/{id}: Retrieves a user by their ID.
  • POST /users: Creates a new user.
  • PUT /users/{id}: Updates user fields such as first name, last name, and salary, department.
  • DELETE /users/{id}: Deletes a user.

Department Statistics

  • GET /departments/averageSalary: Retrieves the average salary per department.

Security

The API endpoints are secured using JWT token authentication. To access the protected endpoints, you need to include the JWT token in the request headers.

Database Schema

The database schema includes the following tables:

  • department: Stores department information.
  • auth_user: Stores user information.
  • auth_role: Stores user roles.
  • auth_user_role: Represents the many-to-many relationship between users and roles.

Running the Tests

Unit tests are available for the application. To run the tests, execute the following command:

mvn test

Contact

For any inquiries or questions, please contact Tolga Aksoy.


This README provides a brief overview of the User Management API. For more detailed documentation, please refer to the codebase and API documentation generated by Swagger.

Swagger documentation is available at http://localhost:8080/api/v3/api-docs/swagger-ui/index.html.