Skip to content

Задача: спроектировать и разработать API для системы опросов пользователей

Notifications You must be signed in to change notification settings

ImmortalRabbit/pollMaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

pollMaker

Задача: спроектировать и разработать API для системы опросов пользователей

Installation requirements

  • python3.7
  • Django2.2.10
  • djangorestframework3.11.0

Installation guide

cd pollMaker/
pip install -r requirements.txt
cd pollMaker/
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

API documentation

To get user token:

curl --location --request GET 'http://localhost:8000/api/login/' \
--form 'username=%username' \
--form 'password=%password'

To create poll:

  • Request method: POST
  • URL: http://localhost:8000/api/poll/create/
  • Header:
    • Authorization: Token userToken
  • Body:
    • poll_name: name of poll
    • pub_date: publication date can be set only when poll is created, format: YYYY-MM-DD HH:MM:SS
    • end_date: poll end date, format: YYYY-MM-DD HH:MM:SS
    • Poll_description: description of poll
  • Example:
curl --location --request POST 'http://localhost:8000/api/poll/create/' \
--header 'Authorization: Token %userToken' \
--form 'poll_name=%poll_name' \
--form 'pub_date=%pub_date' \
--form 'end_date=%end_date \
--form 'poll_description=%poll_description'

To update poll:

  • Request method: PATCH
  • URL: http://localhost:8000/api/poll/update/[poll_id]/
  • Header:
    • Authorization: Token userToken
  • Param:
    • poll_id
  • Body:
    • poll_name: name of poll
    • end_date: poll end date, format: YYYY-MM-DD HH:MM:SS
    • Poll_description: description of poll
  • Example:
curl --location --request PATCH 'http://localhost:8000/api/poll/update/[poll_id]/' \
--header 'Authorization: Token %userToken' \
--form 'poll_name=%poll_name' \
--form 'end_date=%end_date \
--form 'poll_description=%poll_description'

To delete poll:

curl --location --request DELETE 'http://localhost:8000/api/poll/update/[poll_id]/' \
--header 'Authorization: Token %userToken'

To view all polls:

curl --location --request GET 'http://localhost:8000/api/poll/view/' \
--header 'Authorization: Token %userToken'

To view currently active polls:

curl --location --request GET 'http://localhost:8000/api/poll/view/active/' \
--header 'Authorization: Token %userToken'

To create question:

curl --location --request POST 'http://localhost:8000/api/question/create/' \
--header 'Authorization: Token %userToken' \
--form 'poll=%poll' \
--form 'question_text=%question_text' \
--form 'question_type=%question_type \

To update question:

curl --location --request PATCH 'http://localhost:8000/api/question/update/[question_id]/' \
--header 'Authorization: Token %userToken' \
--form 'poll=%poll' \
--form 'question_text=%question_text' \
--form 'question_type=%question_type \

To delete question:

curl --location --request DELETE 'http://localhost:8000/api/question/update/[question_id]/' \
--header 'Authorization: Token %userToken' \
--form 'poll=%poll' \
--form 'question_text=%question_text' \
--form 'question_type=%question_type \

To create choice:

curl --location --request POST 'http://localhost:8000/api/choice/create/' \
--header 'Authorization: Token %userToken' \
--form 'question=%question' \
--form 'choice_text=%choice_text'

To update choice:

curl --location --request PATCH 'http://localhost:8000/api/choice/update/[choice_id]/' \
--header 'Authorization: Token %userToken' \
--form 'question=%question' \
--form 'choice_text=%choice_text'

To delete choice:

curl --location --request DELETE 'http://localhost:8000/api/choice/update/[choice_id]/' \
--header 'Authorization: Token %userToken' \
--form 'question=%question' \
--form 'choice_text=%choice_text'

To create answer:

  • Request method: POST
  • URL: http://localhost:8000/api/answer/create/
  • Header:
    • Authorization: Token userToken
  • Body:
    • poll: id of poll
    • question: id of question
    • choice: if question type is one or multiple then it’s id of choice else null
    • choice_text: if question type is text then it’s text based answer else null
  • Example:
curl --location --request POST 'http://localhost:8000/api/answer/create/' \
--header 'Authorization: Token %userToken' \
--form 'poll=%poll' \
--form 'question=%question' \
--form 'choice=%choice \
--form 'choice_text=%choice_text'

To update answer:

  • Request method: PATCH
  • URL: http://localhost:8000/api/answer/update/[answer_id]/
  • Header:
    • Authorization: Token userToken
  • Param:
    • answer_id
  • Body:
    • poll: id of poll
    • question: id of question
    • choice: if question type is one or multiple then it’s id of choice else null
    • choice_text: if question type is text then it’s text based answer else null
  • Example:
curl --location --request PATCH 'http://localhost:8000/api/answer/update/[answer_id]' \
--header 'Authorization: Token %userToken' \
--form 'poll=%poll' \
--form 'question=%question' \
--form 'choice=%choice \
--form 'choice_text=%choice_text'

To delete answer:

curl --location --request DELETE 'http://localhost:8000/api/answer/update/[answer_id]' \
--header 'Authorization: Token %userToken'

To view answers of user:

curl --location --request GET 'http://localhost:8000/api/answer/view/[user_id]' \
--header 'Authorization: Token %userToken'

About

Задача: спроектировать и разработать API для системы опросов пользователей

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages