Skip to content

ngtrthinh169TPC/AnchiBackend

Repository files navigation

AnchiBackend

Backend for Anchi - A project for my school homework.

This project is currently (2022) being deployed here.




API List

Click the name of API for more details.

// TODO: add api names to all detail sections

User APIs

Name Method Path
Register POST /user/
Login POST /login/
Logout POST /logout/
Change Password POST /change-password/

Food APIs

Name Method Path
All Foods GET /all-foods/
GET Favourite Foods GET /favourite-foods/
POST Favourite Food POST /favourite-foods/
PATCH Favourite Foods PATCH /favourite-foods/
GET Blacklist Foods GET /blacklist-foods/
POST Blacklist Food POST /blacklist-foods/
PATCH Blacklist Foods PATCH /blacklist-foods/
Next Food GET /next-food/
POST Food POST /food/

Restaurant APIs

Name Method Path
All Restaurants GET /all-restaurants/
GET Favourite Restaurants GET /favourite-restaurants/
POST Favourite Restaurant POST /favourite-restaurants/
PATCH Favourite Restaurants PATCH /favourite-restaurants/
GET Blacklist Restaurants GET /blacklist-restaurants/
POST Blacklist Restaurant POST /blacklist-restaurants/
PATCH Blacklist Restaurants PATCH /blacklist-restaurants/
Next Restaurant GET /next-restaurant/
POST Restaurant POST /restaurant/

Tag & Ingredient & Area APIs

Name Method Path
All Tags GET /all-tags/
POST Tag POST /tag/
All Ingredients GET /all-ingredients/
POST Ingredient POST /ingredient/
All Areas GET /all-areas/
POST Area POST /area/



Register API


Register a new User.

  • API: /user/

  • Request example:

    {
      "username": "Minh Huong",
      "password": "minhehe123",
      "email": "[email protected]"
    }
  • Response example:

    {
      "username": "Minh Huong",
      "token": "b48d7ff8fd3de7417c451156a7516fc75aecf40d",
      "email": "[email protected]"
    }

^



Login API


Log in as an User.

  • API: /login/

  • Request example:

    { "username": "Minh Huong", "password": "minhehe123" }
  • Login Successful Response example:

    {
      "username": "Minh Huong",
      "token": "b48d7ff8fd3de7417c451156a7516fc75aecf40d",
      "email": "[email protected]"
    }
  • Login Failed Response:

    {
      "detail": "Invalid user credentials."
    }

^


Logout


Log out

  • API: /logout/

  • Request body can be null. Only need the token.

  • Logout Successful Response:

    { "detail": "Log out successfully." }

^


Change Password


Change password using the old password


  • Request example:

    {
      "username": "Minh Huong",
      "password": "minhehe123",
      "new_password": "minhehe124"
    }
  • Change Password Successful Response:

    {
      "detail": "Your password has been changed successfully."
    }
  • Wrong user credential Response:

    {
      "detail": "Invalid user credentials."
    }
  • Duplicated password Response:

    {
      "detail": "Your new password should be different from the old password."
    }
  • No new password provided Response:

    {
      "detail": "Missing new_password field."
    }

^


All Foods


Get a list of all of the foods from database


  • Response example:

    [
      {
        "id": 1,
        "name": "bánh mì",
        "image": "/media/fallback.png",
        "description": "banh mi bnh mi banh mi banh mi",
        "address": "ai ma biet duoc",
        "recipe": "banh mi",
        "tags": [
          {
            "id": 1,
            "name": "ăn sáng",
            "description": "",
            "verified": true
          }
        ],
        "ingredients": [
          {
            "id": 1,
            "name": "bột mì",
            "description": "",
            "verified": true
          }
        ],
        "areas": [],
        "verified": true
      },
      {
        "id": 2,
        "name": "taiyaki đậu đỏ",
        "image": "/media/fallback.png",
        "description": "bánh cá Nhật Bản nhân đậu đỏ",
        "address": "",
        "recipe": "",
        "tags": [
          {
            "id": 2,
            "name": "ăn vặt",
            "description": "",
            "verified": true
          }
        ],
        "ingredients": [
          {
            "id": 1,
            "name": "bột mì",
            "description": "",
            "verified": true
          },
          {
            "id": 3,
            "name": "đậu đỏ",
            "description": "",
            "verified": true
          }
        ],
        "areas": [],
        "verified": true
      },
      {
        "id": 3,
        "name": "bánh rán",
        "image": "/media/images/foods/how.jpg",
        "description": "bánh rán nhân đỗ xanh tẩm đường giòn ngon nhưng ăn nhiều thì béo",
        "address": "",
        "recipe": "",
        "tags": [
          {
            "id": 2,
            "name": "ăn vặt",
            "description": "",
            "verified": true
          }
        ],
        "ingredients": [
          {
            "id": 2,
            "name": "bột nếp",
            "description": "",
            "verified": true
          }
        ],
        "areas": [],
        "verified": true
      }
    ]

