Ibrahim-mj / RatingAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Menu Item Rating API

This is a REST API that allows authenticated users to rate a menu item and view the available ratings.

Requirements

Check the requirements.txt file for the required dependencies.

Installation

  1. Clone the repository:
git clone https://github.com/Ibrahim-mj/RatingAPI.git
  1. Create a virtual environment:
python -m venv .venv
  1. Activate the virtual environment:
  2. Install the requirements:
pip install -r requirements.txt
  1. Run the migrations:
python manage.py migrate
  1. Run the server:
python manage.py runserver
  1. Open the browser and go to the local server address

Usage

  1. Create a rating:
POST /api/ratings/

Request body:

{
    "menu_id": 1,
    "rating": 5
}

Response body:

{
    "id": 1,
    "menu_id": 1,
    "rating": 5,
    "user": 1
}

This endpoint uses Djoser's Token Authentication. To get a token, you must register a user and then login. The token is returned in the response body.

  1. Register a user:
POST /auth/users/

Request body:

{
    "username": "username",
    "password": "password"
}

Response body:

{
    "email": "",
    "username": "username",
    "id": 1
}
  1. Login:
POST /auth/token/login/

Request body:

{
    "username": "username",
    "password": "password"
}

Response body:

{
    "auth_token": "token"
}
  1. Get all ratings:
GET /api/ratings/

Response body:

[
    {
        "id": 1,
        "menu_id": 1,
        "rating": 5,
        "user": 1
    },
    {
        "id": 2,
        "menu_id": 1,
        "rating": 4,
        "user": 2
    }
]
  1. Get a rating:
GET /api/ratings/<id>/

Response body:

{
    "id": 1,
    "menu_id": 1,
    "rating": 5,
    "user": 1
}

About


Languages

Language:Python 100.0%