Skip to content

Commit 5177532

Browse files
[fix][prompt]list prompt by createAt (#330)
* chore: [Coda] order prompt commits by created_at * bugfix:list_opt --------- Co-authored-by: Coda <coda@bytedance.com>
1 parent ea722f6 commit 5177532

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

backend/modules/prompt/application/manage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ func (app *PromptManageApplicationImpl) RevertDraftFromCommit(ctx context.Contex
788788

789789
func (app *PromptManageApplicationImpl) listPromptOrderBy(dtoEnum *manage.ListPromptOrderBy) int {
790790
if dtoEnum == nil {
791-
return mysql.ListPromptBasicOrderByID
791+
return mysql.ListPromptBasicOrderByCreatedAt
792792
}
793793
switch *dtoEnum {
794794
case manage.ListPromptOrderByCreatedAt:

backend/modules/prompt/application/manage_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ func TestPromptManageApplicationImpl_ListPrompt(t *testing.T) {
11301130
FilterPromptTypes: []entity.PromptType{prompt.PromptTypeNormal},
11311131
PageNum: 1,
11321132
PageSize: 10,
1133-
OrderBy: mysql.ListPromptBasicOrderByID,
1133+
OrderBy: mysql.ListPromptBasicOrderByCreatedAt,
11341134
Asc: false,
11351135
}).Return(&repo.ListPromptResult{
11361136
Total: 1,
@@ -1233,7 +1233,7 @@ func TestPromptManageApplicationImpl_ListPrompt(t *testing.T) {
12331233
FilterPromptTypes: []entity.PromptType{entity.PromptTypeNormal},
12341234
PageNum: 1,
12351235
PageSize: 10,
1236-
OrderBy: mysql.ListPromptBasicOrderByID,
1236+
OrderBy: mysql.ListPromptBasicOrderByCreatedAt,
12371237
Asc: false,
12381238
}).Return(&repo.ListPromptResult{
12391239
Total: 2,
@@ -1366,7 +1366,7 @@ func TestPromptManageApplicationImpl_ListPrompt(t *testing.T) {
13661366
FilterPromptTypes: []entity.PromptType{entity.PromptTypeNormal},
13671367
PageNum: 1,
13681368
PageSize: 10,
1369-
OrderBy: mysql.ListPromptBasicOrderByID,
1369+
OrderBy: mysql.ListPromptBasicOrderByCreatedAt,
13701370
Asc: false,
13711371
}).Return(&repo.ListPromptResult{
13721372
Total: 1,
@@ -1510,7 +1510,7 @@ func TestPromptManageApplicationImpl_ListPrompt(t *testing.T) {
15101510
FilterPromptTypes: []entity.PromptType{entity.PromptTypeNormal},
15111511
PageNum: 1,
15121512
PageSize: 10,
1513-
OrderBy: mysql.ListPromptBasicOrderByID,
1513+
OrderBy: mysql.ListPromptBasicOrderByCreatedAt,
15141514
Asc: false,
15151515
}).Return(nil, errorx.New("list prompt error"))
15161516

@@ -1543,7 +1543,7 @@ func TestPromptManageApplicationImpl_ListPrompt(t *testing.T) {
15431543
FilterPromptTypes: []entity.PromptType{entity.PromptTypeSnippet},
15441544
PageNum: 1,
15451545
PageSize: 10,
1546-
OrderBy: mysql.ListPromptBasicOrderByID,
1546+
OrderBy: mysql.ListPromptBasicOrderByCreatedAt,
15471547
Asc: false,
15481548
}).Return(&repo.ListPromptResult{
15491549
Total: 1,
@@ -2869,7 +2869,7 @@ func TestPromptManageApplicationImpl_listPromptOrderBy(t *testing.T) {
28692869
arg *manage.ListPromptOrderBy
28702870
exp int
28712871
}{
2872-
{"nil", nil, mysql.ListPromptBasicOrderByID},
2872+
{"nil", nil, mysql.ListPromptBasicOrderByCreatedAt},
28732873
{"created", ptr.Of(manage.ListPromptOrderByCreatedAt), mysql.ListPromptBasicOrderByCreatedAt},
28742874
{"committed", ptr.Of(manage.ListPromptOrderByCommitedAt), mysql.ListPromptBasicOrderByLatestCommittedAt},
28752875
{"default", ptr.Of(manage.ListPromptOrderBy("unknown")), mysql.ListPromptBasicOrderByID},

backend/modules/prompt/infra/repo/manage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ func (d *ManageRepoImpl) ListCommitInfo(ctx context.Context, param repo.ListComm
979979
result.CommitDOs = commitDOs
980980
return result, nil
981981
}
982-
result.NextPageToken = commitPOs[param.PageSize].ID
982+
result.NextPageToken = commitPOs[param.PageSize].CreatedAt.Unix()
983983
result.CommitInfoDOs = commitInfoDOs[:len(commitPOs)-1]
984984
result.CommitDOs = commitDOs[:len(commitPOs)-1]
985985
return result, nil

backend/modules/prompt/infra/repo/manage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ func TestManageRepoImpl_ListCommitInfo(t *testing.T) {
13951395
CommittedAt: time.Unix(2000, 0),
13961396
},
13971397
},
1398-
NextPageToken: 3,
1398+
NextPageToken: 3000,
13991399
CommitDOs: []*entity.PromptCommit{
14001400
{
14011401
CommitInfo: &entity.CommitInfo{

backend/modules/prompt/infra/repo/mysql/prompt_commit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ func (d *PromptCommitDAOImpl) List(ctx context.Context, param ListCommitParam, o
134134
tx = tx.Where(q.PromptCommit.PromptID.Eq(param.PromptID))
135135
if param.Cursor == nil {
136136
if param.Asc {
137-
tx = tx.Order(q.PromptCommit.ID.Asc())
137+
tx = tx.Order(q.PromptCommit.CreatedAt.Asc())
138138
} else {
139-
tx = tx.Order(q.PromptCommit.ID.Desc())
139+
tx = tx.Order(q.PromptCommit.CreatedAt.Desc())
140140
}
141141
} else {
142142
if param.Asc {
143-
tx = tx.Where(q.PromptCommit.ID.Gte(*param.Cursor)).Order(q.PromptCommit.ID.Asc())
143+
tx = tx.Where(q.PromptCommit.CreatedAt.Gte(time.Unix(*param.Cursor, 0))).Order(q.PromptCommit.CreatedAt.Asc())
144144
} else {
145-
tx = tx.Where(q.PromptCommit.ID.Lte(*param.Cursor)).Order(q.PromptCommit.ID.Desc())
145+
tx = tx.Where(q.PromptCommit.CreatedAt.Lte(time.Unix(*param.Cursor, 0))).Order(q.PromptCommit.CreatedAt.Desc())
146146
}
147147
}
148148
tx = tx.Limit(param.Limit)

0 commit comments

Comments
 (0)