# API

## Registration

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/register/`

#### Request Body

| Name              | Type    | Description     |
| ----------------- | ------- | --------------- |
| username          | string  | bobby           |
| firstName         | string  | bobby           |
| lastName          | string  | lee             |
| email             | string  | <bob@email.com> |
| pasword1          | string  | bobbob123       |
| password2         | string  | bobbob123       |
| isPersonalTrainer | boolean | false           |
| referralCode      | string  | JAMES1          |
| calories          | number  | 2000            |

{% tabs %}
{% tab title="200 Returns an authentication token that is required for further requests after logging in. This key is held in our redux-store on our front-end, and sent in the headers of every subsequent query." %}

```
{
    "key": "c502905e8f6f0b3a8aafd8054e688f1cc4fec401",
    "user": {
        "id": 6,
        "password":"pbkdf2_sha256$260000$Bapflp65ZoA7YIH20MV8Qr$kljzhFs39Xd2bfGKVjPoha9KhP9khhBTiq/xZcNU8Nk=",
        "last_login": "2021-06-25T21:38:27.082979+08:00",
        "username": "bobby",
        "first_name" "bobby",
        "last_name": "lee",
        "email": "bob@email.com",
        "date_joined": "2021-06-25T21:38:26.984507+08:00",
        "isPersonalTrainer": false,
        "Signed up": "With personal Trainer",
        "status": "ok",
    }
}
```

{% endtab %}
{% endtabs %}

## Login

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/login/`

#### Request Body

| Name     | Type   | Description   |
| -------- | ------ | ------------- |
| username | string | bobby         |
| password | string | bobbybobby123 |

{% tabs %}
{% tab title="200 " %}

```
{
    "key": "c502905e8f6f0b3a8aafd8054e688f1cc4fec401",
    "user": {
        "id": 6,
        "password":"pbkdf2_sha256$260000$Bapflp65ZoA7YIH20MV8Qr$kljzhFs39Xd2bfGKVjPoha9KhP9khhBTiq/xZcNU8Nk=",
        "last_login": "2021-06-25T21:38:27.082979+08:00",
        "username": "bobby",
        "first_name" "bobby",
        "last_name": "lee",
        "email": "bob@email.com",
        "date_joined": "2021-06-25T21:38:26.984507+08:00",
        "isPersonalTrainer": false,
        "Signed up": "With personal Trainer",
        "status": "ok",
    }
}
```

{% endtab %}
{% endtabs %}

## Profile

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/<username>`

Returns the requesting user's profile information.

{% tabs %}
{% tab title="200 " %}

```
{ 
    "id": 1, 
    "username": "james", 
    "referralCode": "JAMES1", 
    "user": { 
        "id": 1, 
        "password": "pbkdf2_sha256$260000$gj9PvJqUW4y1ewIf4qpQhR$WppJps88jtXA3H0ybem8i72hh0Ye//uYhMkNPbeGxYI=", 
        "last_login": "2021-06-25T21:55:04.857808+08:00", 
        "is_superuser": false, "username": "james", 
        "first_name": "james", 
        "last_name": "yeap", 
        "email": "james@eamil.com", 
        "is_staff": false, 
        "is_active": true, 
        "date_joined": "2021-06-23T17:11:11.774779+08:00", 
        "isPersonalTrainer": true, 
        "mealPlans": [ 1, 2 ] } 
    } 
}
```

{% endtab %}
{% endtabs %}

## Get Custom Recipes

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/recipes/custom/`

Returns a list of recipes created by the user

{% tabs %}
{% tab title="200 " %}

```
 [ 
  { 
   "id": 1, 
   "title": "chicken", 
   "ingredients": "chicken", 
   "instructions": "cook it", 
   "calories": 123, 
   "servings": 1, 
   "custom": false, 
   "author": "james" 
  }, 
  { 
   "id": 2, 
   "title": "fish", 
   "ingredients": "fish", 
   "instructions": "cook it", 
   "calories": 321, "servings": 1, 
   "custom": false, 
   "author": "james" 
  }, 
  { 
   "id": 3, 
   "title": "crab", 
   "ingredients": "crab", 
   "instructions": "cook it", 
   "calories": 213, 
   "servings": 1, 
   "custom": false, 
   "author": "james" 
  }
 ]
```

