A simple CRUD (Create, Read, Update, Delete) API project for managing employee records.

This project provides a RESTful API for basic CRUD operations on an employee database. It leverages the following technologies:
- Spring Boot for building robust and scalable applications.
- Spring Data JPA for easy data access with Hibernate.
- MySQL for data storage and retrieval.
- OpenCSV for CSV parsing.
- Project Lombok for reducing boilerplate code in Java.
- JUnit for unit testing.
- Mockito for mocking objects in tests.
- Redis for caching and improving requests performance.
- OpenApi for documentation generation.
- Ensure you have Java 17, Maven and Redis (for caching) installed.
- Clone this repository.
- Configure your MySQL database details in the application.properties file.
- By default, the database is set to localhost:3036 with root as both the username and password. The database should be created using the sql script inside the "sql-scripts" folder.
- Go to the repository's location
- Run Redis server
- Open a terminal and run the following command to start the Redis server. You can change the port Redis will use in application.properties. By default, it's 6484.
Or add the following to the application.properties file to disable cache.
redis-server --port 6484
-
spring.cache.type=none
- Open a terminal and run the following command to start the Redis server. You can change the port Redis will use in application.properties. By default, it's 6484.
- Run the application using Maven:
mvn spring-boot:run
- Get your token by making a POST request to http://localhost:8080/token with with basic authentication using the username "eren" and password "password". You can use tools like cURL or Postman.
The JWT implementation in this project is for educational purposes only. The user "eren" is an in-memory user, and the public and private keys are exposed for demonstration purposes. In a production environment, secure practices should be followed for user authentication and key management.
This is important! While the following documentation is still right, you can better read (and interact) with the swagger documentation for the API at http://localhost:8080/swagger-ui/index.html
The API adheres to REST principles, making it intuitive to interact with. For example, to retrieve information about an employee with ID 1, simply make a GET request to:
GET localhost:8080/employee/1For updating or deleting an employee with a specific ID (employee_id), use the corresponding request to:
PUT or DELETE localhost:8080/employees/{employee_id}When updating, remember to include the employee details in JSON format, specifying the firstName, lastName, and email properties.
To interact with the API, you can use external tools like Postman for POST, PUT, and DELETE requests. Alternatively, for a more user-friendly experience, consider using the version available in crudMVCDemo. It's an MVC CRUD web app that provides a graphical UI for adding, deleting, or updating employees, yet this version is more developed.
If you want to customize the number of employees displayed or control the page size when retrieving all employees (GET URL /employees), you can use query parameters. For example:
GET http://localhost:8080/employees?size=3By default, the page size is set to 10 and cannot exceed 100. Feel free to adjust the query parameters according to your preferences.