fix: order by clause in task comments
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kolaente 2023-08-31 15:44:59 +02:00
parent 5392ca788c
commit 5811d2a13b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 12 additions and 8 deletions

@ -238,13 +238,17 @@ func (tc *TaskComment) ReadAll(s *xorm.Session, auth web.Auth, search string, pa
limit, start := getLimitFromPageIndex(page, perPage)
comments := []*TaskComment{}
where := []builder.Cond{
builder.Eq{"task_id": tc.TaskID},
}
if search != "" {
where = append(where, db.ILIKE("comment", search))
}
query := s.
Where(builder.And(
builder.Eq{"task_id": tc.TaskID},
db.ILIKE("comment", search),
)).
Where(builder.And(where...)).
Join("LEFT", "users", "users.id = task_comments.author_id").
OrderBy("id", "asc")
OrderBy("task_comments.id asc")
if limit > 0 {
query = query.Limit(limit, start)
}

@ -214,8 +214,8 @@ func TestTaskComment_ReadAll(t *testing.T) {
tc := &TaskComment{TaskID: 1}
u := &user.User{ID: 1}
result, resultCount, total, err := tc.ReadAll(s, u, "", 0, -1)
resultComment := result.([]*TaskComment)
assert.NoError(t, err)
resultComment := result.([]*TaskComment)
assert.Equal(t, 1, resultCount)
assert.Equal(t, int64(1), total)
assert.Equal(t, int64(1), resultComment[0].ID)
@ -241,8 +241,8 @@ func TestTaskComment_ReadAll(t *testing.T) {
tc := &TaskComment{TaskID: 35}
u := &user.User{ID: 1}
result, _, _, err := tc.ReadAll(s, u, "", 0, -1)
comments := result.([]*TaskComment)
assert.NoError(t, err)
comments := result.([]*TaskComment)
assert.Len(t, comments, 2)
var foundComment bool
for _, comment := range comments {
@ -261,8 +261,8 @@ func TestTaskComment_ReadAll(t *testing.T) {
tc := &TaskComment{TaskID: 35}
u := &user.User{ID: 1}
result, _, _, err := tc.ReadAll(s, u, "COMMENT 15", 0, -1)
resultComment := result.([]*TaskComment)
assert.NoError(t, err)
resultComment := result.([]*TaskComment)
assert.Equal(t, int64(15), resultComment[0].ID)
})
}