Skip to content

PyBites-Open-Source/questionnaire-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Open Issues Forks Stars Build Maintained Made with Python Open Source Love Built with Love PyBites/Opentrivia

THIS PROJECT IS UNDER ACTIVE DEVELOPMENT, README MAY CHANGE EVERY ONCE IN A WHILE

Index

About

This will be a free to use, open sourced questions database which has a REST API implemented in Python3 & Flask using PostgresSQL database, also this will be a source for a minimal quizzing website which will also let contributors add new questions in multiple categories and as MCQ or T/F types.

Usage

To use this project.

Installation

Development

If you want just to do a simple test run of the application, you can install and use it with development config.

  • Clone the repository
$ git clone https://github.com/PyBites-Open-Source/questionnaire-api.git
  • Create the virtualenv and activate it
$ cd questionnaire-api
$ python -m venv virtualenv
$ source virtualenv/bin/activate # unix
$ .\virtualenv\Scripts\activate  # windows
  • Install requirements
$ pip3 install -r ./src/requirements.txt
  • Create database and apply migrations
$ cd src && flask db upgrade
  • Run the application
$ cd src && flask run

Production

In order to use postgresql database ready for production, you need to use docker and to add some additional environment variables.

  • Setup database
# create .env file wihtin src folder with the following environment variables. 
POSTGRES_USER="trivia"
POSTGRES_PASSWORD="trivia"
POSTGRES_DB_PROD="opentrivia_prod"
POSTGRES_DB_TEST="opentrivia_test"
DB_PORT="5432"
DB_HOST="localhost"

# if you want to change these settings you have to change also the init.sql file 
# from db folder. 
  • Run the application
$ cd src && docker-compose up

File Structure

  • Add a file structure here with the basic details about files, below is an example.
.
β”œβ”€β”€ docker
β”‚Β Β  β”œβ”€β”€ api-server
β”‚Β Β  β”‚Β Β  └── Dockerfile
β”‚Β Β  └── db-server
β”‚Β Β      └── Dockerfile
β”œβ”€β”€ logo
β”‚Β Β  └── opentrivia.png
β”œβ”€β”€ src
β”‚Β Β  β”œβ”€β”€ app
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ api
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ routes
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ answers.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ categories.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── questions.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ tests
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ test_answers.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ test_categories.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── test_questions.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ models
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ answer.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ category.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── question.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ static
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── swagger.json
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ templates
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ base.html
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ developer.html
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── home.html
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  └── views.py
β”‚Β Β  β”œβ”€β”€ db
β”‚Β Β  β”‚Β Β  └── init.sql
β”‚Β Β  β”œβ”€β”€ instance
β”‚Β Β  β”‚Β Β  └── dev_opentrivia.db
β”‚Β Β  β”œβ”€β”€ migrations
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ versions
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── 798672a50ee1_.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ README
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ alembic.ini
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ env.py
β”‚Β Β  β”‚Β Β  └── script.py.mako
β”‚Β Β  β”œβ”€β”€ tests
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  └── test_opentrivia.py
β”‚Β Β  β”œβ”€β”€ config.py
β”‚Β Β  β”œβ”€β”€ docker-compose.yml
β”‚Β Β  β”œβ”€β”€ requirements.txt
β”‚Β Β  └── run.py
β”œβ”€β”€ CONTRIBUTING.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
└── _config.yml

Guideline

  • Code Style

In order to maintain the code style consistency across entire project we use a code formatter. Therefore, we kindly suggest you to do the same whenever you push commits to this project.

The python code formatter we chose is called black. Black is a great tool and it can be installed quickly by running

pip install black.

or

python3.6 -m pip install black

It requires Python 3.6.0+ to run.

  • Usage

black {source_file_or_directory}

For more details and available options, please check the GitHub project.

  • Close Issues

Close issues using keywords: how to ?

Gallery

Endpoints

Available Views

Available Endpoints

  • Questions
    • GET api/v1/questions (Get all Questions)
    • GET api/v1/questions/<id> (Get Question)
    • POST api/v1/questions (Create new Question)
    • PUT api/v1/questions/<id> (Update Question)
    • DELETE api/v1/questions/<id> (Delete Question)
  • Answers
    • GET api/v1/answers/<id> (Get Answer)
    • POST api/v1/answers (Create new Answer)
    • PUT api/v1/answers/<id> (Update Answer)
    • DELETE api/v1/answers/<id (Delete Answer)
  • Categories
    • GET api/v1/categories (Get all Categories)
    • GET api/v1/categories/<id> (Get Category)
    • POST api/v1/categories (Create new Category)
    • PUT GET api/v1/categories/<id> (Update Category)
    • DELETE GET api/v1/categories/<id> (Delete Category)

feel free to add more functionalities endpoint url structure: /api/v1/. . .

Credit/Acknowledgment

Contributors

License

License