^


GET Favourite Foods


Get a list of user's favourite foods


  • Response example:

    {
      "username": "user003",
      "favouriteFoods": [
        {
          "id": 1,
          "name": "bánh mì",
          "image": "/media/fallback.png",
          "description": "banh mi bnh mi banh mi banh mi",
          "address": "ai ma biet duoc",
          "recipe": "banh mi",
          "tags": [
            {
              "id": 1,
              "name": "ăn sáng",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 1,
              "name": "bột mì",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to have your favourite foods listed."
    }

^


POST Favourite Food


Add food into your favourite list.


  • Request example:

    {
      "foodId": 2
    }
  • Response example:

    {
      "username": "user003",
      "favouriteFoods": [
        {
          "id": 1,
          "name": "bánh mì",
          "image": "/media/fallback.png",
          "description": "banh mi bnh mi banh mi banh mi",
          "address": "ai ma biet duoc",
          "recipe": "banh mi",
          "tags": [
            {
              "id": 1,
              "name": "ăn sáng",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 1,
              "name": "bột mì",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        },
        {
          "id": 2,
          "name": "taiyaki đậu đỏ",
          "image": "/media/fallback.png",
          "description": "bánh cá Nhật Bản nhân đậu đỏ",
          "address": "",
          "recipe": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 1,
              "name": "bột mì",
              "description": "",
              "verified": true
            },
            {
              "id": 3,
              "name": "đậu đỏ",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to have your favourite foods listed."
    }
  • Food id not found Response:

    {
      "detail": "Provided food is not found at food_id 7"
    }
  • Food not found Response:

    {
      "detail": "You must provide a food in order add to your favourite list"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


PATCH Favourite Foods


Edit your favourite food list.


  • Request example:

    {
      "favouriteFoods": [2, 6]
    }
  • Response example:

    {
      "username": "user002",
      "favouriteFoods": [
        {
          "id": 2,
          "name": "taiyaki đậu đỏ",
          "image": "/media/fallback.png",
          "description": "bánh cá Nhật Bản nhân đậu đỏ",
          "address": "",
          "recipe": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 1,
              "name": "bột mì",
              "description": "",
              "verified": true
            },
            {
              "id": 3,
              "name": "đậu đỏ",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        },
        {
          "id": 6,
          "name": "bánh nướng",
          "image": "/media/fallback.png",
          "description": "nhân thập cẩm là số 1, nhân đậu xanh là tà đạo",
          "address": "",
          "recipe": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to have your favourite foods listed."
    }
  • Food id not found Response:

    {
      "detail": "Provided food is not found at food_id 7"
    }
  • List not found Response:

    {
      "detail": "You must provide a list to update your favourite foods"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


GET Blacklist Foods


Get a list of user's blacklisted foods


  • Response example:

    {
      "username": "user003",
      "blacklistFoods": [
        {
          "id": 3,
          "name": "bánh rán",
          "image": "/media/images/foods/how.jpg",
          "description": "bánh rán nhân đỗ xanh tẩm đường giòn ngon nhưng ăn nhiều thì béo",
          "address": "",
          "recipe": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 2,
              "name": "bột nếp",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to blacklist foods."
    }

^


POST Blacklist Food


Add food into your blacklist.


  • Request example:

    {
      "foodId": 2
    }
  • Response example:

    {
      "username": "user003",
      "blacklistFoods": [
        {
          "id": 2,
          "name": "taiyaki đậu đỏ",
          "image": "/media/fallback.png",
          "description": "bánh cá Nhật Bản nhân đậu đỏ",
          "address": "",
          "recipe": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 1,
              "name": "bột mì",
              "description": "",
              "verified": true
            },
            {
              "id": 3,
              "name": "đậu đỏ",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        },
        {
          "id": 3,
          "name": "bánh rán",
          "image": "/media/images/foods/how.jpg",
          "description": "bánh rán nhân đỗ xanh tẩm đường giòn ngon nhưng ăn nhiều thì béo",
          "address": "",
          "recipe": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 2,
              "name": "bột nếp",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to blacklist foods."
    }
  • Food id not found Response:

    {
      "detail": "Provided food is not found at food_id 7"
    }
  • Food not found Response:

    {
      "detail": "You must provide a food in order add to your blacklist"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


PATCH Blacklist Foods


Edit your food blacklist.


  • Request example:

    {
      "blacklistFoods": [3]
    }
  • Response example:

    {
      "username": "user002",
      "blacklistFoods": [
        {
          "id": 3,
          "name": "bánh rán",
          "image": "/media/images/foods/how.jpg",
          "description": "bánh rán nhân đỗ xanh tẩm đường giòn ngon nhưng ăn nhiều thì béo",
          "address": "",
          "recipe": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "ingredients": [
            {
              "id": 2,
              "name": "bột nếp",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to blacklist foods."
    }
  • Food id not found Response:

    {
      "detail": "Provided food is not found at food_id 7"
    }
  • List not found Response:

    {
      "detail": "You must provide a list to update your blacklist foods"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


Next Food


Get a random food from database


  • Request body can be null.

  • Request example

    {
      "lastFood": 2
    }
  • Response example:

    {
      "nextFood": {
        "id": 1,
        "name": "bánh mì",
        "image": "/media/fallback.png",
        "description": "banh mi bnh mi banh mi banh mi",
        "address": "ai ma biet duoc",
        "recipe": "banh mi",
        "tags": [
          {
            "id": 1,
            "name": "ăn sáng",
            "description": "",
            "verified": true
          }
        ],
        "ingredients": [
          {
            "id": 1,
            "name": "bột mì",
            "description": "",
            "verified": true
          }
        ],
        "areas": [],
        "verified": true
      }
    }
  • Response not found:

    {
      "detail": "We don't have any foods left :( come again later or try add some foods for us."
    }

^


POST Food


Post a new Food item to the system


  • Request example:

    {
      "name": "bánh nướng",
      "description": "nhân thập cẩm là số 1, nhân đậu xanh là tà đạo",
      "tags": [2]
    }
  • Response example:

    {
      "id": 6,
      "name": "bánh nướng",
      "image": "/media/fallback.png",
      "description": "nhân thập cẩm là số 1, nhân đậu xanh là tà đạo",
      "address": "",
      "recipe": "",
      "tags": [
        {
          "id": 2,
          "name": "ăn vặt",
          "description": "",
          "verified": true
        }
      ],
      "ingredients": [],
      "areas": [],
      "verified": false
    }

^


All Restaurants


Get a list of all of the restaurants from database


  • Response example:

    [
      {
        "id": 1,
        "name": "tiem banh mi",
        "image": "/media/fallback.png",
        "description": "",
        "address": "tiem banh mi",
        "menu": "banh mi",
        "note": "banh mi",
        "tags": [
          {
            "id": 1,
            "name": "ăn sáng",
            "description": "",
            "verified": true
          },
          {
            "id": 2,
            "name": "ăn vặt",
            "description": "",
            "verified": true
          }
        ],
        "areas": [],
        "verified": true
      },
      {
        "id": 4,
        "name": "bánh trung thu Đông Phương",
        "image": "/media/fallback.png",
        "description": "hiệu bánh trung thu bán chạy nhất Hải Phòng hàng năm, nguyên nhân làm tắc đường Cầu Đất mỗi tháng 8",
        "address": "",
        "menu": "",
        "note": "",
        "tags": [
          {
            "id": 2,
            "name": "ăn vặt",
            "description": "",
            "verified": true
          }
        ],
        "areas": [],
        "verified": true
      }
    ]

^


GET Favourite Restaurants


Get a list of user's favourite restaurants


  • Response example:

    {
      "username": "user003",
      "favouriteRestaurants": [
        {
          "id": 1,
          "name": "tiem banh mi",
          "image": "/media/fallback.png",
          "description": "",
          "address": "tiem banh mi",
          "menu": "banh mi",
          "note": "banh mi",
          "tags": [
            {
              "id": 1,
              "name": "ăn sáng",
              "description": "",
              "verified": true
            },
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to have your favourite restaurants listed."
    }

^


POST Favourite Restaurant


Add restaurant into your favourite list.


  • Request example:

    {
      "restaurantId": 2
    }
  • Response example:

    {
      "username": "user003",
      "favouriteRestaurants": [
        {
          "id": 1,
          "name": "tiem banh mi",
          "image": "/media/fallback.png",
          "description": "",
          "address": "tiem banh mi",
          "menu": "banh mi",
          "note": "banh mi",
          "tags": [
            {
              "id": 1,
              "name": "ăn sáng",
              "description": "",
              "verified": true
            },
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        },
        {
          "id": 36,
          "name": "phở có hành?",
          "image": "/media/fallback.png",
          "description": "thêm vào để blacklist",
          "address": "",
          "menu": "",
          "note": "hành ~~ rất nhiều hành",
          "tags": [],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to have your favourite restaurants listed."
    }
  • Restaurant id not found Response:

    {
      "detail": "Provided restaurant is not found at restaurant_id 6"
    }
  • Restaurant not found Response:

    {
      "detail": "You must provide a restaurant in order add to your favourite list"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


PATCH Favourite Restaurants


Edit your favourite restaurant list.


  • Request example:

    {
      "favouriteRestaurants": [1]
    }
  • Response example:

    {
      "username": "user002",
      "favouriteRestaurants": [
        {
          "id": 1,
          "name": "tiem banh mi",
          "image": "/media/fallback.png",
          "description": "",
          "address": "tiem banh mi",
          "menu": "banh mi",
          "note": "banh mi",
          "tags": [
            {
              "id": 1,
              "name": "ăn sáng",
              "description": "",
              "verified": true
            },
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to have your favourite restaurants listed."
    }
  • Restaurant id not found Response:

    {
      "detail": "Provided restaurant is not found at restaurant_id 3"
    }
  • List not found Response:

    {
      "detail": "You must provide a list to update your favourite restaurants"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


GET Blacklist Restaurants


Get a list of user's blacklisted restaurants


  • Response example:

    {
      "username": "user003",
      "blacklistRestaurants": [
        {
          "id": 36,
          "name": "phở có hành?",
          "image": "/media/fallback.png",
          "description": "thêm vào để blacklist",
          "address": "",
          "menu": "",
          "note": "hành ~~ rất nhiều hành",
          "tags": [],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to blacklist restaurants."
    }

^


POST Blacklist Restaurant


Add restaurant into your blacklist.


  • Request example:

    {
      "restaurantId": 35
    }
  • Response example:

    {
      "username": "user003",
      "blacklistRestaurants": [
        {
          "id": 35,
          "name": "bánh trung thu Đông Phương",
          "image": "/media/fallback.png",
          "description": "hiệu bánh trung thu bán chạy nhất Hải Phòng hàng năm, nguyên nhân làm tắc đường Cầu Đất mỗi tháng 8",
          "address": "",
          "menu": "",
          "note": "",
          "tags": [
            {
              "id": 2,
              "name": "ăn vặt",
              "description": "",
              "verified": true
            }
          ],
          "areas": [],
          "verified": true
        },
        {
          "id": 36,
          "name": "phở có hành?",
          "image": "/media/fallback.png",
          "description": "thêm vào để blacklist",
          "address": "",
          "menu": "",
          "note": "hành ~~ rất nhiều hành",
          "tags": [],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to blacklist restaurants."
    }
  • Restaurant id not found Response:

    {
      "detail": "Provided restaurant is not found at restaurant_id 6"
    }
  • Restaurant not found Response:

    {
      "detail": "You must provide a restaurant in order add to your blacklist"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


PATCH Blacklist Restaurants


Edit your restaurant blacklist.


  • Request example:

    {
      "blacklistRestaurants": [36]
    }
  • Response example:

    {
      "username": "user002",
      "blacklistRestaurants": [
        {
          "id": 36,
          "name": "phở có hành?",
          "image": "/media/fallback.png",
          "description": "thêm vào để blacklist",
          "address": "",
          "menu": "",
          "note": "hành ~~ rất nhiều hành",
          "tags": [],
          "areas": [],
          "verified": true
        }
      ]
    }
  • Anonymous User Response:

    {
      "detail": "You must sign in to have your blacklist restaurants listed."
    }
  • Restaurant id not found Response:

    {
      "detail": "Provided restaurant is not found at restaurant_id 6"
    }
  • List not found Response:

    {
      "detail": "You must provide a list to update your blacklist restaurants"
    }
  • Not AnchiUser Response:

    {
      "detail": "Invalid user credentials."
    }

^


Next Restaurant


Get a random restaurant from database


  • Request body can be null.

  • Request example

    {
      "lastRestaurant": 2
    }
  • Response example:

    {
      "nextRestaurant": {
        "id": 4,
        "name": "bánh trung thu Đông Phương",
        "image": "/media/fallback.png",
        "description": "hiệu bánh trung thu bán chạy nhất Hải Phòng hàng năm, nguyên nhân làm tắc đường Cầu Đất mỗi tháng 8",
        "address": "",
        "menu": "",
        "note": "",
        "tags": [
          {
            "id": 2,
            "name": "ăn vặt",
            "description": "",
            "verified": true
          }
        ],
        "areas": [],
        "verified": true
      }
    }
  • Response not found:

    {
      "detail": "We don't have any food restaurants left :( come again later or try add some restaurants for us."
    }

^


POST Restaurant


Post a new Restaurant item to the system


  • Request example:

    {
      "name": "bánh trung thu Đông Phương",
      "description": "hiệu bánh trung thu bán chạy nhất Hải Phòng hàng năm, nguyên nhân làm tắc đường Cầu Đất mỗi tháng 8",
      "tags": [2]
    }
  • Response example:

    {
      "id": 35,
      "name": "bánh trung thu Đông Phương",
      "image": "/media/fallback.png",
      "description": "hiệu bánh trung thu bán chạy nhất Hải Phòng hàng năm, nguyên nhân làm tắc đường Cầu Đất mỗi tháng 8",
      "address": "",
      "menu": "",
      "note": "",
      "tags": [
        {
          "id": 2,
          "name": "ăn vặt",
          "description": "",
          "verified": true
        }
      ],
      "areas": [],
      "verified": true
    }

^


All Tags


Get a list of all of the tags from database


  • Response example:

    [
      {
        "id": 1,
        "name": "ăn sáng",
        "description": "",
        "verified": true
      },
      {
        "id": 2,
        "name": "ăn vặt",
        "description": "",
        "verified": true
      }
    ]

^


POST Tag


Post a new Tag item to the system


  • Request example:

    {
      "name": "ăn trưa"
    }
  • Response example:

    {
      "id": 5,
      "name": "ăn trưa",
      "description": "",
      "verified": false
    }

^


All Ingredients


Get a list of all of the ingredients from database


  • Response example:

    [
      {
        "id": 1,
        "name": "bột mì",
        "description": "",
        "verified": true
      },
      {
        "id": 2,
        "name": "bột nếp",
        "description": "",
        "verified": true
      },
      {
        "id": 3,
        "name": "đậu đỏ",
        "description": "",
        "verified": true
      }
    ]

^


POST Ingredient


Post a new Ingredient item to the system


  • Request example:

    {
      "name": "thịt heo"
    }
  • Response example:

    {
      "id": 4,
      "name": "thịt heo",
      "description": "",
      "verified": false
    }

^


All Areas


Get a list of all of the areas from database


  • Response example:

    [
      {
        "id": 1,
        "name": "ĐHQG - ĐHSP",
        "description": "",
        "verified": true
      }
    ]

^


POST Area


Post a new Area item to the system


  • Request example:

    {
      "name": "Nghĩa Tân - Cầu Giấy"
    }
  • Response example:

    {
      "id": 2,
      "name": "Nghĩa Tân - Cầu Giấy",
      "description": "",
      "verified": false
    }

^



About

Backend for Anchi - A project for my school homework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages