From 74f7b5bdbab12ca25957b2ef16dbaa3435acff4a Mon Sep 17 00:00:00 2001 From: Andreas Lenhardt Date: Fri, 26 Apr 2024 14:18:37 +0200 Subject: [PATCH] orderBy in task_comments.go --- pkg/models/task_comments.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/models/task_comments.go b/pkg/models/task_comments.go index 108273208..44a2bb959 100644 --- a/pkg/models/task_comments.go +++ b/pkg/models/task_comments.go @@ -18,6 +18,7 @@ package models import ( "time" + "fmt" "code.vikunja.io/api/pkg/db" @@ -37,6 +38,9 @@ type TaskComment struct { Author *user.User `xorm:"-" json:"author"` TaskID int64 `xorm:"not null" json:"-" param:"task"` + // The query parameter to order the items by. This can be either asc or desc, with asc being the default. + OrderBy []string `query:"order_by" json:"order_by"` + Reactions ReactionMap `xorm:"-" json:"reactions"` Created time.Time `xorm:"created" json:"created"` @@ -270,7 +274,7 @@ func (tc *TaskComment) ReadAll(s *xorm.Session, auth web.Auth, search string, pa query := s. Where(builder.And(where...)). Join("LEFT", "users", "users.id = task_comments.author_id"). - OrderBy("task_comments.created asc") + OrderBy(fmt.Sprintf("task_comments.created %s", tc.OrderBy[0])) if limit > 0 { query = query.Limit(limit, start) }