Skip to content

Commit

Permalink
Fix sorting was ignored for submission lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mraron committed Nov 28, 2023
1 parent 8a00521 commit 6833e08
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/njudge/db/submissionlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ func (s *SubmissionListQuery) getSubmissionList(ctx context.Context, req njudge.
return nil, -1, err
}

if req.SortField != "" {
inv := req.SortDir == njudge.SortDESC
sort.Slice(res, func(i, j int) bool {
switch req.SortField {
case njudge.SubmissionSortFieldScore:
return inv != (res[i].Score < res[j].Score)
default:
return inv != (res[i].ID < res[j].ID)
}
})
}

cnt, err := models.Submissions(filterMods...).Count(ctx, s.db)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return nil, -1, err
Expand Down

0 comments on commit 6833e08

Please sign in to comment.