{% endtab %}
{% endtabs %}

## Search All Recipes

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/recipes/search/`

Returns a list of recipes created by the user and personal trainers.

{% tabs %}
{% tab title="200 " %}

```
 [ 
  { 
   "id": 5, 
   "title": "chicken", 
   "ingredients": "chicken", 
   "instructions": "cook it", 
   "calories": 123, 
   "servings": 1, 
   "custom": false, 
   "author": "bob" 
  }, 
  { 
   "id": 2, 
   "title": "fish", 
   "ingredients": "fish", 
   "instructions": "cook it", 
   "calories": 321, "servings": 1, 
   "custom": false, 
   "author": "james" 
  }, 
  { 
   "id": 3, 
   "title": "crab", 
   "ingredients": "crab", 
   "instructions": "cook it", 
   "calories": 213, 
   "servings": 1, 
   "custom": false, 
   "author": "james" 
  }
 ]
```

{% endtab %}
{% endtabs %}

## Add Recipe

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/recipes/`

Adds a new recipe to the database

#### Request Body

| Name         | Type    | Description     |
| ------------ | ------- | --------------- |
| title        | string  | chicken         |
| ingredients  | string  | chicken and egg |
| instructions | string  | cook it         |
| calories     | number  | 123             |
| servings     | number  | 1               |
| custom       | boolean | false           |
| author       | string  | james           |

{% tabs %}
{% tab title="200 " %}

```
{ 
     "id": 1,
     "title": "chicken", 
     "ingredients": "chicken and egg", 
     "instructions": "cook it", 
     "calories": 123, 
     "servings": 1, 
     "custom": false, 
     "author": "james" 
}
```

{% endtab %}
{% endtabs %}

## Edit Recipe

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/api/recipes/edit/<recipeID>`

Note: Only the author of the recipe is allowed to make changes to the recipe.

#### Request Body

| Name         | Type    | Description |
| ------------ | ------- | ----------- |
| title        | string  | crab        |
| ingredients  | string  | crab        |
| instructions | string  | cook it     |
| calories     | number  | 503         |
| servings     | number  | 1           |
| custom       | boolean | true        |

{% tabs %}
{% tab title="200 " %}

```
{ 
    "title": "crab", 
    "ingredients": "crab", 
    "instructions": "cook it", 
    "calories": 503, 
    "servings": 1, 
    "custom": true 
}
```

{% endtab %}
{% endtabs %}

## Delete Recipe

<mark style="color:red;">`DELETE`</mark> `https://freshie-api.herokuapp.com/api/recipes/edit/<recipeID>`

Deletes the recipe with the recipe ID

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Get Meal Plans

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/<username>/mealplans/`

{% tabs %}
{% tab title="200 " %}

```
[ 
    { 
        "id": 1, 
        "title": "week 1", 
        "meal": 
            [ 
                { 
                    "id": 1, 
                    "title": "chicken", 
                    "ingredients": "chicken and egg", 
                    "instructions": "cook it", 
                    "calories": 123, 
                    "servings": 1, 
                    "custom": false, 
                    "author": "james" 
                }, 
                { 
                    "id": 2,
                    "title": "fish",     
                    "ingredients": "fish", 
                    "instructions": "cook it", 
                    "calories": 321, 
                    "servings": 1, 
                    "custom": false, 
                    "author": "james" 
                } 
            ] 
    }, 
    { 
        "id": 8, 
        "title": "week 2", 
        "meal": 
            [ 
                {
                     "id": 9, 
                     "title": "fish", 
                     "ingredients": "fish", 
                     "instructions": "cook it", 
                     "calories": 321, 
                     "servings": 1, 
                     "custom": false, 
                     "author": null 
                 }, 
                 { 
                     "id": 10, 
                     "title": "crab", 
                     "ingredients": "crab", 
                     "instructions": "cook it", 
                     "calories": 213, 
                     "servings": 1, 
                     "custom": false, 
                     "author": null 
                 } 
             ] 
     } 
 ]
