Add 'get count of comment' method

Draft JavaScript side
This commit is contained in:
Yax 2015-05-09 20:25:35 +02:00
parent ac00f6ad33
commit 20b01caf86
4 changed files with 124 additions and 51 deletions

View file

@ -11,17 +11,13 @@ from app.helpers.hashing import md5
logger = logging.getLogger(__name__)
@app.route("/comments", methods=['GET', 'POST'])
@app.route("/comments", methods=['GET'])
def query_comments():
comments = []
try:
if request.method == 'POST':
token = request.json['token']
url = request.json['url']
else:
token = request.args.get('token', '')
url = request.args.get('url', '')
token = request.args.get('token', '')
url = request.args.get('url', '')
logger.info('retrieve comments for token %s, url %s' % (token, url))
for comment in Comment.select(Comment).join(Site).where(
@ -44,3 +40,19 @@ def query_comments():
r = jsonify({'data': []})
r.status_code = 400
return r
@app.route("/comments/count", methods=['GET'])
def get_comments_count():
try:
token = request.args.get('token', '')
url = request.args.get('url', '')
count = Comment.select(Comment).join(Site).where(
(Comment.url == url) &
(Site.token == token)).count()
r = jsonify({'count': count})
r.status_code = 200
except:
r = jsonify({'count': 0})
r.status_code = 200
return r