def get(self, id): message = db.session.query(MessageModel).filter_by(id=id).first() if message is None: abort(404) res = MessageSchema().dump(message).data return res
def post(self): args = self.reqparse.parse_args() hoge = MessageModel(args.sentence, args.thread_id, args.sender_id) db.session.add(hoge) db.session.commit() res = MessageSchema().dump(hoge).data return res, 201
from flask import Blueprint, request, jsonify, g from models.message import Message, MessageSchema from lib.secure_route import secure_route api = Blueprint('messages', __name__) messages_schema = MessageSchema(many=True) message_schema = MessageSchema() @api.route('/messages', methods=['GET']) def index(): messages = Message.query.all() return messages_schema.jsonify(messages) @api.route('/messages/<int:message_id>', methods=['GET']) def show(message_id): message = Message.query.get(message_id) return message_schema.jsonify(message)
from flask import Blueprint, request, jsonify, g from models.story import Story, StorySchema from lib.secure_route import secure_route from models.message import Message, MessageSchema api = Blueprint('message', __name__) message_schema = MessageSchema() # === message show === @api.route('/messages/<int:message_id>', methods=['GET']) @secure_route def show(message_id): message = Message.query.get(message_id) return message_schema.jsonify(message), 200
def get(self, thread_id): results = MessageModel.query.filter_by(thread_id=thread_id).all() jsonData = MessageSchema(many=True).dump(results).data #jsonData = json.dumps(results) # print(results) return jsonify({'items': jsonData})