```

{% endtab %}
{% endtabs %}

## Add Meal Plan

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/<username>/add-mealplan/`

#### Request Body

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| title | string | Week 24     |
| meals | array  | \[2, 9]     |

{% tabs %}
{% tab title="200 " %}

```
{ 
    "id": 9, 
    "title": "Week 24", 
    "meal": 
        [ 
            {
                 "id": 14, 
                 "title": "fish", 
                 "ingredients": "fish", 
                 "instructions": "cook it", 
                 "calories": 321, 
                 "servings": 1, 
                 "custom": false, 
                 "author": null 
             }, 
             { 
                 "id": 15, 
                 "title": "fish", 
                 "ingredients": "fish", 
                 "instructions": "cook it", 
                 "calories": 321, 
                 "servings": 1, 
                 "custom": false, 
                 "author": null 
             } 
         ] 
 }
```

{% endtab %}
{% endtabs %}

## Delete Meal Plan

<mark style="color:red;">`DELETE`</mark> `https://freshie-api.herokuapp.com/api/<username>/mealplan/<mealPlanID>/`

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Get Client List

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/<username>/clients/`

Returns a list of clients that a personal trainer has.

{% tabs %}
{% tab title="200 " %}

```
[
   {
      "id":1,
      "username":"bob",
      "user":{
         "id":2,
         "password":"pbkdf2_sha256$260000$EsA4WqV9P0BqSIBb4qYVqI$sro4B8EGCzCnKIv/ZyzG/7dBNAdhWYwxZHCtUSA75Is=",
         "last_login":"2021-06-24T16:32:13.063393+08:00",
         "username":"bob",
         "first_name":"bob",
         "last_name":"bee",
         "email":"",
         "date_joined":"2021-06-23T17:19:28.358985+08:00",
         "isPersonalTrainer":false,
         "mealPlans":[
            1
         ]
      },
      "personalTrainer":{
         "id":1,
         "username":"james",
         "referralCode":"JAMES1",
         "user":"james"
      }
   },
   {
      "id":3,
      "username":"Q",
      "user":{
         "id":4,
         "password":"pbkdf2_sha256$260000$zWMyFNScojkjtS8hyCYouY$AxrFmC2OEWeR0jmIobWp9pHxIr/vVTHsbA0SD+rQKRI=",
         "last_login":"2021-06-23T23:00:39.117705+08:00",
         "username":"Q",
         "first_name":"Q",
         "last_name":"Q",
         "email":"Q@email.com",
         "date_joined":"2021-06-23T18:14:35.098894+08:00",
         "isPersonalTrainer":false,
         "mealPlans":[
            
         ]
      },
      "personalTrainer":{
         "id":1,
         "username":"james",
         "referralCode":"JAMES1",
         "user":"james"
      }
   },
   {
      "id":4,
      "username":"bobby",
      "user":{
         "id":6,
         "password":"pbkdf2_sha256$260000$Bapflp65ZoA7YIH20MV8Qr$kljzhFs39Xd2bfGKVjPoha9KhP9khhBTiq/xZcNU8Nk=",
         "last_login":"2021-06-25T22:27:05.566278+08:00",
         "username":"bobby",
         "first_name":"bobby",
         "last_name":"lee",
         "email":"bob@email.com",
         "date_joined":"2021-06-25T21:38:26.984507+08:00",
         "isPersonalTrainer":false,
         "mealPlans":[
            
         ]
      },
      "personalTrainer":{
         "id":1,
         "username":"james",
         "referralCode":"JAMES1",
         "user":"james"
      }
   }
```

{% endtab %}
{% endtabs %}

## Get Client Profile

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/<username>/client/<clientUsername>/view/`

Returns the profile details of a client.

{% tabs %}
{% tab title="200 " %}

```
{
   "id":4,
   "username":"bobby",
   "user":{
      "id":6,
      "password":"pbkdf2_sha256$260000$Bapflp65ZoA7YIH20MV8Qr$kljzhFs39Xd2bfGKVjPoha9KhP9khhBTiq/xZcNU8Nk=",
      "last_login":"2021-06-25T22:27:05.566278+08:00",
      "username":"bobby",
      "first_name":"bobby",
      "last_name":"lee",
      "email":"",
      "date_joined":"2021-06-25T21:38:26.984507+08:00",
      "isPersonalTrainer":false,
      "mealPlans":[
         
      ]
   },
   "personalTrainer":{
      "id":1,
      "username":"james",
      "referralCode":"JAMES1",
      "user":"james"
   }
}
```

{% endtab %}
{% endtabs %}

## Get Meal Plans Assigned To A Client

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/<username>/client/<clientUsername>/meal-plans/`

Returns the meal plans assigned to a client.

{% tabs %}
{% tab title="200 " %}

```
[
   {
      "id":2,
      "title":"week 2",
      "meal":[
         {
            "id":2,
            "title":"fish",
            "ingredients":"fish",
            "instructions":"cook it",
            "calories":321,
            "servings":1,
            "custom":false,
            "author":"james"
         },
         {
            "id":3,
            "title":"crab",
            "ingredients":"crab",
            "instructions":"cook it",
            "calories":213,
            "servings":1,
            "custom":false,
            "author":"james"
         }
      ]
   }
]
```

{% endtab %}
{% endtabs %}

## Assign a Meal Plan To A Client

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/api/<username>/client/<clientUsername>/assign-meal-plan/`

Assigns a meal plan to the client.

#### Request Body

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| mealPlanID | number | 2           |

{% tabs %}
{% tab title="200 " %}

```
"week 2 assigned to bobby!"
```

{% endtab %}
{% endtabs %}

## Delete Client's Meal Plan

<mark style="color:red;">`DELETE`</mark> `https://freshie-api.herokuapp.com/api/<username>/client/<clientUsername>/remove-meal-plan/`

Unassigns a meal plan from a client.

#### Request Body

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| mealPlanID | number |             |

{% tabs %}
{% tab title="200 " %}

```
"Successfully removed week 2 from bobby's meal plans!"
```

{% endtab %}
{% endtabs %}

## Delete Client

<mark style="color:red;">`DELETE`</mark> `https://freshie-api.herokuapp.com/api/<username>/client/<clientUsername>/remove/`

Removes a client from a personal trainer's client list.

{% tabs %}
{% tab title="200 " %}

```
 "You have successfully removed bobby as your client."
```

{% endtab %}
{% endtabs %}

## Add Personal Trainer

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/api/<username>/add-personal-trainer/`

Assigns a personal trainer to a client based on the referralID provided.

#### Request Body

| Name         | Type   | Description |
| ------------ | ------ | ----------- |
| referralCode | string | JAMES1      |

{% tabs %}
{% tab title="200 " %}

```
"James is now your personal trainer!"
```

{% endtab %}
{% endtabs %}

## Get Calorie Count

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api//<username>/calories`

Note: A client will only be able to view his own calorie count.

{% tabs %}
{% tab title="200 " %}

```
{ 
    "id": 4, 
    "dailyCalories": 2000, 
    "currentCalories": 0, 
    "client": "bobby" 
}
```

{% endtab %}
{% endtabs %}

## Edit Calorie Count

<mark style="color:purple;">`PATCH`</mark> `https://freshie-api.herokuapp.com/api/<username>/calories/`

Note: Only the client or his personal trainer will be able to update his calories.

#### Request Body

| Name            | Type   | Description |
| --------------- | ------ | ----------- |
| currentCalories | number | 532         |

{% tabs %}
{% tab title="200 " %}

```
{ 
    "id": 4, 
    "dailyCalories": 2000, 
    "currentCalories": 532, 
    "client": "bobby" 
}
```

{% endtab %}
{% endtabs %}

## Get History of Meals Consumed

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/<username>/consumed-meals/`

Returns a list of the consumed meals on the date provided.

#### Request Body

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| day   | number | 24          |
| month | number | 6           |
| year  | number | 2021        |

{% tabs %}
{% tab title="200 " %}

```
         "title":"chicken",
         "ingredients":"chicken and egg",
         "instructions":"cook it",
         "calories":123,
         "servings":1,
         "custom":false,
         "author":"james"
      },
      "client":{
         "id":1,
         "username":"bob",
         "user":"bob",
         "personalTrainer":"james"
      }
   },
   {
      "id":26,
      "mealType":"Supper",
      "date":"2021-06-24",
      "calories":321,
      "meal":{
         "id":4,
         "title":"fish",
         "ingredients":"fish",
         "instructions":"cook it",
         "calories":321,
         "servings":1,
         "custom":false,
         "author":"james"
      },
      "client":{
         "id":1,
         "username":"bob",
         "user":"bob",
         "personalTrainer":"james"
      }
   }
]
```

{% endtab %}
{% endtabs %}

## Add Consumed Meal

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/api/<username>/add-consumed-meal/`

