ecommerce_backend

Built an e-commerce backend system for managing users, products, orders, and more. It uses HonoJS, TypeScript, Prisma, and PostgreSQL to provide a secure and scalable RESTful API.

MIT License

Stars
0
Committers
2

eCommerce Backend System

Welcome to the eCommerce Backend System. This application provides a RESTful API for managing users, products, categories, orders, carts, payments, and reviews.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/venkateshramkumarg/ecommerce_backend.git
    cd ecommerce-backend
    
  2. Install dependencies:

    npm install
    
  3. Set up the database using Prisma:

    npx prisma migrate dev
    
  4. Start the application:

    npm start
    

Usage

The application runs on http://localhost:3000/api. You can use tools like Postman or curl to interact with the API.

API Endpoints

Admin

  • Create Admin

    POST /api/admin/create/admin/new
    

    Request Body:

    {
      "user_name": "admin_name",
      "password": "password",
      "email": "[email protected]"
    }
    
  • Delete Admin

    DELETE /api/admin/delete/admin/:name
    
  • Update Admin

    PUT /api/admin/update/admin/:name
    

    Request Body:

    {
      "password": "new_password",
      "email": "[email protected]"
    }
    

Users

  • Create User

    POST /api/users/create/user/new
    

    Request Body:

    {
      "user_name": "user_name",
      "password": "password",
      "email": "[email protected]"
    }
    
  • Delete User

    DELETE /api/users/delete/user/:name
    
  • Update User

    PUT /api/users/update/user/:name
    

    Request Body:

    {
      "password": "new_password",
      "email": "[email protected]"
    }
    

Products

  • Create Product

    POST /api/products/addproduct
    

    Request Body:

    {
      "user_name": "admin_name",
      "productName": "product_name",
      "description": "product_description",
      "price": "product_price",
      "stock": "product_stock",
      "categoryId": "category_id"
    }
    
  • Delete Product

    DELETE /api/products/deleteproduct/:id
    
  • Update Product

    PUT /api/products/updateproduct/:id
    

    Request Body:

    {
      "productName": "new_product_name",
      "description": "new_product_description",
      "price": "new_product_price",
      "stock": "new_product_stock",
      "categoryId": "new_category_id"
    }
    
  • Get All Products

    GET /api/products/allproducts
    
  • Get Product by ID

    GET /api/products/uniqueproduct/:id
    

Categories

  • Create Category

    POST /api/categories/add/category
    

    Request Body:

    {
      "user_name": "admin_name",
      "categoryName": "category_name"
    }
    
  • Delete Category

    DELETE /api/categories/delete/category/:id
    
  • Update Category

    PUT /api/categories/update/category/:id
    

    Request Body:

    {
      "categoryName": "new_category_name"
    }
    
  • Get All Categories

    GET /api/categories/allcategories
    
  • Get Category by ID

    GET /api/categories/uniquecategory/:id
    

Orders

  • Create Order

    POST /api/orders/create/order
    

    Request Body:

    {
      "user_name": "user_name",
      "productIds": ["product_id1", "product_id2"],
      "totalAmount": "total_amount",
      "shippingAddress": "shipping_address"
    }
    
  • Delete Order

    DELETE /api/orders/delete/order/:id
    
  • Update Order

    PUT /api/orders/update/order/:id
    

    Request Body:

    {
      "status": "new_status"
    }
    
  • Get All Orders

    GET /api/orders
    
  • Get Order by ID

    GET /api/orders/:id
    

Carts

  • Add to Cart

    POST /api/carts/addtocart
    

    Request Body:

    {
      "user_name": "user_name",
      "productId": "product_id",
      "quantity": "quantity"
    }
    
  • Delete from Cart

    DELETE /api/carts/removefromcart/:id
    
  • Get User's Cart

    GET /api/carts/user/:name
    

Payments

  • Process Payment

    POST /api/payments/processpayment
    

    Request Body:

    {
      "user_name": "user_name",
      "orderId": "order_id",
      "paymentMethod": "payment_method"
    }
    
  • Get Payment Details

    GET /api/payments/paymentdetails/:paymentid
    

Reviews

  • Add Review

    POST /api/reviews/addreview
    

    Request Body:

    {
      "user_name": "user_name",
      "productId": "product_id",
      "rating": "rating",
      "comment": "comment"
    }
    
  • Delete Review

    DELETE /api/reviews/deletereview/:id
    
  • Update Review

    PUT /api/reviews/updatereview/:id
    

    Request Body:

    {
      "rating": "new_rating",
      "comment": "new_comment"
    }
    
  • Get Reviews for Product

    GET /api/reviews/product/:id
    

Environment Variables

Create a .env file in the root directory and add the following environment variables:

DATABASE_URL="your-database-url"
Related Projects