Chocolate Euphoria Backend
is a RESTful API built with Node.js
and Express.js
, designed to manage products, reviews, subscriptions, and promocodes for a chocolate store.
- Clone the repository:
git clone https://github.com/KristinaHranovska/chocolate-euphoria-backend.git cd chocolate-euphoria-backend
- Install dependencies:
npm install
- Create a
.env
file in the root directory and add your environment variables (see Environment Variables section). - Start the server:
The server will run on
npm run dev
http://localhost:3000
.
To interact with the API, you can use tools like Postman
or cURL
. Below are the available routes and their descriptions.
The API is documented using Swagger
. After starting the server, you can access the Swagger UI
at:
https://chocolate-euphoria-backend.onrender.com/api-docs
-
Get all products
GET /products
Response:
[
{
"_id": "665b04985a6b6fa18a935f59",
"productName": "Lime & Sea Salt dark chocolate",
"category": "Dark chocolate",
"price": "66 UAH",
"description": "Sea salt and chocolate is a unique combination that has completely taken...",
"compound": [
"Sustainably grown chocolate",
"Palm oil free & all natural ingredients",
"Recyclable packaging",
"Proudly made in York, North Yorkshire",
"Registered with The Vegan Society"
],
"photo": "https://res.cloudinary.com/dntbkzhtq/image/upload/v1715618947/limeAmdS..."
}
]
-
Get a product by ID
GET /products/:id
Parameters:
id
(string): The ID of the product.
- Get all reviews
GET /reviews
Response:
[
{
"_id": "665b04985a6b6fa18a935f59",
"name": "John Doe",
"email": "[email protected]",
"phone": "(12) 345-6789",
"comment": "Great chocolate! Highly recommend."
}
]
- Create a new review
POST /reviews
Request body:
{
"name": "John Doe",
"email": "[email protected]",
"phone": "(12) 345-6789",
"comment": "Great chocolate! Highly recommend."
}
- Subscribe a user by email
POST /subscribe
Request body:
{
"email": "[email protected]"
}
- Get a random promocode
GET /promocodes
Request body:
{
"promocode": "SAVE10",
"percent": 10
}
- Check a promocode
POST /promocodes/check
Request body:
{
"promocode": "SAVE10"
}
Response:
{
"promocode": "SAVE10",
"percent": 10
}
- Create a new order
POST /order
Request body:
{
"userContact": {
"firstName": "John",
"lastName": "Doe",
"phone": "12-345-6789",
"email": "[email protected]",
"selectRegion": "Some Region",
"selectCity": "Some City",
"comment": "Please deliver between 9 AM to 5 PM"
},
"order": [
{
"nameProduct": "Lime & Sea Salt dark chocolate",
"photo": "https://res.cloudinary.com/dntbkzhtq/image/upload/v1715618947/limeAmdS...",
"quantity": 2,
"total": "132 UAH"
}
],
"totalPrice": 132,
"discount": 0,
"status": "Order accepted"
}
Create a .env
file in the root directory of your project and add the following environment variables:
DB_HOST=your_mongodb_connection_string
PORT=3000
Replace your_mongodb_connection_string
with your actual MongoDB connection string.
If you would like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.
The code is deployed using render.com. You can access the deployed application at:
https://chocolate-euphoria-backend.onrender.com