-
Clone the repository:
Use the following command to clone the repository:git clone https://github.com/fmahadyBD/dream-shop.git
-
Set up the database:
Follow these steps to configure your database:- Start the MySQL database server.
- The database will be automatically created.
- If MySQL is running on a port other than
3306
, update the port in the configuration. - Ensure the correct database username and password are set in the
application.properties
file:spring.datasource.url=jdbc:mysql://localhost:3305/shopping-card?createDatabaseIfNotExist=true spring.datasource.username=root spring.datasource.password=
-
Navigate to the project directory:
cd dream-shop
-
Start the Spring Boot application:
Use Maven to run the application:mvn spring-boot:run
-
Test the endpoints:
Test the application's endpoints using tools like Postman or curl.
-
Endpoint:
POST http://localhost:8080/registration
-
Description:
Adds a new user to the system. -
Request Body:
{ "first_name": "Mahady Hasan", "last_name": "Fahim", "email": "fmahadybd@gmail.com", "password": "12345", "userRole": "ADMIN" }
-
Response:
-
Success:
HTTP Status:200 OK
{ "message": "Added new user", "data": { "userid": 2, "first_name": "Mahady Hasan", "last_name": "Fahim", "email": "fmahadybd@gmail.com", "password": "$2a$10$IhDAzGDF7TtZgXrfqfwJM.qZs0fIQUjPeV0JR4ugJxYP7QXDkqHsq", "userRole": "ADMIN" } }
-
Error:
HTTP Status:400 Bad Request
{ "error": "Validation error", "details": "Email is already in use" }
-
-
Endpoint:
POST http://localhost:8080/authenticate
-
Description:
Authenticates an existing user. -
Request Body:
{ "email": "fmahady01@gmail.com", "password": "12345" }
-
Response:
-
Success:
HTTP Status:200 OK
{ "token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJmbWFoYWR5MDFAZ21haWwuY29tIiwiaWF0IjoxNzMyNDAxMzk5LCJleHAiOjE3MzI0MDE0MTl9.VrX0t8oqmbMqMzIjjUDcyUoZo-2HuaFUc-m3y7OiAra0SM4-xIKNhDc6Wyt32se5qp870KZ8ts2wyDYpp8cJpg" }
-
Error:
HTTP Status:403 Forbidden
{ "error": "Invalid credentials" }
-
- The
password
field is hashed using BCrypt when stored in the database. - Role-based access control is implemented via the
userRole
field (ADMIN
,USER
,MODERATOR
). - Use the authentication token from the login response to access protected routes.
-
Endpoint:
POST http://localhost:8080/admin/api/v1/categories/add
-
Authentication:
Set the Bearer Token from the authentication response. -
Request Body:
{ "name": "Art" }
-
Response:
- Success:
HTTP Status:200 OK
{ "message": "Add Category Successfully", "data": { "id": 1, "name": "Art" } }
- Success:
-
Endpoint:
GET http://localhost:8080/admin/api/v1/categories/all
-
Authentication:
Set the Bearer Token from the authentication response. -
Response:
HTTP Status:200 OK
{ "message": "Found", "data": [ { "id": 1, "name": "Art" } ] }
-
Endpoint:
GET http://localhost:8080/admin/api/v1/categories/category/id/{id}
-
Response:
HTTP Status:200 OK
{ "message": "Found", "data": { "id": 2, "name": "Art" } }
-
Endpoint:
GET http://localhost:8080/admin/api/v1/categories/category/name/{name}
-
Response:
HTTP Status:200 OK
{ "message": "Found", "data": { "id": 2, "name": "Art" } }
-
Endpoint:
PUT http://localhost:8080/admin/api/v1/categories/category/update/id/{id}
-
Request Body:
{ "name": "The Art Color" }
-
Response:
-
Success:
HTTP Status:200 OK
{ "message": "Update Category Successfully", "data": { "id": 2, "name": "The Art Color" } }
-
Error:
HTTP Status:404 Not Found
{ "message": "Category Not Found!", "data": null }
-
-
Endpoint:
DELETE http://localhost:8080/admin/api/v1/categories/category/delete/id/{id}
-
Response:
-
Success:
HTTP Status:200 OK
{ "message": "Delete Category Successfully", "data": null }
-
Error:
HTTP Status:404 Not Found
{ "message": "Category Not Found!", "data": null }
-
URL: http://localhost:8080/admin/api/v1/products/add
Method: POST
{
"name": "Laptop",
"price": 1200.00,
"brand": "Dell",
"inventory": 50,
"description": "High-performance Dell Laptop",
"category": {
"name": "Electronics"
}
}
Note: If the category with the specified name does not exist in the database, a new category will be created.
{
"message": "Error",
"data": "Cannot invoke \"com.fahim.shoppingcard.model.Category.getName()\" because the return value of \"com.fahim.shoppingcard.request.AddProductRequest.getCategory()\" is null"
}
{
"message": "Added new Product",
"data": {
"id": 1,
"name": "Laptop",
"price": 1200.00,
"brand": "Dell",
"inventory": 50,
"description": "High-performance Dell Laptop",
"category": {
"id": 102,
"name": "Electronics"
},
"images": []
}
}
URL: http://localhost:8080/admin/api/v1/products/all
Method: GET
{
"message": "Found!",
"data": [
{
"id": 1,
"name": "Laptop",
"price": 1200.00,
"brand": "Dell",
"inventory": 50,
"description": "High-performance Dell Laptop",
"images": []
}
]
}
URL: http://localhost:8080/admin/api/v1/products/product/id/{id}
Method: GET
URL: http://localhost:8080/admin/api/v1/products/product/id/1
Response:
{
"message": "Found!",
"data": {
"id": 1,
"name": "Laptop",
"price": 1200.00,
"brand": "Dell",
"inventory": 50,
"description": "High-performance Dell Laptop",
"images": []
}
}