Progress on API to retrieve comments
This commit is contained in:
parent
a0bb9938fa
commit
6681a721a2
1 changed files with 21 additions and 3 deletions
|
@ -2,11 +2,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
from flask import request, jsonify
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
from app import app
|
||||
from app.models.site import Site
|
||||
from app.models.comment import Comment
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@app.route("/comments", methods=['GET'])
|
||||
def get_comments():
|
||||
return "OK"
|
||||
@app.route("/comments", methods=['POST'])
|
||||
def query_comments():
|
||||
|
||||
query = request.json
|
||||
token = query['token']
|
||||
url = query['url']
|
||||
logger.info('token=%s url=%s' % (token, url))
|
||||
|
||||
comments = []
|
||||
for comment in Comment.select(Comment).join(Site).where(
|
||||
(Comment.url == url) &
|
||||
(Site.token == token)).order_by(Comment.published):
|
||||
comments.append(model_to_dict(comment))
|
||||
|
||||
r = jsonify({'data': comments})
|
||||
r.status_code = 200
|
||||
return r
|
||||
|
|
Loading…
Add table
Reference in a new issue