Skip to content

Commit

Permalink
Fix comment offset/limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Temmmmmo authored Oct 29, 2024
1 parent ca54781 commit 8d01462
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 8d01462

Please sign in to comment.