diff options
| author | Santo Cariotti <dcariotti24@gmail.com> | 2020-03-20 11:15:21 +0000 |
|---|---|---|
| committer | Santo Cariotti <dcariotti24@gmail.com> | 2020-03-20 11:15:21 +0000 |
| commit | d880d90e6d6d0cade731ae43ab40934928c20ba4 (patch) | |
| tree | 91a70553e4ddf248095b2b89e6bfdd98f05f82d4 /src/frest/templates/route.rst | |
| parent | ce12b3c0916958819d3e5cec5c3609e204b28ad8 (diff) | |
chore: rename templates in txt
Diffstat (limited to 'src/frest/templates/route.rst')
| -rw-r--r-- | src/frest/templates/route.rst | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/src/frest/templates/route.rst b/src/frest/templates/route.rst deleted file mode 100644 index a24a3b1..0000000 --- a/src/frest/templates/route.rst +++ /dev/null @@ -1,88 +0,0 @@ -from flask import Blueprint, request, abort -from fapi.utils import http_call, model_serialize -from fapi.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) |
