Hassaanjbaig-code / E_X-Backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ•ΉοΈπŸ•ΉοΈ E X API πŸ•ΉοΈπŸ•ΉοΈ


logo

πŸ“— Table of Contents

πŸ“– [E_X-api]

[E X APi] is the backend application for the ECommerce website where the user can add the products update and delete a products. If the user like the product he/she can add to cart it show much qunatity they need. The user login and log out by the Token base Authentication.

Tech Stack

Key Features

  • [User Registration and Authentication]
  • [When the user adds a product to the cart with a certain quantity, the quantity of the product also decreases.]
  • [Add Active Storage to store the image of the product.]

(back to top)

πŸš€ Resources

There are 4 main resources need in ECommerence prototypes:

(back to top)

## How to

you can fetch data with any kind of methods you know(fetch API, Axios, jquery ajax,...)

Get all products

fetch("http://127.0.0.1:3001/api/v1/products")
  .then((res) => res.json())
  .then((json) => console.log(json));

Get a single product

fetch("http://127.0.0.1:3001/api/v1/products/1")
  .then((res) => res.json())
  .then((json) => console.log(json));

Add new product

fetch("http://127.0.0.1:3001/api/v1/products", {
  method: "POST",
  body: JSON.stringify({
    title: "test product",
    price: 13.5,
    description: "test Description",
    image: "Add a File",
    category: "electronic",
  }),
})
  .then((res) => res.json())
  .then((json) => console.log(json));

/* will return
{
 id:31,
 title:'...',
 price:'...',
 category:'...',
 description:'...',
 image:'...'
 quantity: '....'
}
*/

Note: Posted data will not really insert into the database and just return a fake id.

Updating a product

fetch("http://127.0.0.1:3001/api/v1/products/7", {
  method: "PUT",
  body: JSON.stringify({
    title: "test product",
    price: 13.5,
    description: "lorem ipsum set",
    image: "File",
    category: "electronic",
    quantity: '12'
  }),
})
  .then((res) => res.json())
  .then((json) => console.log(json));

/* will return
{
    id:7,
    title: 'test product',
    price: 13.5,
    description: 'lorem ipsum set',
    image: 'https://i.pravatar.cc',
    category: 'electronic'
    quantity: '12'
}
*/

Deleting a product

```js
fetch("http://127.0.0.1:3001/api/v1/products/8", {
  method: "DELETE",
});

Nothing will delete on the database.

All available routes

Products

fields:
{
    id:Number,
    title:String,
    price:Number,
    category:String,
    description:String,
    image:file
    quantity: String
}

GET:

- /products (get all products)
- /products/1 (get specific product based on id)
- /products (Creating a Product)
- /products/1 (Deleting a Products)
- /products/1 (Updating a Products)

Carts

fetch("http://127.0.0.1:3001/api/v1/carts", {
  method: "PUT",
  body: JSON.stringify({
    total_price: 56
    quantity: '12'
  }),
})
  .then((res) => res.json())
  .then((json) => console.log(json));

/* will return
{
    id:1,
    total_price: 56
    quantity: '12'
    created_at: date
    update_at: date
}
*/

GET:

  • /carts
  • /carts/1

// Cart display only the user cart which user selected

POST:

  • /carts

PATCH:

  • /carts/1

DELETE:

  • /carts/1

Users

Creating a user

fetch("http://127.0.0.1:3001/api/v1/user", {
  method: "POST",
  body: JSON.stringify({
    name: 'test',
    email: 'test@example.com',
    passoword: 'Test1122'
  }),
})
  .then((res) => res.json())
  .then((json) => console.log(json));

/* will return
{
    id:1,
    name: 'test',
    email: 'test@example.com',
    passoword: 'Test1122'
}
*/

See the current user

/me

Auth

fields:
{
    email:String,
    password:String
}

POST:

  • /login

πŸ’» Getting Started

To get a local copy up and running, follow these steps.

Prerequisites

In order to run this project you need:

  1. git use the following link to setup git if you dont have it already installed on your computer

(install git)

  1. Ruby use the following link to setup Ruby if you dont have it already installed on your computer

(install Ruby)

  1. Rails use the following link to setup Rails if you dont have it already installed on your computer

(install Ruby)

  1. PostgreSQL use the following link to setup PostgreSQL if you dont have it already installed on your computer

(install PostgreSQL)

Setup

Clone this repository to your desired folder:

  git clone https://github.com/Hassaanjbaig-code/E_X-Backend.git

Install dependencies:

  cd E_X-Backend
  bundle install

Database

Edit config/database.yml with your database connection info. Run the foolowing command

    rails db:create
    rails db:schema:load

Usage

The following command can be used to run the application.

  rails s

(back to top)

πŸ‘₯ Authors

πŸ‘€ Hassaan Baig

πŸ”­ Future Features

  • [Add Admin dashboard]
  • [Add payment system]

(back to top)

🀝 Contributing

Contributions, issues, and feature requests are welcome!

Feel free to check the issues page.

(back to top)

⭐️ Show your support

If you like this project, please don't forget to follow the contributors and give it a star.

(back to top)

πŸ“ License

This project is MIT licensed.

(back to top)

About


Languages

Language:Ruby 99.4%Language:HTML 0.6%