diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index f1821e6..e3a701e 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -85,9 +85,7 @@ async def get_comments( comments = Comment.query(session=db.session).all() if not comments: raise ObjectNotFound(Comment, 'all') - result = CommentGetAll(limit=limit, offset=offset, total=len(comments)) - for comment in comments[offset : limit + offset]: - result.comments.append(comment) + result = CommentGetAll(limit=limit, offset=offset, total=len(comments), comments=comments) if lecturer_id: result.comments = [comment for comment in result.comments if comment.lecturer_id == lecturer_id] if unreviewed: @@ -99,6 +97,9 @@ async def get_comments( raise ForbiddenAction(Comment) else: result.comments = [comment for comment in result.comments if comment.review_status is ReviewStatus.APPROVED] + + result.comments = result.comments[offset : limit + offset] + if "create_ts" in order_by: result.comments.sort(key=lambda comment: comment.create_ts) result.total = len(result.comments)