@@ -5,12 +5,11 @@ import (
55
66 "entgo.io/ent/dialect/sql"
77
8- "github.com/GoYoko/web"
9-
108 "github.com/chaitin/MonkeyCode/backend/consts"
119 "github.com/chaitin/MonkeyCode/backend/db"
1210 "github.com/chaitin/MonkeyCode/backend/db/task"
1311 "github.com/chaitin/MonkeyCode/backend/db/taskrecord"
12+ "github.com/chaitin/MonkeyCode/backend/db/user"
1413 "github.com/chaitin/MonkeyCode/backend/domain"
1514 "github.com/chaitin/MonkeyCode/backend/pkg/cvt"
1615)
@@ -54,15 +53,17 @@ func (b *BillingRepo) CompletionInfo(ctx context.Context, id string) (*domain.Co
5453}
5554
5655// ListChatRecord implements domain.BillingRepo.
57- func (b * BillingRepo ) ListChatRecord (ctx context.Context , page * web. Pagination ) (* domain.ListChatRecordResp , error ) {
56+ func (b * BillingRepo ) ListChatRecord (ctx context.Context , req domain. ListRecordReq ) (* domain.ListChatRecordResp , error ) {
5857 q := b .db .Task .Query ().
5958 WithUser ().
6059 WithModel ().
6160 WithTaskRecords ().
6261 Where (task .ModelType (consts .ModelTypeLLM )).
6362 Order (task .ByCreatedAt (sql .OrderDesc ()))
6463
65- records , p , err := q .Page (ctx , page .Page , page .Size )
64+ filterTask (q , req )
65+
66+ records , p , err := q .Page (ctx , req .Page , req .Size )
6667 if err != nil {
6768 return nil , err
6869 }
@@ -75,14 +76,37 @@ func (b *BillingRepo) ListChatRecord(ctx context.Context, page *web.Pagination)
7576 }, nil
7677}
7778
79+ func filterTask (q * db.TaskQuery , req domain.ListRecordReq ) {
80+ if req .IsAccept != nil {
81+ q .Where (task .IsAccept (* req .IsAccept ))
82+ }
83+
84+ if req .Author != "" {
85+ q .Where (task .HasUserWith (func (s * sql.Selector ) {
86+ s .Where (sql .Like (s .C (user .FieldUsername ), "%" + req .Author + "%" ))
87+ }))
88+ }
89+
90+ if req .Language != "" {
91+ q .Where (func (s * sql.Selector ) {
92+ s .Where (
93+ sql .Like (s .C (task .FieldProgramLanguage ), "%" + req .Language + "%" ),
94+ )
95+ })
96+ }
97+ }
98+
7899// ListCompletionRecord implements domain.BillingRepo.
79- func (b * BillingRepo ) ListCompletionRecord (ctx context.Context , page * web. Pagination ) (* domain.ListCompletionRecordResp , error ) {
100+ func (b * BillingRepo ) ListCompletionRecord (ctx context.Context , req domain. ListRecordReq ) (* domain.ListCompletionRecordResp , error ) {
80101 q := b .db .Task .Query ().
81102 WithUser ().
82103 WithModel ().
83104 Where (task .ModelType (consts .ModelTypeCoder )).
84105 Order (task .ByCreatedAt (sql .OrderDesc ()))
85- records , p , err := q .Page (ctx , page .Page , page .Size )
106+
107+ filterTask (q , req )
108+
109+ records , p , err := q .Page (ctx , req .Page , req .Size )
86110 if err != nil {
87111 return nil , err
88112 }
0 commit comments