Giter Site home page Giter Site logo

estore-backend's Introduction

estore-backend

A Store REST API built with Express JS, MySQL and Sequelize

Video Demo

Contents

Local Installation End Points Credits

Local Installation

This projects is configured using Yarn 2 - https://yarnpkg.com/getting-started You may need to run yarn install twice to start the project successfully.

You will need to edit the .env.EXAMPLE to your local MySQL installation.

Setup the database from the db folder. Start MySQLSH and run the schema.sql file.

Once setup you should be able to start the server using yarn start.This will confirm if the database has correctly started.

If successful, you can open a new terminal and run yarn seed to populate the server with data for testing.

End Points

Postman Documentation link

End points for https://github.com/minusInfinite/estore-backend

Indices


Category

The end points for a completing CRUD actions against the Store's Category API

1. Add New

Add New

Add a New Category to the database. It will provide an ID

Endpoint:

Method: POST
Type: RAW
URL: http://localhost:3001/api/categories/

Body:

{
    "category_name": "mugs"
}

More example Requests/Responses:

I. Example Request: Add New

Body:

{
    "category_name": "mugs"
}

I. Example Response: Add New

{
    "id": 7,
    "category_name": "mugs"
}

Status Code: 200

2. Delete Category

Delete By ID

Delete a single categories in the database by the ID at the end of the URL.

Endpoint:

Method: DELETE
Type:
URL: http://localhost:3001/api/categories/9

More example Requests/Responses:

I. Example Response: Delete Category

"Deleted 9"

Status Code: 200

3. Get All

Get All

Get all categories in the database and related products.

Endpoint:

Method: GET
Type:
URL: http://localhost:3001/api/categories/

More example Requests/Responses:

I. Example Request: Get All

I. Example Response: Get All

[
    {
        "id": 1,
        "category_name": "Jumpers",
        "products": [
            {
                "id": 1,
                "product_name": "Plain T-Shirt",
                "price": 14.99,
                "stock": 14,
                "category_id": 1
            }
        ]
    },
    {
        "id": 2,
        "category_name": "Shorts",
        "products": [
            {
                "id": 5,
                "product_name": "Cargo Shorts",
                "price": 29.99,
                "stock": 22,
                "category_id": 2
            }
        ]
    },
    {
        "id": 3,
        "category_name": "Music",
        "products": [
            {
                "id": 4,
                "product_name": "Top 40 Music Compilation Vinyl Record",
                "price": 12.99,
                "stock": 50,
                "category_id": 3
            }
        ]
    },
    {
        "id": 4,
        "category_name": "Hats",
        "products": [
            {
                "id": 7,
                "product_name": "Basketball Cap",
                "price": 25,
                "stock": 10,
                "category_id": 4
            },
            {
                "id": 3,
                "product_name": "Branded Baseball Hat",
                "price": 22.99,
                "stock": 12,
                "category_id": 4
            }
        ]
    },
    {
        "id": 5,
        "category_name": "Shoes",
        "products": [
            {
                "id": 2,
                "product_name": "Running Sneakers",
                "price": 90,
                "stock": 25,
                "category_id": 5
            }
        ]
    }
]

Status Code: 200

4. Get by ID

Get By ID

Get a single categories in the database and related products by the ID at the end of the URL.

Endpoint:

Method: GET
Type:
URL: http://localhost:3001/api/categories/1

More example Requests/Responses:

I. Example Request: Get by ID

I. Example Response: Get by ID

{
    "id": 1,
    "category_name": "Jumpers",
    "products": [
        {
            "id": 1,
            "product_name": "Plain T-Shirt",
            "price": 14.99,
            "stock": 14,
            "category_id": 1
        }
    ]
}

Status Code: 200

5. Update Category

Update By ID

Update a single categories in the database by the ID at the end of the URL.

Endpoint:

Method: PUT
Type: RAW
URL: http://localhost:3001/api/categories/7

Body:

{
    "category_name": "Jumpers"
}

More example Requests/Responses:

I. Example Request: Update Category

Body:

{
    "category_name": "Jumpers"
}

I. Example Response: Update Category

{
    "message": "Jumpers Updated"
}

Status Code: 202

Product

1. Add New

Add New

Add a New Product to the database, while options you can provide a category ID and Tag IDs in an Array.

Endpoint:

Method: POST
Type: RAW
URL: http://localhost:3001/api/products/

Body:

{
    "product_name": "Basketball Cap",
    "price": 25.0,
    "stock": 10,
    "category_id": 4,
    "tagIds": [5]
}

More example Requests/Responses:

I. Example Request: Add New

Body:

{
    "product_name": "Basketball Cap",
    "price": 25.0,
    "stock": 10,
    "category_id": 4,
    "tagIds": [5]
}

