mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-01 22:33:30 +08:00
feat: 记录列表筛选
This commit is contained in:
@@ -399,6 +399,24 @@
|
||||
"summary": "获取对话记录",
|
||||
"operationId": "list-chat-record",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "作者",
|
||||
"name": "author",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"description": "是否接受筛选",
|
||||
"name": "is_accept",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "语言",
|
||||
"name": "language",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "下一页标识",
|
||||
@@ -500,6 +518,24 @@
|
||||
"summary": "获取补全记录",
|
||||
"operationId": "list-completion-record",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "作者",
|
||||
"name": "author",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"description": "是否接受筛选",
|
||||
"name": "is_accept",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "语言",
|
||||
"name": "language",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "下一页标识",
|
||||
|
||||
@@ -10,19 +10,26 @@ import (
|
||||
)
|
||||
|
||||
type BillingUsecase interface {
|
||||
ListChatRecord(ctx context.Context, page *web.Pagination) (*ListChatRecordResp, error)
|
||||
ListCompletionRecord(ctx context.Context, page *web.Pagination) (*ListCompletionRecordResp, error)
|
||||
ListChatRecord(ctx context.Context, req ListRecordReq) (*ListChatRecordResp, error)
|
||||
ListCompletionRecord(ctx context.Context, req ListRecordReq) (*ListCompletionRecordResp, error)
|
||||
CompletionInfo(ctx context.Context, id string) (*CompletionInfo, error)
|
||||
ChatInfo(ctx context.Context, id string) (*ChatInfo, error)
|
||||
}
|
||||
|
||||
type BillingRepo interface {
|
||||
ListChatRecord(ctx context.Context, page *web.Pagination) (*ListChatRecordResp, error)
|
||||
ListCompletionRecord(ctx context.Context, page *web.Pagination) (*ListCompletionRecordResp, error)
|
||||
ListChatRecord(ctx context.Context, req ListRecordReq) (*ListChatRecordResp, error)
|
||||
ListCompletionRecord(ctx context.Context, req ListRecordReq) (*ListCompletionRecordResp, error)
|
||||
CompletionInfo(ctx context.Context, id string) (*CompletionInfo, error)
|
||||
ChatInfo(ctx context.Context, id string) (*ChatInfo, error)
|
||||
}
|
||||
|
||||
type ListRecordReq struct {
|
||||
*web.Pagination
|
||||
Author string `json:"author" query:"author"` // 作者
|
||||
Language string `json:"language" query:"language"` // 语言
|
||||
IsAccept *bool `json:"is_accept" query:"is_accept"` // 是否接受筛选
|
||||
}
|
||||
|
||||
type ListChatRecordResp struct {
|
||||
*db.PageInfo
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ func NewBillingHandler(
|
||||
g := w.Group("/api/v1/billing")
|
||||
g.Use(auth.Auth())
|
||||
|
||||
g.GET("/chat/record", web.BaseHandler(b.ListChatRecord, web.WithPage()))
|
||||
g.GET("/completion/record", web.BaseHandler(b.ListCompletionRecord, web.WithPage()))
|
||||
g.GET("/chat/record", web.BindHandler(b.ListChatRecord, web.WithPage()))
|
||||
g.GET("/completion/record", web.BindHandler(b.ListCompletionRecord, web.WithPage()))
|
||||
g.GET("/completion/info", web.BaseHandler(b.CompletionInfo))
|
||||
g.GET("/chat/info", web.BaseHandler(b.ChatInfo))
|
||||
|
||||
@@ -39,11 +39,12 @@ func NewBillingHandler(
|
||||
// @ID list-chat-record
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query web.Pagination true "分页"
|
||||
// @Param page query domain.ListRecordReq true "参数"
|
||||
// @Success 200 {object} web.Resp{data=domain.ListChatRecordResp}
|
||||
// @Router /api/v1/billing/chat/record [get]
|
||||
func (h *BillingHandler) ListChatRecord(c *web.Context) error {
|
||||
records, err := h.usecase.ListChatRecord(c.Request().Context(), c.Page())
|
||||
func (h *BillingHandler) ListChatRecord(c *web.Context, req domain.ListRecordReq) error {
|
||||
req.Pagination = c.Page()
|
||||
records, err := h.usecase.ListChatRecord(c.Request().Context(), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -58,11 +59,12 @@ func (h *BillingHandler) ListChatRecord(c *web.Context) error {
|
||||
// @ID list-completion-record
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query web.Pagination true "分页"
|
||||
// @Param page query domain.ListRecordReq true "参数"
|
||||
// @Success 200 {object} web.Resp{data=domain.ListCompletionRecordResp}
|
||||
// @Router /api/v1/billing/completion/record [get]
|
||||
func (h *BillingHandler) ListCompletionRecord(c *web.Context) error {
|
||||
records, err := h.usecase.ListCompletionRecord(c.Request().Context(), c.Page())
|
||||
func (h *BillingHandler) ListCompletionRecord(c *web.Context, req domain.ListRecordReq) error {
|
||||
req.Pagination = c.Page()
|
||||
records, err := h.usecase.ListCompletionRecord(c.Request().Context(), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@ import (
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
||||
"github.com/GoYoko/web"
|
||||
|
||||
"github.com/chaitin/MonkeyCode/backend/consts"
|
||||
"github.com/chaitin/MonkeyCode/backend/db"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/task"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/taskrecord"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/user"
|
||||
"github.com/chaitin/MonkeyCode/backend/domain"
|
||||
"github.com/chaitin/MonkeyCode/backend/pkg/cvt"
|
||||
)
|
||||
@@ -54,7 +53,7 @@ func (b *BillingRepo) CompletionInfo(ctx context.Context, id string) (*domain.Co
|
||||
}
|
||||
|
||||
// ListChatRecord implements domain.BillingRepo.
|
||||
func (b *BillingRepo) ListChatRecord(ctx context.Context, page *web.Pagination) (*domain.ListChatRecordResp, error) {
|
||||
func (b *BillingRepo) ListChatRecord(ctx context.Context, req domain.ListRecordReq) (*domain.ListChatRecordResp, error) {
|
||||
q := b.db.Task.Query().
|
||||
WithUser().
|
||||
WithModel().
|
||||
@@ -62,7 +61,9 @@ func (b *BillingRepo) ListChatRecord(ctx context.Context, page *web.Pagination)
|
||||
Where(task.ModelType(consts.ModelTypeLLM)).
|
||||
Order(task.ByCreatedAt(sql.OrderDesc()))
|
||||
|
||||
records, p, err := q.Page(ctx, page.Page, page.Size)
|
||||
filterTask(q, req)
|
||||
|
||||
records, p, err := q.Page(ctx, req.Page, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -75,14 +76,37 @@ func (b *BillingRepo) ListChatRecord(ctx context.Context, page *web.Pagination)
|
||||
}, nil
|
||||
}
|
||||
|
||||
func filterTask(q *db.TaskQuery, req domain.ListRecordReq) {
|
||||
if req.IsAccept != nil {
|
||||
q.Where(task.IsAccept(*req.IsAccept))
|
||||
}
|
||||
|
||||
if req.Author != "" {
|
||||
q.Where(task.HasUserWith(func(s *sql.Selector) {
|
||||
s.Where(sql.Like(s.C(user.FieldUsername), "%"+req.Author+"%"))
|
||||
}))
|
||||
}
|
||||
|
||||
if req.Language != "" {
|
||||
q.Where(func(s *sql.Selector) {
|
||||
s.Where(
|
||||
sql.Like(s.C(task.FieldProgramLanguage), "%"+req.Language+"%"),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ListCompletionRecord implements domain.BillingRepo.
|
||||
func (b *BillingRepo) ListCompletionRecord(ctx context.Context, page *web.Pagination) (*domain.ListCompletionRecordResp, error) {
|
||||
func (b *BillingRepo) ListCompletionRecord(ctx context.Context, req domain.ListRecordReq) (*domain.ListCompletionRecordResp, error) {
|
||||
q := b.db.Task.Query().
|
||||
WithUser().
|
||||
WithModel().
|
||||
Where(task.ModelType(consts.ModelTypeCoder)).
|
||||
Order(task.ByCreatedAt(sql.OrderDesc()))
|
||||
records, p, err := q.Page(ctx, page.Page, page.Size)
|
||||
|
||||
filterTask(q, req)
|
||||
|
||||
records, p, err := q.Page(ctx, req.Page, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package usecase
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/GoYoko/web"
|
||||
|
||||
"github.com/chaitin/MonkeyCode/backend/domain"
|
||||
)
|
||||
|
||||
@@ -17,13 +15,13 @@ func NewBillingUsecase(repo domain.BillingRepo) domain.BillingUsecase {
|
||||
}
|
||||
|
||||
// ListChatRecord implements domain.BillingUsecase.
|
||||
func (b *BillingUsecase) ListChatRecord(ctx context.Context, page *web.Pagination) (*domain.ListChatRecordResp, error) {
|
||||
return b.repo.ListChatRecord(ctx, page)
|
||||
func (b *BillingUsecase) ListChatRecord(ctx context.Context, req domain.ListRecordReq) (*domain.ListChatRecordResp, error) {
|
||||
return b.repo.ListChatRecord(ctx, req)
|
||||
}
|
||||
|
||||
// ListCompletionRecord implements domain.BillingUsecase.
|
||||
func (b *BillingUsecase) ListCompletionRecord(ctx context.Context, page *web.Pagination) (*domain.ListCompletionRecordResp, error) {
|
||||
return b.repo.ListCompletionRecord(ctx, page)
|
||||
func (b *BillingUsecase) ListCompletionRecord(ctx context.Context, req domain.ListRecordReq) (*domain.ListCompletionRecordResp, error) {
|
||||
return b.repo.ListCompletionRecord(ctx, req)
|
||||
}
|
||||
|
||||
// CompletionInfo implements domain.BillingUsecase.
|
||||
|
||||
@@ -109,5 +109,8 @@ func (m *ModelUsecase) Update(ctx context.Context, req *domain.UpdateModelReq) (
|
||||
|
||||
func (m *ModelUsecase) InitModel(ctx context.Context) error {
|
||||
m.logger.With("init_model", m.cfg.InitModel).Debug("init model")
|
||||
if m.cfg.InitModel.ModelName == "" {
|
||||
return nil
|
||||
}
|
||||
return m.repo.InitModel(ctx, m.cfg.InitModel.ModelName, m.cfg.InitModel.ModelKey, m.cfg.InitModel.ModelURL)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user