Skip to content

API for managing posts and comments with AI moderation and auto-reply.

Notifications You must be signed in to change notification settings

Gubchik123/Startnavi-test-task

Repository files navigation

Header image

API for managing posts and comments with AI moderation and auto-reply.

Project modules

celery Django django-celery-beat django-celery-results django-cors-headers djangorestframework djoser drf-spectacular flower google_generativeai psycopg2-binary python-dotenv redis

Features

  1. User registration;
  2. User login;
  3. API for managing posts;
  4. API for managing comments;
  5. Checking posts or comments at the time of creation for the presence of obscene language, insults, etc., and blocking such posts or comments.
  6. Analytics on the number of comments that have been added to posts for a certain period. Example URL: /api/v1/posts/1/comments_analytics?date_from=2020-02-02&date_to=2022-02-15. The API returns analytics aggregated by days for each day, the number of comments created and the number of blocked comments.
  7. The function of automatic reply to comments if the user has enabled it for his posts. The automatic response doesn't occur immediately, but after a period of time set by the user. Also, the answer relevant to the post and comment to which the answer is being made.

Technology Stack

The project utilizes the following technologies and tools:

Backend:

  • Python programming language (OOP);
  • Django framework for building the application;
    • Django REST Framework for creating RESTful APIs;
    • Djoser for user authentication;
    • Django CORS Headers for handling Cross-Origin Resource Sharing (CORS);
    • Django Celery Beat for periodic tasks;
    • Django Celery Results for storing Celery task results;
    • DRF Spectacular for generating API documentation;
  • PostgreSQL database (Django ORM);
  • Celery for asynchronous task processing;
  • Redis as a message broker for Celery;
  • Flower for monitoring Celery tasks and workers;
  • Google GenerativeAI for generating comments;
  • python-dotenv for managing environment variables.

Version Control:

  • Git for version control and collaboration.

Environment Variables

To run this project, you will need to add the following environment variables:

SECRET_KEY DB_PORT DB_HOST DB_NAME DB_USER DB_PASSWORD CENSORED_WORDS GEMINI_API_KEY

Look at the .env.sample

Getting Started

To get started with the project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/Gubchik123/Starnavi-test-task.git
  2. Go to the project directory:

    cd Starnavi-test-task

Without Docker (without Celery & Redis, without auto comment answers)

  1. Install the required dependencies:

    pip install -r requirements.txt
  2. Set up the database connection and configurations according to the selected database engine. Apply migrations

    python manage.py migrate
  3. Run the Django development server:

    python manage.py runserver

    Note: Don't forget about environment variables

  4. Access the API Swagger documentation at:

    http://127.0.0.1:8000/api/schema/swagger/
    

With Docker (with Celery & Redis, with auto comment answers)

  1. Build the Docker image:

    docker-compose build
  2. Run the Docker container:

    docker-compose up -d
  3. Apply migrations:

    docker-compose run backend python manage.py migrate
  4. Access the API Swagger documentation at:

    http://127.0.0.1:8000/api/schema/swagger/
    

Testing

To run the tests, run the following command:

python manage.py test