Skip to content

mikhalexandr/mathusha-api

Repository files navigation

Mathusha API

License Python Version Version Contributions welcome

API which is written for the Mathusha service. It interacts with user data and also has the ability to perform admin requests

Note

Other project repositories: mobile, web, telegram-bot

πŸ› οΈ Tech Stack

γ…€Python Flask SQLAlchemy Keycloak Yandex GPT Shell Script Docker

🎯 Quick Start

  • Clone the project to your computer from Github using the command:
git clone https://github.com/mikhalexandr/mathusha-api.git
  • Install all required dependencies from requirements.txt:
pip install requirements.txt
  • create .env in the project folder and paste these lines there:
SECRET_KEY=your_secret_key

YANDEX_GPT_DIRECTORY_ID=your_yandex_gpt_directory_id
YANDEX_GPT_API_KEY=your_yandex_gpt_api_key

KEYCLOAK_SERVER_URL=your_keycloak_server_url
KEYCLOAK_USER_REALM_NAME=your_keycloak_realm_name
KEYCLOAK_CLIENT_ID=your_keycloak_client_id
KEYCLOAK_CLIENT_SECRET_KEY=your_keycloak_client_secret_key
  • Run app.py

Tip

To create a docker container use Dockerfile and docker-compose.yml

Tip

To host the API on Glitch use start.sh

πŸ“ Documentation

🧩 SQLAlchemy Database Structure

  • Users Table
    • name - user's name -> str
    • hashed_password - user's hashed password -> str
    • level_amount - number of levels completed by the user -> int (default=0)
    • time - amount of time spent by the user on completion (in seconds) -> int (default=0)

πŸ“¬ Requests

πŸ‘¨β€πŸ’Ό Admin

  • Achievements Requests
    • GET "/api/admin/achievements"
      • returns list of achievements (body: list[id -> int, name -> str, decription -> str] + list of files)
    • PATCH "/api/admin/achievement" (body: id -> int, name -> str, decription -> str + file)
      • updates achievement data
    • DELETE "/api/admin/achievemnt" (body: id -> int)
      • deletes achievemnt
  • Statistics Requests
    • GET "/api/admin/statistics"
      • returns lists of topics, users and achievements for data analysis (topics -> list, users -> list, achievements -> list)
  • Topics Requests
    • GET "/api/admin/topics"
      • returns topics list (body: list[id -> int, name -> str, decription -> str] + list of files)
    • POST "/api/admin/topic" (body: name -> str, decription -> str + file + excel_file)
      • adds new topic
    • PATCH "/api/admin/topic" (body: id -> int, name -> str, decription -> str + file)
      • updates topic
    • DELETE "/api/admin/topic" (body: id -> int)
      • delete topic

πŸ™β€β™‚οΈ User

  • User profile Requests
    • GET "/api/user"
      • returns user profile information (body: username -> str, rating -> int, place_in_top -> int + file)
    • PUT "/api/user/photo" (body: file)
      • updates user photo
    • DELETE "/api/user/photo"
      • deletes user photo
  • Topics Requests
    • GET "/api/user/topics" (body: lang -> str)
      • returns list of topics (body: list[id -> int, name -> str, photo -> str] + list of files)
    • GET "/api/user/topic_description" (body: id -> int, lang -> str)
      • returns topic description (body: description -> str)
    • GET "/api/user/topics_for_mix" (body: lang -> str)
      • returns list of topics for mix (list[id -> int, name -> str])
  • Tasks Requests
    • GET "/api/user/task" (body: id -> int, complexity -> int, tasks_for_mix -> list, lang -> str)
      • returns topic task (body: problem -> str, solution -> str)
    • PATCH "/api/user/solved_task" (body: id -> int, complexity -> int)
      • updates user and topic ratings
  • Achievements Requests
    • GET "/api/user/achievements" (body: lang -> str)
      • returns list of achievements (body: list[id -> int, name -> str, deccription -> str, photo -> str, unlocked -> int] + list of files)
  • Progress Requests
    • GET "/api/user/progress" (body: lang -> str)
      • returns topics information (body: list[id -> int, name -> str, color -> str, easy_solved_tasks -> int, medium_solved_tasks -> int, hard_solved_tasks -> int, solved_tasks -> int])
  • Rating Requests
    • GET "/api/user/rating"
      • returns sorted user list for rating (body: rating -> list[id -> int, username -> str, rating -> int], user_info -> tuple[list[id -> int, username -> str, rating -> int], place_in_top -> int], leaders -> list[id -> int] + list of files)