From 6833e08065b1c8b40baa91790a9dd90c5b76d4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ron=20Nosz=C3=A1ly?= Date: Tue, 28 Nov 2023 19:02:59 +0100 Subject: [PATCH] Fix sorting was ignored for submission lists --- internal/njudge/db/submissionlist.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/njudge/db/submissionlist.go b/internal/njudge/db/submissionlist.go index 7aa400f2..4cff2539 100644 --- a/internal/njudge/db/submissionlist.go +++ b/internal/njudge/db/submissionlist.go @@ -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