Skip to content

Veritaris/SF-test-case

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SF-test-case

Test project for Solution Factory employer

Setup

Ensure that you have at least Python 3.8 installed
To setup this project execute the following code:

python3.8 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python manage.py migrate

Now app is ready to start up, but you also need to create as user:

python manage.py createsuperuser

Then prompt username, password and repeat password
Now you can run app with

python manage.py runserver

API description

Auth

To get bearer token make this request:

curl --location --request POST 'http://localhost:8000/api/v1/auth' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=<your username>>' \
--data-urlencode 'password=<your password>'

Polls

Manage polls

Requires auth with Bearer token

Required fields:
title

Optional fields:
description

Response format:

{
    "id": 2,
    "title": "New poll",
    "description": null,
    "date_created": "2021-11-08T23:44:33.775459Z",
    "questions": []
}

GET

http://localhost:8000/api/v1/polls/ID/
Get all polls if ID is missing or poll with specified id

Response format:

[
    {
        "id": 2,
        "title": "New poll",
        "description": null,
        "date_created": "2021-11-08T23:44:33.775459Z",
        "questions": []
    }
]
{
    "id": 2,
    "title": "New poll",
    "description": null,
    "date_created": "2021-11-08T23:44:33.775459Z",
    "questions": []
}

Requires auth with Bearer token
Change given poll

Optional fields:
description, title

Response format:

{
    "id": 2,
    "title": "New poll patched",
    "description": null,
    "date_created": "2021-11-08T23:49:01.085238Z",
    "questions": []
}

Requires auth with Bearer token
Delete given poll
No fields required, empty response with 204 status is returned

Questions

Manage questions of polls

Requires auth with Bearer token

Required fields:
poll_id, type, text

  • poll_id is id returned after success poll creation
  • text is a question's text
  • type is a question type. Available values: TEXT, SINGLE_CHOICE, NULTIPLE_CHOICE

Response format:

{
    "id": 6,
    "text": "Сколько времени?",
    "type": "TEXT",
    "answers": [],
    "poll_id": 1
}

Get all questions if ID is missing or question with specified id

Response format:

[
    {
        "id": 3,
        "text": "Когда спать?",
        "type": "MULTIPLE_CHOICE",
        "answers": [
            {
                "id": 1,
                "text": "Скоро",
                "question": 3,
                "voter": 1
            }
        ],
        "poll_id": 1
    },
    {
        "id": 6,
        "text": "Сколько времени?",
        "type": "TEXT",
        "answers": [],
        "poll_id": 1
    }
]
{
    "id": 2,
    "title": "New poll",
    "description": null,
    "date_created": "2021-11-08T23:44:33.775459Z",
    "questions": []
}

Requires auth with Bearer token
Change given question

Optional fields:
type, text

Response format:

{
    "id": 1,
    "text": "Добрый день",
    "type": "SINGLE_CHOICE",
    "answers": [],
    "poll_id": 1
}

Requires auth with Bearer token
Delete given question
No fields required, empty response with 204 status is returned

Answers

Voting in the given poll

Required fields:
text, question

Optional fields:
voter

  • text is a question answer
  • question is a question id
  • voter is integer ID of someone who votes. Can be null

Response format:

{
    "id": 8,
    "text": "Огонь",
    "question": 3,
    "voter": 1
}

Get all answers if ID is missing or answer with specified id

Response format:

[
    {
        "id": 6,
        "text": "Скоро",
        "question": 3,
        "voter": 1
    },
    {
        "id": 7,
        "text": "Скоро",
        "question": 3,
        "voter": 1
    },
    {
        "id": 8,
        "text": "Огонь",
        "question": 3,
        "voter": 1
    }
]
{
    "id": 2,
    "text": "Скоро",
    "question": 3,
    "voter": 1
}

Requires auth with Bearer token
After creating answer is not editable anymore unless you are admin

Requires auth with Bearer token
Delete given answer
No fields required, empty response with 204 status is returned

Voters

Requires auth with Bearer token
You can easily populate your table with new empty voters...but for what?

Required fields:
id

Response format:

{
    "id": 5,
    "voted_polls": []
}

Get all voters if ID is missing or voter with specified id

Response format:

[
    {
        "id": 1,
        "voted_polls": [
            {
                "id": 1,
                "title": "Опрос",
                "description": null,
                "date_created": "2021-11-08T22:26:07.681122Z",
                "questions": [
                    {
                        "id": 3,
                        "text": "Когда спать?",
                        "type": "MULTIPLE_CHOICE",
                        "answers": [
                            {
                                "id": 1,
                                "text": "Скоро",
                                "question": 3,
                                "voter": 1
                            },
                            {
                                "id": 2,
                                "text": "Ещё немножко",
                                "question": 3,
                                "voter": 3
                            },
                            {
                                "id": 3,
                                "text": "Почти сделал",
                                "question": 3,
                                "voter": 1
                            },
                            {
                                "id": 4,
                                "text": "Забыл тесты",
                                "question": 3,
                                "voter": 1
                            },
                            {
                                "id": 5,
                                "text": "Ушёл спать",
                                "question": 3,
                                "voter": 1
                            }
                        ],
                        "poll_id": 1
                    },
                    {
                        "id": 4,
                        "text": "Ну алло",
                        "type": "TEXT",
                        "answers": [],
                        "poll_id": 1
                    }
                ]
            }
        ]
    },
    {
        "id": 3,
        "voted_polls": []
    }
]
{
    "id": 3,
    "voted_polls": []
}

Requires auth with Bearer token
Change given voter

Optional fields:
id

I do not think that patching voter directly is a good idea

Requires auth with Bearer token
Delete given voter
No fields required, empty response with 204 status is returned

About

Test project for Solution Factory employer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages