diff options
Diffstat (limited to 'pgcommitfest/commitfest/api.py')
-rw-r--r-- | pgcommitfest/commitfest/api.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pgcommitfest/commitfest/api.py b/pgcommitfest/commitfest/api.py index ea12043..1c97ef1 100644 --- a/pgcommitfest/commitfest/api.py +++ b/pgcommitfest/commitfest/api.py @@ -4,6 +4,7 @@ from django.conf import settings from django.views.decorators.csrf import csrf_exempt from functools import wraps from django.utils.decorators import available_attrs +from django.db import connection import json @@ -29,3 +30,47 @@ def active_commitfests(request): ] return HttpResponse(json.dumps(res), content_type='application/json') + +@api_authenticate +def commitfest(request, cfid): + cf = get_object_or_404(CommitFest, pk=cfid) + + whereclauses = [] + params = { 'cid': cf.id } + if 'since' in request.GET: + whereclauses.append("latestmessage > %(since)s") + params['since'] = request.GET['since'] + + if whereclauses: + wherestring = 'AND ({0})'.format( + ' AND '.join(whereclauses) + ) + else: + wherestring = '' + + curs = connection.cursor() + curs.execute("""SELECT p.id, p.name, poc.status, + json_agg(json_build_object( + 'msgid', mt.messageid, + 'first', mt.firstmessage, + 'latest', mt.latestmessage, + 'attachments', attachments + )) AS threads +FROM commitfest_patch p +INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id=p.id +LEFT JOIN ( + SELECT mtp.patch_id, t.messageid, t.firstmessage, t.latestmessage, + json_agg(json_build_object('messageid', mta.messageid, 'attachmentid', mta.attachmentid, 'filename', mta.filename, 'time', mta.date)) AS attachments + FROM commitfest_mailthread_patches mtp + INNER JOIN commitfest_mailthread t ON t.id=mtp.mailthread_id + LEFT JOIN commitfest_mailthreadattachment mta ON mta.mailthread_id=t.id + GROUP BY mtp.patch_id, t.id + ) AS mt ON mt.patch_id=p.id +WHERE poc.commitfest_id=%(cid)s {0} +GROUP BY p.id, poc.id""".format(wherestring), params) + + res = { + 'patches': [dict(zip([col[0] for col in curs.description], row)) for row in curs.fetchall()], + } + return HttpResponse(json.dumps(res), + content_type='application/json') |