السَّلامُ عَلَيْكُم ورَحْمَةُ اللهِ وَبَرَكاتُهُ
Assalaam-Alaikum
Welcome to the Rental Car Agency application! This is a REST API service built with the Spring Boot framework,
that allows you to perform CRUD operations on a car rental database.
This application is designed to demonstrate how to build a simple Spring Boot application that interacts with a MySQL
database and provides RESTful endpoints for client-side communication.
The following technologies were used to build this application:
✅ Java 17
✅ Spring Boot 3
✅ Spring Data JPA
✅ MySQL
✅ Flyway
✅ JUnit
✅ Mockito
✅ Maven
✅ IntelliJ IDEA
✅ Postman
-
Having Java 17 or later installed.
You can download it from Oracle's website. -
Having MySQL DataBase installed, or you can fire up an instance of MySQL using the docker-compose file provided in the project.
Install MySQL from MySQL's website. -
Having a Client-Side application to communicate with the REST API endpoints.
Install Postman from Postman's website.
- Clone this repository to your local machine using this
command :
git clone https://github.com/NidhalNaffati/Rental-Car-Agency.git
- Import the project into your IDE (such as IntelliJ IDEA or Eclipse).
- Open the
application.yml
file located insrc/main/resources/
and update the database credentials with your own.
spring:
datasource:
url: jdbc:mysql://localhost:3306/RentalCarDB?createDatabaseIfNotExist=true
username: MYSQL_USERNAME
password: MYSQL_PASSWORD
- Run the application as a Spring Boot application, or using the Maven plugin
mvn spring-boot:run
.
After running the application, you can use Postman to communicate with the REST API endpoints.
Each endpoint expects a specific input format and returns a specific output format.
If you want to test it out in Postman, you can import the collections located in src/test/postman/
The following endpoints are available in the API:
HTTP Method | Endpoint | Request Body | Response Body | Description |
---|---|---|---|---|
POST |
/api/v1/cars |
Car |
Car |
Create a new car |
PUT |
/api/v1/cars/{id} |
Car |
Car |
Update an existing car by id |
DELETE |
/api/v1/cars/{id} |
- | - | Delete an existing car by id |
GET |
/api/v1/cars/{id} |
- | Car |
Get an existing car by id |
GET |
/api/v1/cars |
- | List<Car> |
Get a list of all cars |
GET |
/api/v1/cars?registrationNumber={registrationNumber} |
- | Car |
Get a car by registrationNumber |
GET |
/api/v1/cars?carName={carName} |
- | List<Car> |
Get a list of cars by carName |
GET |
/api/v1/cars?model={model} |
- | List<Car> |
Get a list of cars by model |
GET |
/api/v1/cars?kilometre={kilometre}&lesser |
- | List<Car> |
Get a list of cars with kilometres lesser than or equal to kilometre |
GET |
/api/v1/cars?kilometre={kilometre}&greater |
- | List<Car> |
Get a list of cars with kilometres greater than or equal to kilometre |
HTTP Method | Endpoint | Request Body | Response Body | Description |
---|---|---|---|---|
POST |
/api/v1/customers |
Customer |
Customer |
Create a new customer |
PUT |
/api/v1/customers/{id} |
Customer |
Customer |
Update an existing customer by id |
DELETE |
/api/v1/customers/{id} |
- | - | Delete an existing customer by id |
GET |
/api/v1/customers/{id} |
- | Customer |
Get an existing customer by id |
GET |
/api/v1/customers |
- | List<Customer> |
Get a list of all customers |
GET |
/api/v1/customers?name={email} |
- | Customer |
Get a customer by email |
GET |
/api/v1/customers?name={name} |
- | List<Customer> |
Get a list of customers by name |
HTTP Method | Endpoint | Request Body | Response Body | Description |
---|---|---|---|---|
POST |
/api/v1/dealers |
Dealer |
Dealer |
Create a new Customer |
PUT |
/api/v1/dealers/{id} |
Dealer |
Dealer |
Update an existing dealer by id |
DELETE |
/api/v1/dealers/{id} |
- | - | Delete an existing dealer by id |
GET |
/api/v1/dealers/{id} |
- | Dealer |
Get an existing dealer by id |
GET |
/api/v1/dealers |
- | List<Dealer> |
Get a list of all dealers |
GET |
/api/v1/dealers?name={email} |
- | Dealer |
Get a dealers by email |
GET |
/api/v1/dealers?name={name} |
- | List<Dealer> |
Get a list of dealers by name |
HTTP Method | Endpoint | Request Body | Response Body | Description |
---|---|---|---|---|
POST |
/api/v1/transactions |
Transaction |
Transaction |
Create a new Transaction |
GET |
/api/v1/transactions |
- | List<Transaction> |
Get a list of all transactions |
In this project, I learned how to build a REST API using Spring Boot and how to use Spring Data JPA to interact with a MySQL database.
- Spring Boot 3 basics and how to use it to build a REST API.
- Following the RESTful API design principles.
- Using Spring Data JPA to interact with a MySQL database.
- Flyway for database migrations.
- Server and Client Side Error Handling.
- Validating user inputs or JSON object using Spring Boot Validation.
- Unit Testing using JUnit and Mockito.
- Integration Testing using Spring Boot Test.
- Dealing with Data using Spring Data JPA.
- Fetching data using a GET api.
- Sending data from a FORM using a POST api.
- Editing an existing object using a PUT api
- Deleting an existing product using a DELETE api
- Fork this repository to your GitHub account.
- Clone the forked repository to your local machine.
- Create a new branch for your changes.
- Make your changes and commit them with descriptive commit messages.
- Push your changes to your GitHub account.
- Create a pull request from your branch to the original repository's main branch.
- Wait for the maintainers to review and merge your changes.
When making contributions, please keep the following in mind:
- Follow the code style and formatting guidelines used in the project.
- Write clear and concise commit messages that explain the changes you made.
- Make sure your changes do not break existing functionality.
- Write tests for new code and ensure that all existing tests pass.
You are allowed to use, copy, modify, and distribute the code freely, just don't create a bomb or something like that xD