Skip to content

V3DxNT/GDG-26-BackEnd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Food Ordering Backend API

A RESTful API for a food ordering application built with Node.js, Express, MongoDB, and Cloudinary for image uploads.

Features

  • JWT Authentication with HTTP-only cookies
  • Role-based access (User, Restaurant Owner, Admin)
  • Restaurant and menu management
  • Shopping cart functionality
  • Order management with status tracking
  • Image uploads via Cloudinary
  • Restaurant analytics and user order history

Tech Stack

  • Node.js + Express.js
  • MongoDB + Mongoose
  • JWT Authentication
  • Cloudinary (Image uploads)
  • bcryptjs (Password hashing)

Quick Start

  1. Install dependencies

    npm install
  2. Environment Setup

    Create .env file:

    PORT=5000
    NODE_ENV=development
    MONGODB_URI=mongodb://localhost:27017/food_ordering_db
    JWT_SECRET=your_jwt_secret
    JWT_EXPIRE=7d
    JWT_COOKIE_EXPIRE=7
    COOKIE_SECRET=your_cookie_secret
    CLOUDINARY_CLOUD_NAME=your_cloud_name
    CLOUDINARY_API_KEY=your_api_key
    CLOUDINARY_API_SECRET=your_api_secret
  3. Start the server

    npm run dev  # Development
    npm start    # Production

API Endpoints

Authentication

  • POST /api/auth/register - Register user
  • POST /api/auth/login - Login user
  • POST /api/auth/logout - Logout user
  • GET /api/auth/me - Get current user

Restaurants

  • GET /api/restaurants - Get all restaurants
  • GET /api/restaurants/:id - Get single restaurant
  • POST /api/restaurants - Create restaurant (Restaurant role)

Foods

  • GET /api/foods - Get all foods
  • GET /api/foods/restaurant/my-dishes - Get restaurant's dishes
  • POST /api/foods - Add dish with images (Restaurant role)
  • PUT /api/foods/:id - Update dish
  • PATCH /api/foods/:id/price - Update price only
  • DELETE /api/foods/:id - Delete dish

Cart

  • GET /api/cart - Get cart
  • POST /api/cart/add - Add to cart
  • PUT /api/cart/update/:itemId - Update cart item
  • DELETE /api/cart/remove/:itemId - Remove from cart

Orders

  • POST /api/orders - Place order
  • GET /api/orders - Get user orders
  • GET /api/orders/history - Order history with stats
  • GET /api/orders/restaurant/orders - Restaurant orders
  • GET /api/orders/restaurant/analytics - Restaurant analytics
  • PUT /api/orders/:id/status - Update order status

Order States

  • preparingpreparedcompleted
  • cancelled (only from preparing state)

User Roles

  • user - Browse and order food
  • restaurant - Manage restaurant and menu
  • admin - Full system access

Project Structure

├── server.js
├── package.json
├── .env
└── src/
    ├── app.js
    ├── config/
    ├── controllers/
    ├── middleware/
    ├── models/
    └── routes/

Scripts

npm start      # Start production server
npm run dev    # Start development server

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors