From 119d2aaabedc678bd94e07d12d3192ab5ad862f1 Mon Sep 17 00:00:00 2001 From: Fulgen301 Date: Sun, 16 Sep 2018 17:48:50 +0200 Subject: uploads: Fix GET /api/uploads, always return comment and vote on creation --- routes/uploads.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'routes/uploads.py') diff --git a/routes/uploads.py b/routes/uploads.py index 3777795..40d9426 100644 --- a/routes/uploads.py +++ b/routes/uploads.py @@ -46,7 +46,7 @@ def _add_upload(entry : Upload, session : DBSession): votes = session.query(Vote).filter_by(upload=entry) e["voting"] = { - "sum" : sum(i.vote for i in votes), + "sum" : sum(i.impact for i in votes), "count" : votes.count() } @@ -187,16 +187,18 @@ def post_comments(id): raise HTTPResponse("Invalid upload id", 404) try: - session.add(Comment( + + comment = Comment( body=request_data()["body"], author=get_user(session), upload=upload - )) + ) except KeyError as e: raise HTTPResponse(f"Missing json value: {e.args[0]}", 400) + session.add(comment) session.commit() - return HTTPResponse(status=201) + return comment.json() @delete("/api/uploads//comments/") @jwt_auth_required @@ -241,4 +243,4 @@ def post_vote(id): vote.impact = request_data()["impact"] session.add(vote) session.commit() - return HTTPResponse(status=204) + return vote.json() -- cgit v1.2.3-54-g00ecf