system-pri/backend
2022-10-27 19:53:39 +02:00
..
app add a workload statistics endpoint for the coordinator and fix the student's view of assigning their own group for the exam 2022-10-27 19:53:39 +02:00
migrations add mode to examination schedule model and add endpoints list of examination schedule for students and project supervisors 2022-10-27 12:05:50 +02:00
tests Move backend code to separate folder 2022-05-16 22:42:08 +02:00
.dockerignore add docker 2022-05-23 14:23:22 +02:00
.env.example add cors 2022-05-17 16:33:34 +02:00
.gitignore Move backend code to separate folder 2022-05-16 22:42:08 +02:00
Dockerfile add docker 2022-05-23 14:23:22 +02:00
main.py Move backend code to separate folder 2022-05-16 22:42:08 +02:00
Readme.md rename readme for backend and add .gitignore 2022-05-17 16:13:45 +02:00
requirements.txt update requirements.txt file and reformat code 2022-10-25 20:38:47 +02:00

Installation

Python 3.8 version is required.

python3 --version

Create virtual environment and install packages

virtualenv venv
source ./venv/bin/activate
pip install -r requirements.txt

Usage

Create .env file and fill with similar data like .env.example. Then run application:

flask run

Testing

Run tests

pytest

Useful commands:

Add new package

pip install NAME_OF_PACKAGE

Save new added package to requirements

pip freeze > requirements.txt

Flask commands:

Create the application structure directories

flask startapp NAME_OF_APP

Above command create package structure:
Create serializer in __schemas__.py file:

class ExampleSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = MODEL_NAME


Create models in __models__.py file:

class Example(db.Model):
    __tablename__ = "examples"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(255), unique=True)


Create api routes in __routes__.py file. You only have to register blueprint in app/__init__.py.

from flask import Blueprint, make_response, jsonify, Response


bp = Blueprint("{name}", __name__, url_prefix="/{name}")


@bp.route("/", methods=["GET"])
def index() -> Response:
    return make_response(jsonify({{"hello": "{name}"}}), 200)


Print all your routes

flask routes

Create migration, but first you have to create model

flask db migrate

Apply your changes to database, use after migration command

flask db upgrade

If you want back changes in your databases, use below command

flask db downgrade

Create empty migration, you can write manually migration here.

flask db revision