Adds a consumed meal.

#### Request Body

| Name     | Type   | Description |
| -------- | ------ | ----------- |
| recipeID | string | 18          |
| mealType | string | Supper      |

{% tabs %}
{% tab title="200 " %}

```
{
   "id":18,
   "mealType":"Supper",
   "date":"2021-06-24",
   "calories":123,
   "meal":{
      "id":1,
      "title":"chicken",
      "ingredients":"chicken and egg",
      "instructions":"cook it",
      "calories":123,
      "servings":1,
      "custom":false,
      "author":"james"
   },
   "client":{
      "id":1,
      "username":"bob",
      "user":"bob",
      "personalTrainer":"james"
   }
}
```

{% endtab %}
{% endtabs %}

## Delete Consumed Meal

<mark style="color:red;">`DELETE`</mark> `https://freshie-api.herokuapp.com/api/<username>/consumed-meal/<consumedMealID>/`

Deletes a consumed meal.

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Get Favourite Meals

<mark style="color:blue;">`GET`</mark> `https://freshie-api.herokuapp.com/api/<username>/fav-meals/`

Returns a list of the client's favourite meals.

{% tabs %}
{% tab title="200 " %}

```
[
   {
      "id":1,
      "meal":{
         "id":11,
         "title":"chicken",
         "ingredients":"chicken and egg",
         "instructions":"cook it",
         "calories":123,
         "servings":1,
         "custom":false,
         "author":null
      },
      "client":{
         "id":1,
         "username":"bob",
         "user":"bob",
         "personalTrainer":"james"
      }
   },
   {
      "id":2,
      "meal":{
         "id":12,
         "title":"fish",
         "ingredients":"fish",
         "instructions":"cook it",
         "calories":321,
         "servings":1,
         "custom":false,
         "author":null
      },
      "client":{
         "id":1,
         "username":"bob",
         "user":"bob",
         "personalTrainer":"james"
      }
   }
]
```

