diff options
| author | Santo Cariotti <dcariotti24@gmail.com> | 2020-04-06 19:54:53 +0000 |
|---|---|---|
| committer | Santo Cariotti <dcariotti24@gmail.com> | 2020-04-06 19:54:53 +0000 |
| commit | 3a2246e26e9febe3c15e2ddc1e7e6f320f86fe15 (patch) | |
| tree | 9cbd95771d38dfd66bedb4a447470391d34a68eb /src/frest/templates/routes.txt | |
| parent | 6188a952974b3e268936beb1027ea58fbfaa67aa (diff) | |
chore: move package in frest folder
Diffstat (limited to 'src/frest/templates/routes.txt')
| -rw-r--r-- | src/frest/templates/routes.txt | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/src/frest/templates/routes.txt b/src/frest/templates/routes.txt deleted file mode 100644 index 11ba63a..0000000 --- a/src/frest/templates/routes.txt +++ /dev/null @@ -1,88 +0,0 @@ -from flask import Blueprint, request, abort -from frest.utils import http_call, model_serialize -from frest.decorators import check_token, admin_required -from .models import %%NAME%% -from .forms import %%NAME%%Form -from database import db -import json -from datetime import datetime -from pytz import timezone - -api = Blueprint("%%name%%s", __name__) - - -@api.route("/api/%%name%%") -def all_%%name%%s(): - return http_call( - [ - model_serialize(i, params="%%params%%") - for i in %%NAME%%.query.all() - ], - 200, - ) - - -@api.route("/api/%%name%%/<%%name%%Id>") -def get_%%name%%(%%name%%Id): - %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id).first() - if not %%first_char%%: - abort(404) - - return http_call(model_serialize(%%first_char%%, params="%%params%%"), 200) - - -@api.route("/api/%%name%%/<%%name%%Id>", methods=["DELETE"]) -@check_token -def delete_%%name%%(%%name%%Id): - %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id) - if not %%first_char%%: - abort(404) - - deleted = %%first_char%%.delete() - db.session.commit() - - return http_call({"delete": deleted}, 200) - - -@api.route("/api/%%name%%", methods=["POST"]) -@check_token -def new_%%name%%(): - if not request.json: - abort(400) - - form = %%NAME%%Form(request.json) - - if form.is_valid(): - %%first_char%% = %%NAME%%( - %%params_form%% - ) - db.session.add(%%first_char%%) - - db.session.commit() - - return http_call({"%%name%%Id": %%first_char%%.%%name%%Id}, 201) - - abort(400) - - -@api.route("/api/%%name%%/<%%name%%Id>", methods=["PUT"]) -@check_token -def edit_%%name%%(%%name%%Id): - if not request.json: - abort(400) - - form = %%NAME%%Form(request.json) - - if form.is_valid(): - %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id).first() - if not %%first_char%%: - abort(404) - - %%params_put%% - %%first_char%%.updated_at = datetime.now(timezone("Europe/Rome")) - - db.session.commit() - - return http_call({"%%name%%Id": %%first_char%%.%%name%%Id}, 200) - - abort(400) |
