> For the complete documentation index, see [llms.txt](https://sayyidkhan92.gitbook.io/fashionshopdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sayyidkhan92.gitbook.io/fashionshopdocs/api/api-documentation/product-api.md).

# Product API

## How to use Example section of Each API Endpoint ?

If the application is currently running and records are loaded into the database, clicking on an example will cause the web browser to open a new tab and render the API outcome.&#x20;

An Example is shown here below.

{% hint style="info" %}
**Example:**

[http://localhost:5000/product/](<http://localhost:5000/product/pg?currentPage=1\&itemPerPage=10&#xA;>)
{% endhint %}

## Using Swagger API UI to test URL endpoints

Alternatively, to **test the API endpoint** u can [**turn on the Swagger API UI**](/fashionshopdocs/api/swagger-api.md) and **test it directly** with the application.&#x20;

## Get All Product

<mark style="color:blue;">`GET`</mark> `http://localhost:5000/product`

Get all the records w/o sorting or pagination involved.\
\
No parameters are required to be passed in order to use this API.\
An API which helps to get all the products from the product's table.

{% tabs %}
{% tab title="200 Returns a list of productDTO
Object Received: ProductDTO \[ ]" %}

```
[
  {
    "id": 477,
    "name": "A/C Shirt - M",
    "description": "shirts",
    "price": 79
  },
  {
    "id": 311,
    "name": "Active Briefs - W",
    "description": "bras",
    "price": 24
  },
  {
    "id": 312,
    "name": "Active Hipster - W",
    "description": "bras",
    "price": 24
  },
  {
    "id": 308,
    "name": "Active Mesh Bra - W",
    "description": "bras",
    "price": 45
  }
]
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Example:**

<http://localhost:5000/product>
{% endhint %}

## Insert A New Product Listing

<mark style="color:green;">`POST`</mark> `http://localhost:5000/product`

Insert a new product object that needs to be added to the product listing,\
\
No parameters required to be passed.

#### Request Body

| Name         | Type   | Description                             |
| ------------ | ------ | --------------------------------------- |
| Request Body | object | Insert a new record into product table. |

{% tabs %}
{% tab title="201 Returns a the new productDTO object
Object Received: ProductDTO" %}

```
{
  "id": 501,
  "name": "string",
  "description": "string",
  "price": "0.00"
}
```

{% endtab %}

{% tab title="404 No Product(s) Found" %}

```
```

{% endtab %}
{% endtabs %}

**Example Value | Schema (Request Body which is required to be passed)**

**Schema Used: CreateProductDTO**

```
{
  "name": "string",
  "description": "string",
  "price": 0
}
```

**CreateProductDTO**

| Key           | Datatype | Description                                                                                                              |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| name\*        | string   | the title of the product                                                                                                 |
| description\* | string   | the description describing the category of the product which it falls under                                              |
| price\*       | number   | <p>minimum: 0<br>maximum: 9999<br>default: 0</p><p>the price of the product, accepts a number up to 2 decimal points</p> |

{% hint style="info" %}
**Example:**

<http://localhost:5000/product>
{% endhint %}

## Get All Products + Sorting

<mark style="color:blue;">`GET`</mark> `http://localhost:5000/product/sortby`

Get all the records + allows single or multiple sorting\
\
1\. optional to pass {orderByName} -> if passed as PARAM\_QUERY will sort based on possible values\
2\. optional to pass {orderByPrice} -> if passed as PARAM\_QUERY will sort based on possible values\
3\. if multiple sort is specified, then it will be sorted by name then price.\
4\. if other values is provided to orderByName / orderByPrice, it will disregard the value and sort it in ascending order.

#### Query Parameters

| Name         | Type   | Description                                                                                              |
| ------------ | ------ | -------------------------------------------------------------------------------------------------------- |
| orderByPrice | string | <p>Accepts<br><code>asc</code> sort by Ascending Order<br><code>desc</code> sort by Descending Order</p> |
| orderByName  | string | <p>Accepts<br><code>asc</code> sort by Ascending Order<br><code>desc</code> sort by Descending Order</p> |

{% tabs %}
{% tab title="200 Displays a list of all the products from the database sorted by choice(s) selected
Object Received: ProductDTO \[]" %}

```
[
  {
    "id": 477,
    "name": "A/C Shirt - M",
    "description": "shirts",
    "price": 79
  },
  {
    "id": 311,
    "name": "Active Briefs - W",
    "description": "bras",
    "price": 24
  },
  {
    "id": 312,
    "name": "Active Hipster - W",
    "description": "bras",
    "price": 24
  }
]
```

{% endtab %}

{% tab title="404 No Product Found, No Record In Database" %}

```
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Example:**

<http://localhost:5000/product/sortby?orderByPrice=asc>
{% endhint %}

## Get One Product by ID Only

<mark style="color:blue;">`GET`</mark> `http://localhost:5000/product/filterById/{id}`

get one product by ID, only numbers(integer) are accepted.\
\
If product ID does not exist, it will return 404 error. Currently data preparation ID's are (1 - 500) are valid records. ID 501 and later does not exist unless added. Can use these data for data testing scenarios.&#x20;

#### Path Parameters

| Name | Type   | Description                                                                |
| ---- | ------ | -------------------------------------------------------------------------- |
| id   | number | any number from one to infinity -> possible values: ( 1 ... n )the product |

{% tabs %}
{% tab title="200 Return 1 productDTO successfully which was searched by ID.
Object Received: ProductDTO" %}

```
{
  "id": 20,
  "name": "Micro Puff Jacket - W",
  "description": "jackets",
  "price": 249
}
```

{% endtab %}

{% tab title="404 No Product(s) Found." %}

```
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Example:**

<http://localhost:5000/product/filterById/20>
{% endhint %}

## Get Products by filtering price + sorting

<mark style="color:blue;">`GET`</mark> `http://localhost:5000/product/filterByPrice`

get products by filtering price (within min - max range) or (>= min) or (<= max) then sorting\
\
1\. {minprice} - OPTIONAL\_PARAMETER, query will still work w/o min price input\
2\. {maxprice) - OPTIONAL\_PARAMETER, query will still work w/o max price input\
3\. optional to pass {orderByName} -> query will still work w/o inputing min or max value\
4\. optional to pass {orderByPrice} -> query will still work w/o input min or max value \
5\. if multiple sort is specified, then it will be sorted by name then price.\
6\. if other values is provided to orderByName / orderByPrice, it will disregard the value and sort it in ascending order.

#### Query Parameters

| Name         | Type   | Description                                                                                              |
| ------------ | ------ | -------------------------------------------------------------------------------------------------------- |
| minprice     | number | minimum price - cannot be less than 0                                                                    |
| maxprice     | number | max maximum price - cannot be more than 9999                                                             |
| orderByPrice | string | <p>Accepts<br><code>asc</code> sort by Ascending Order<br><code>desc</code> sort by Descending Order</p> |
| orderByName  | string | <p>Accepts<br><code>asc</code> sort by Ascending Order<br><code>desc</code> sort by Descending Order</p> |

{% tabs %}
{% tab title="200 Displays a list of all the products from the database with price filter(s) + sorted by choice(s) selected.
Object Received: ProductDTO \[ ]" %}

```
[
  {
    "id": 314,
    "name": "Sender Hipster - W",
    "description": "bras",
    "price": 18
  },
  {
    "id": 315,
    "name": "Sender Briefs - W",
    "description": "bras",
    "price": 18
  }
]
```

{% endtab %}

{% tab title="400 ERROR - Min price greater than or equal to Max price." %}

```
```

{% endtab %}

{% tab title="404 No Product(s) found." %}

```
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Example:**

<http://localhost:5000/product/filterByPrice?minprice=10&maxprice=20>
{% endhint %}

## Get Products by filtering name + sorting

<mark style="color:blue;">`GET`</mark> `http://localhost:5000/product/filterByName/{name}`

get products by filtering name using the like clause + sorting\
\
1\. {name) - REQUIRED PARAMETER, query will search for name of product and returns the product name which has the text name in it\
2\. optional to pass {orderByName} -> query will still work w/o inputing min or max value\
3\. optional to pass {orderByPrice} -> query will still work w/o input min or max value \
4\. if multiple sort is specified, then it will be sorted by name then price.\
5\. if other values is provided to orderByName / orderByPrice , it will disregard the value and sort it in ascending order.

#### Path Parameters

| Name | Type   | Description                                               |
| ---- | ------ | --------------------------------------------------------- |
| name | string | name of the product -> will be filtered using like clause |

#### Query Parameters

| Name         | Type   | Description                                                                                              |
| ------------ | ------ | -------------------------------------------------------------------------------------------------------- |
| orderByPrice | string | <p>Accepts<br><code>asc</code> sort by Ascending Order<br><code>desc</code> sort by Descending Order</p> |
| orderByName  | string | <p>Accepts<br><code>asc</code> sort by Ascending Order<br><code>desc</code> sort by Descending Order</p> |

{% tabs %}
{% tab title="200 Displays a list of all the products from the database with price filter(s) + sorted by choice(s) selected.
Object Received: ProductDTO \[ ]" %}

```
[
  {
    "id": 1,
    "name": "Better Sweater 1/4-Zip - W",
    "description": "jackets",
    "price": 99.1
  },
  {
    "id": 2,
    "name": "Better Sweater Jacket - W",
    "description": "jackets",
    "price": 139.2
  },
  {
    "id": 8,
    "name": "Down Sweater - W",
    "description": "jackets",
    "price": 229
  },
  {
    "id": 17,
    "name": "Down Sweater Hoody - W",
    "description": "jackets",
    "price": 279
  }
]
```

{% endtab %}

{% tab title="404 No Product(s) found." %}

```
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Example:**

<http://localhost:5000/product/filterByName/sweater>
{% endhint %}

For checking the **object structure(DTO)** that was sent or received via API, do check the [DTO used in the Application page.](/fashionshopdocs/api/api-documentation/dto-used-in-the-application.md)
