The Rocket Food Delivery API is a comprehensive service designed for managing food delivery operations. This project implements a RESTful API for handling various aspects of food delivery, including restaurants, orders, products, and users.
src/main/java/com/rocketFoodDelivery/rocketFood/
controller/- REST API controllersdtos/- Data Transfer Objects for API responses and requestsexception/- Custom exception classesmodels/- Domain models representing entities in the applicationrepository/- Repository interfaces for database interactionssecurity/- Security configurations and JWT utility classesservice/- Service layer components for business logicutil/- Utility classes, such as the ResponseBuilder
src/main/resources/
application.properties- Configuration for the applicationtemplates/- HTML templates for the frontend
src/test/resources/
application-test.properties- Configuration for test environments
src/test/java/com/rocketFoodDelivery/rocketFood/
api/- Tests for the API controllers
target/ - Compiled classes and build artifacts
-
Clone the repository:
git clone https://github.com/your-repo/rocket-food-delivery.git cd rocket-food-delivery -
Install dependencies:
Ensure you have Maven installed. Run:
mvn install
-
Set Up MySQL
1. Install MySQL:
- Download and install MySQL from MySQL's official website.
- Follow the installation instructions to complete the setup.
2. Create a Database:
Open a terminal or command prompt and log in to MySQL:
mysql -u root -p
Create a new database for your application:
CREATE DATABASE rdelivery;
3. Configure MySQL User:
Create a user and grant permissions to the new database:
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON rdelivery.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
Replace
your_usernameandyour_passwordwith your desired username and password. -
Configure the Application:
Update the
application.propertiesfile insrc/main/resources/with the MySQL connection details:spring.datasource.url=jdbc:mysql://localhost:3306/rdelivery spring.datasource.username=your_username spring.datasource.password=your_password spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true hibernate.hbm2ddl.auto=update hibernate.show_sql=true logging.level.root=INFO logging.level.com.rocketFoodDelivery=DEBUG logging.level.org.hibernate.SQL=DEBUG spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.cache=false app.jwt.secret="your_jwt_secret"
Replace
your_username,your_password, andyour_jwt_secretwith your credentials and secret key. -
Run the Application:
Start the Spring Boot application as usual. The application will connect to the MySQL database using the configured settings.
./mvnw spring-boot:run
-
POST /api/auth/loginRequest Body:
{ "email": "user@example.com", "password": "yourpassword" }
-
POST /api/restaurantsRequest Body:
{ "user_id": 1, "name": "Test Restaurant", "phone": "15141234567", "email": "test.restaurant@example.com", "price_range": 2, "address": { "street_address": "123 Test St.", "city": "Test City", "postal_code": "12345" } } -
GET /api/restaurants?price_range=3&rating=4 -
GET /api/restaurants -
GET /api/restaurants/{id} -
PUT /api/restaurants/{id}Request Body:
{ "user_id": 2, "name": "Updated Restaurant", "price_range": 3 } -
DELETE /api/restaurants/{id}
-
POST /api/orderRequest Body:
{ "restaurant_id": 1, "customer_id": 2, "order_date": "2024-08-01T12:00:00Z", "items": [ { "product_id": 1, "quantity": 2 } ] } -
GET /api/order/{id} -
PUT /api/order/{id}Request Body:
{ "status": "Completed" } -
DELETE /api/order/{id}
-
POST /api/productsRequest Body:
{ "restaurant_id": 1, "name": "Test Product", "description": "A delicious test product.", "price": 12.99 } -
GET /api/products -
GET /api/products/{id} -
PUT /api/products/{id}Request Body:
{ "name": "Updated Product", "price": 14.99 } -
DELETE /api/products/{id}
-
POST /api/usersRequest Body:
{ "name": "Test User", "email": "test.user@example.com", "password": "yourpassword" } -
GET /api/users/{id} -
PUT /api/users/{id}Request Body:
{ "name": "Updated User" } -
DELETE /api/users/{id}
To run the tests, use the following command:
mvn testAdd an application-test.properties file in src/test/resources/ with the following content:
spring.datasource.url=jdbc:mysql://localhost:3306/rdelivery_test
spring.datasource.username=test_username
spring.datasource.password=test_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
hibernate.hbm2ddl.auto=create-drop
hibernate.show_sql=true
logging.level.root=INFO
logging.level.com.rocketFoodDelivery=DEBUG
logging.level.org.hibernate.SQL=DEBUGReplace test_username and test_password with appropriate test database credentials.
- Spring Boot for the framework.
- MySQL for the database.
- CodeBoxx Academy