Bitpin Technical Task
-
Clone this repository to your local machine
-
If You want to use docker, skip steps 3 to 5 and if don't skip this step. To run with docker:
docker-compose up -d
- Create and activate a virtual environment based on your OS:
python3 -m venv .venv
source .venv/bin/activate
- Install project dependencies:
pip install -r requirements.txt
- Apply database migration commands:
python manage.py makemigrations
python manage.py migrate
- URL:
/api/posts
- Method:
GET
- Purpose: Get list of posts.
- Response:
[ ..., { "id": 2, "average_rating": 2.5, "rating_count": 2, "title": "test title", "content": "test content", "created_at": "2024-05-13T14:50:33.362683Z" }, ... ]
- URL:
/api/posts/<int:post_id>/
- Method:
POST
- Purpose: Post a rating to a post.
- Parameters:
rating
: integer value between 0 and 5.
- Responses:
200 OK
400 Bad Request
302 Redirect
: If user is not logged in
To solve the problem of too many requests, I used login_required decorator to force the user to login for rating a post and also set throttle to limit the number of requests per minute.