Giter Site home page Giter Site logo

polling-api's Introduction

Polling API


linter-check Maintainability


Installation

Package was created with poetry.

  -- install poetry
% pip3 install --upgrade poetry

  -- clone repo
% git clone https://github.com/mnogom/polling.git
% cd polling

  -- create and setup virtual env
% python3 -m venv .venv
% poetry env use .venv/bin/python
% make install
% mv .example_env .env

  -- migrations and migrate
% make migrations
% make migrate

  -- run with manage.py
% make run

  -- setup gunicorn
% source .venv/bin/activate
% export DJANGO_SETTINGS_MODULE=polling_app.settings
% deactivate
  -- run with gunicorn
% make gunicorn-run

  -- run manage.py shell
% make django-shell

Usage

Admin panel

  • Path: /admin
  • Description: From admin panel you can create quizzes. Quiz is set of questions. Questions has types: 1 - Single choice question, 2 - multiple choices questions, 3 - Text answer

Quiz references

look for examples below

  1. Get all quizzes

    • GET /api/quizzes
    • Description: Get list of quizzes. Allow query params: ?group=all to get all quizzes or ?group=active to get active quizzes. Default: group is "active"
  2. Get detailed quiz by id

    • GET /api/quizzes/<int:quiz_id>
    • Description: Get detailed quiz by id

User references

look for examples below

  1. Create new user

    • Post [type: application/json] /api/users
    • Description: create new user
  2. Get history of user quizzes

    • GET /api/users/<int:user_id>/quizzes
    • Description: Get users's history of completed quizzes
  3. Get detailed history of quiz for user

    • GET /api/users/<int:user_id>/quizzes/<int:quiz_id>
    • Description: Get user's detailed completed quiz
  4. Save user answers for quiz

    • POST [type: application/json] /api/users/<int:user_id>/quizzes/<int:quiz_id>
    • Description: Save user's answers for quiz

TODO

  1. Make quiz adding interface easier
  2. Add tests
  3. Client part

Examples

  • GET /api/quizzes and /api/quizzes?group=active:
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "quizzes": [
        {
            "id": 1,
            "name": "What is your best color?",
            "date_start": "2021-05-13",
            "date_end": "2021-05-24",
            "description": "May be red?"
        },
        {
            "id": 2,
            "name": "Who is Mr. Chechill?",
            "date_start": "2021-05-14",
            "date_end": "2021-05-24",
            "description": "Do you know?"
        }
    ]
}
  • GET /api/quizzes?group=all
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "quizzes": [
        {
            "id": 3,
            "name": "Some old quiz",
            "date_start": "2021-05-02",
            "date_end": "2021-05-13",
            "description": "Nevermind"
        },
        {
            "id": 1,
            "name": "What is your best color?",
            "date_start": "2021-05-13",
            "date_end": "2021-05-24",
            "description": "May be red?"
        },
        {
            "id": 2,
            "name": "Who is Mr. Chechill?",
            "date_start": "2021-05-14",
            "date_end": "2021-05-24",
            "description": "Do you know?"
        },
        {
            "id": 4,
            "name": "Brand new quiz",
            "date_start": "2021-05-31",
            "date_end": "2021-06-30",
            "description": "It will blow your mind"
        }
    ]
}
  • GET /api/quizzes/1
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1,
    "name": "What is your best color?",
    "date_start": "2021-05-13",
    "date_end": "2021-05-24",
    "description": "May be red?",
    "questions": [
        {
            "id": 1,
            "text": "Is it red?",
            "type": 1,
            "choices": [
                {
                    "id": 1,
                    "text": "red"
                },
                {
                    "id": 2,
                    "text": "green"
                }
            ]
        },
        {
            "id": 2,
            "text": "Is it green?",
            "type": 2,
            "choices": [
                {
                    "id": 3,
                    "text": "red"
                },
                {
                    "id": 4,
                    "text": "green"
                }
            ]
        }
    ]
}
HTTP 404 Not Found
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Quiz 23 doesn't exists"
}
  • POST /api/users
Post data example

{
  "username": "Sherlock Holmes"
}
HTTP 200 OK
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "user saved",
    "user_id": 7
}
HTTP 400 Bad Request
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "data must contains \"username\",but it contains ['wrong_key']"
}
  • GET /api/users/3/quizzes
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "quizzes": [
        {
            "id": "1",
            "quiz_text": "What is your best color?"
        },
        {
            "id": "2",
            "quiz_text": "Who is Mr. Chechill?"
        }
    ]
}
HTTP 400 Bad Request
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "User 13 doesn't exists"
}
  • GET /api/users/3/quizzes/2
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "quiz": {
        "id": 2,
        "name": "Who is Mr. Chechill?",
        "question": [
            {
                "id": 3,
                "text": "Do you know?",
                "choices": [
                    {
                        "id": 5,
                        "text": "yes",
                        "answer": "0"
                    },
                    {
                        "id": 6,
                        "text": "no",
                        "answer": "1"
                    }
                ]
            },
            {
                "id": 4,
                "text": "So?",
                "choices": [
                    {
                        "id": 7,
                        "text": "placeholder",
                        "answer": "Person"
                    }
                ]
            }
        ]
    }
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "User 3 didn't complete quiz 10"
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "User 100 doesn't exists"
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Quiz 10 doesn't exists"
}
  • POST /api/users/7/quizzes/2
Post data example

{
  "answers": [
    {
      "choice_id": 5,
      "value": "0"
    },
    {
      "choice_id": 6,
      "value": "1"
    },
    {
      "choice_id": 7,
      "value": "British statesman and politician"}
  ]
}
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Quiz saved"
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "User 7 already pass Quiz 2"
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Keys in data not full"
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Data choices IDs doesn't similar with Question choices IDs"
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "data[\"answers\"] must be \"list\"but it type is <class 'int'>"
}
HTTP 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Question ID 3 has only one answer"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.