I. Example Response: Add New

[
    {
        "id": 15,
        "productId": 8,
        "tagId": 5
    }
]

Status Code: 200

2. Delete Product

Delete By ID

Delete a single Product in the database by the ID at the end of the URL.

Endpoint:

Method: DELETE
Type:
URL: http://localhost:3001/api/products/9

More example Requests/Responses:

I. Example Request: Delete Product

I. Example Response: Delete Product

"Deleted 9"

Status Code: 200

3. Get All

Get All

Get all Products in the database and related categories and tags

Endpoint:

Method: GET
Type:
URL: http://localhost:3001/api/products/

More example Requests/Responses:

I. Example Request: Get All

I. Example Response: Get All

[
    {
        "id": 1,
        "product_name": "Plain T-Shirt",
        "price": 14.99,
        "stock": 14,
        "category_id": 1,
        "category": {
            "id": 1,
            "category_name": "Jumpers"
        },
        "tags": [
            {
                "id": 6,
                "tag_name": "white",
                "product_tag": {
                    "id": 1,
                    "product_id": 1,
                    "tag_id": 6,
                    "productId": 1,
                    "tagId": 6
                }
            },
            {
                "id": 7,
                "tag_name": "gold",
                "product_tag": {
                    "id": 2,
                    "product_id": 1,
                    "tag_id": 7,
                    "productId": 1,
                    "tagId": 7
                }
            },
            {
                "id": 8,
                "tag_name": "pop culture",
                "product_tag": {
                    "id": 3,
                    "product_id": 1,
                    "tag_id": 8,
                    "productId": 1,
                    "tagId": 8
                }
            }
        ]
    },
    {
        "id": 2,
        "product_name": "Running Sneakers",
        "price": 90,
        "stock": 25,
        "category_id": 5,
        "category": {
            "id": 5,
            "category_name": "Shoes"
        },
        "tags": [
            {
                "id": 6,
                "tag_name": "white",
                "product_tag": {
                    "id": 4,
                    "product_id": 2,
                    "tag_id": 6,
                    "productId": 2,
                    "tagId": 6
                }
            }
        ]
    },
    {
        "id": 3,
        "product_name": "Branded Baseball Hat",
        "price": 22.99,
        "stock": 12,
        "category_id": 4,
        "category": {
            "id": 4,
            "category_name": "Hats"
        },
        "tags": [
            {
                "id": 1,
                "tag_name": "rock music",
                "product_tag": {
                    "id": 5,
                    "product_id": 3,
                    "tag_id": 1,
                    "productId": 3,
                    "tagId": 1
                }
            },
            {
                "id": 3,
                "tag_name": "blue",
                "product_tag": {
                    "id": 6,
                    "product_id": 3,
                    "tag_id": 3,
                    "productId": 3,
                    "tagId": 3
                }
            },
            {
                "id": 4,
                "tag_name": "red",
                "product_tag": {
                    "id": 7,
                    "product_id": 3,
                    "tag_id": 4,
                    "productId": 3,
                    "tagId": 4
                }
            },
            {
                "id": 5,
                "tag_name": "green",
                "product_tag": {
                    "id": 8,
                    "product_id": 3,
                    "tag_id": 5,
                    "productId": 3,
                    "tagId": 5
                }
            }
        ]
    }
]

Status Code: 200

4. Get by ID

Get by ID

Get a single Product in the database and related categories and tags, with the ID number at the end of the URL

Endpoint:

Method: GET
Type:
URL: http://localhost:3001/api/products/1

More example Requests/Responses:

I. Example Request: Get by ID

I. Example Response: Get by ID

{
    "id": 1,
    "product_name": "Plain T-Shirt",
    "price": 14.99,
    "stock": 14,
    "category_id": 1,
    "category": {
        "id": 1,
        "category_name": "Jumpers"
    },
    "tags": [
        {
            "id": 6,
            "tag_name": "white",
            "product_tag": {
                "id": 1,
                "product_id": 1,
                "tag_id": 6,
                "productId": 1,
                "tagId": 6
            }
        },
        {
            "id": 7,
            "tag_name": "gold",
            "product_tag": {
                "id": 2,
                "product_id": 1,
                "tag_id": 7,
                "productId": 1,
                "tagId": 7
            }
        },
        {
            "id": 8,
            "tag_name": "pop culture",
            "product_tag": {
                "id": 3,
                "product_id": 1,
                "tag_id": 8,
                "productId": 1,
                "tagId": 8
            }
        }
    ]
}

Status Code: 200

5. Update Product

Update By ID

Update the tags on a single Product in the database by the ID at the end of the URL.

Endpoint:

Method: PUT
Type: RAW
URL: http://localhost:3001/api/products/1

Body:

{
    "tagIds": [5]
}

