Skip to content

This backend is designed to manage products, reviews, orders, subscriptions and promocodes for the Chocolate Euphoria online store. It uses Node.js and Express.js to handle queries, stores data in MongoDB, and provides interactive API documentation through the Swagger UI.

Notifications You must be signed in to change notification settings

KristinaHranovska/chocolate-euphoria-backend

Repository files navigation

Chocolate Euphoria Backend

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.

Table of Contents

Installation

  1. Clone the repository:
    git clone https://github.com/KristinaHranovska/chocolate-euphoria-backend.git
    cd chocolate-euphoria-backend
  2. Install dependencies:
    npm install
  3. Create a .env file in the root directory and add your environment variables (see Environment Variables section).
  4. Start the server:
    npm run dev
    The server will run on http://localhost:3000.

Usage

To interact with the API, you can use tools like Postman or cURL. Below are the available routes and their descriptions.

API Documentation

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

Routes

Products

  • 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.

Reviews

  • 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

  • Subscribe a user by email
POST /subscribe

Request body:

{
  "email": "[email protected]"
}

Promocodes

  • 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
}

Order

  • 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"
}

Environment Variables

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.

Contributing

If you would like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add some feature').
  5. Push to the branch (git push origin feature-branch).
  6. Create a new Pull Request.

Deployment

The code is deployed using render.com. You can access the deployed application at:

https://chocolate-euphoria-backend.onrender.com

About

This backend is designed to manage products, reviews, orders, subscriptions and promocodes for the Chocolate Euphoria online store. It uses Node.js and Express.js to handle queries, stores data in MongoDB, and provides interactive API documentation through the Swagger UI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published