{% endtab %}
{% endtabs %}

## Add Favourite Meal

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/api/<username>/add-fav-meal/`

Adds an existing recipe to client's favourites.

#### Request Body

| Name     | Type   | Description |
| -------- | ------ | ----------- |
| recipeID | number | 3           |

{% tabs %}
{% tab title="200 " %}

```
{
   "id": 3,
   "meal":{
      "id":13,
      "title":"crab",
      "ingredients":"crab",
      "instructions":"cook it",
      "calories":213,
      "servings":1,
      "custom":false,
      "author":null
   },
   "client":{
      "id":1,
      "username":"bob",
      "user":"bob",
      "personalTrainer":"james"
   }
}
```

{% endtab %}
{% endtabs %}

## Delete Favourite Meal

<mark style="color:red;">`DELETE`</mark> `https://freshie-api.herokuapp.com/api/<username>/fav-meal/1/`

Removes a recipe from a user's favorite list.

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Edit Client's Target Daily Calories

<mark style="color:green;">`POST`</mark> `https://freshie-api.herokuapp.com/api/ <username>/client/<clientUsername>/edit-calories/`

Allows the personal trainer to change his client's target daily calories.

#### Request Body

| Name     | Type   | Description |
| -------- | ------ | ----------- |
| calories | number | 2100        |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}