More example Requests/Responses:

I. Example Request: Update Product

Body:

{
    "tagIds": [5]
}

I. Example Response: Update Product

[
    3,
    [
        {
            "id": 16,
            "productId": "1",
            "tagId": 5
        }
    ]
]

Status Code: 200

Tags

1. Add New

Add New

Add a New Tag to the database. It will provide an ID

Endpoint:

Method: POST
Type: RAW
URL: http://localhost:3001/api/tags/

Body:

{
    "tag_name": "rock music"
}

More example Requests/Responses:

I. Example Request: Add New

Body:

{
    "tag_name": "rock music"
}

I. Example Response: Add New

{
    "id": 9,
    "tag_name": "rock music"
}

Status Code: 200

2. Delete Product

Delete By ID

Delete the Tag in the database by the ID at the end of the URL.

Endpoint:

Method: DELETE
Type:
URL: http://localhost:3001/api/tags/2

More example Requests/Responses:

I. Example Request: Delete Product

I. Example Response: Delete Product

"Deleted 2"

Status Code: 200

3. Get All

Get All

Get all Tags in the database and related categories and products

Endpoint:

Method: GET
Type:
URL: http://localhost:3001/api/tags/

More example Requests/Responses:

I. Example Request: Get All

I. Example Response: Get All

[
    {
        "id": 1,
        "tag_name": "rock music",
        "products": [
            {
                "id": 3,
                "product_name": "Branded Baseball Hat",
                "price": 22.99,
                "stock": 12,
                "category_id": 4,
                "product_tag": {
                    "id": 5,
                    "product_id": 3,
                    "tag_id": 1,
                    "productId": 3,
                    "tagId": 1
                }
            },
            {
                "id": 4,
                "product_name": "Top 40 Music Compilation Vinyl Record",
                "price": 12.99,
                "stock": 50,
                "category_id": 3,
                "product_tag": {
                    "id": 9,
                    "product_id": 4,
                    "tag_id": 1,
                    "productId": 4,
                    "tagId": 1
                }
            }
        ]
    },
    {
        "id": 2,
        "tag_name": "pop music",
        "products": [
            {
                "id": 4,
                "product_name": "Top 40 Music Compilation Vinyl Record",
                "price": 12.99,
                "stock": 50,
                "category_id": 3,
                "product_tag": {
                    "id": 10,
                    "product_id": 4,
                    "tag_id": 2,
                    "productId": 4,
                    "tagId": 2
                }
            }
        ]
    },
    {
        "id": 3,
        "tag_name": "blue",
        "products": [
            {
                "id": 3,
                "product_name": "Branded Baseball Hat",
                "price": 22.99,
                "stock": 12,
                "category_id": 4,
                "product_tag": {
                    "id": 6,
                    "product_id": 3,
                    "tag_id": 3,
                    "productId": 3,
                    "tagId": 3
                }
            },
            {
                "id": 5,
                "product_name": "Cargo Shorts",
                "price": 29.99,
                "stock": 22,
                "category_id": 2,
                "product_tag": {
                    "id": 12,
                    "product_id": 5,
                    "tag_id": 3,
                    "productId": 5,
                    "tagId": 3
                }
            }
        ]
    }
]

Status Code: 200

4. Get by ID

Get by ID

Get a single Tag in the database and related categories and products, with the ID number at the end of the URL

Endpoint:

Method: GET
Type:
URL: http://localhost:3001/api/tags/1

More example Requests/Responses:

I. Example Request: Get by ID

I. Example Response: Get by ID

{
    "id": 1,
    "tag_name": "rock music",
    "products": [
        {
            "id": 3,
            "product_name": "Branded Baseball Hat",
            "price": 22.99,
            "stock": 12,
            "category_id": 4,
            "product_tag": {
                "id": 5,
                "product_id": 3,
                "tag_id": 1,
                "productId": 3,
                "tagId": 1
            }
        },
        {
            "id": 4,
            "product_name": "Top 40 Music Compilation Vinyl Record",
            "price": 12.99,
            "stock": 50,
            "category_id": 3,
            "product_tag": {
                "id": 9,
                "product_id": 4,
                "tag_id": 1,
                "productId": 4,
                "tagId": 1
            }
        }
    ]
}

Status Code: 200

5. Update Product

Update By ID

Update the Tag name in the database by the ID at the end of the URL.

Endpoint:

Method: PUT
Type: RAW
URL: http://localhost:3001/api/tags/1

Body:

{
    "tag_name": "black"
}

More example Requests/Responses:

I. Example Request: Update Product

Body:

{
    "tag_name": "black"
}

I. Example Response: Update Product

{
    "message": "black Updated"
}

Status Code: 202


Back to top

Credits

API Generated by docgen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.