Progress on API to retrieve comments
This commit is contained in:
parent
1521daf485
commit
f021a9ff49
1 changed files with 21 additions and 3 deletions
|
@ -2,11 +2,29 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from flask import request, jsonify
|
||||||
|
from playhouse.shortcuts import model_to_dict
|
||||||
from app import app
|
from app import app
|
||||||
|
from app.models.site import Site
|
||||||
|
from app.models.comment import Comment
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/comments", methods=['GET'])
|
@app.route("/comments", methods=['POST'])
|
||||||
def get_comments():
|
def query_comments():
|
||||||
return "OK"
|
|
||||||
|
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