From 479a987b75b9031a22e6944e3c12623014b61b3a Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Thu, 1 Feb 2018 22:40:22 +0100 Subject: [PATCH] Update request --- Pipfile | 1 + app.py | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Pipfile b/Pipfile index 944fb21..19f4e5a 100644 --- a/Pipfile +++ b/Pipfile @@ -20,3 +20,4 @@ python-dotenv = "*" flask-script = "*" flask-migrate = "*" faker = "*" +flask-restplus-patched = "*" diff --git a/app.py b/app.py index 0ae1777..52b228d 100644 --- a/app.py +++ b/app.py @@ -1,26 +1,26 @@ # -*- coding: utf-8 -*- + # Librarys +# ========================= import os -from flask import Flask, jsonify +from flask import Flask, jsonify, request from flask_restplus import Resource, Api from dotenv import load_dotenv, find_dotenv from models import db, User, News, Comment +# Extensions initialization +# ========================= load_dotenv(find_dotenv()) - - app = Flask(__name__) +api = Api(app) -# Config Flask + +# Configurations +# ========================= app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY') - -# Config Database app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URI') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) - -# Config API -api = Api(app) PRE_URL = '/api/v1/' @@ -50,10 +50,10 @@ class NewsList(Resource): def get(self): my_news = News.query.all() - return jsonify([i.serialize for i in my_news]) + return serializeQuery(my_news) def post(self): - return {'hello': 'world'} + return request.form @api.route(PRE_URL + 'news/') @@ -73,6 +73,10 @@ class Comments(Resource): return {'hello': 'world'} +def serializeQuery(query): + return jsonify([i.serialize for i in query]) + + if __name__ == '__main__': app.run(debug=os.environ.get('DEBUG') == 'True' if True else False)