Skip to content

Commit

Permalink
feat(admin, hitokoto): add uuids search
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Oct 5, 2023
1 parent 22b6fc0 commit 11f3a83
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
5 changes: 2 additions & 3 deletions internal/controller/hitokoto/hitokoto_adminV1_move_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func (c *ControllerAdminV1) MoveList(ctx context.Context, req *adminV1.MoveListR

failedChan := make(chan *moveErrCollector, total)
for _, uuid := range req.UUIDs {
uuid := uuid
go func() {
go func(uuid string) {
defer wg.Done()
sentence, err := service.Hitokoto().GetHitokotoV1SchemaByUUID(ctx, uuid)
if err != nil {
Expand All @@ -42,7 +41,7 @@ func (c *ControllerAdminV1) MoveList(ctx context.Context, req *adminV1.MoveListR
}
return
}
}()
}(uuid)
}
go func() {
wg.Wait()
Expand Down
12 changes: 9 additions & 3 deletions internal/controller/hitokoto/hitokoto_admin_v1_get_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package hitokoto

import (
"context"
"fmt"
"strings"

"github.com/hitokoto-osc/reviewer/internal/model"
"github.com/hitokoto-osc/reviewer/internal/service"
"github.com/samber/lo"

"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
Expand All @@ -14,12 +15,17 @@ import (
)

func (c *ControllerAdminV1) GetList(ctx context.Context, req *adminV1.GetListReq) (res *adminV1.GetListRes, err error) {
fmt.Printf("GetList: %+v", req)
// fmt.Printf("GetList: %+v", req)
if len(req.UUIDs) > 0 {
req.UUIDs = lo.Map(req.UUIDs, func(item string, index int) string {
return strings.Trim(item, "\" '") // 去除首尾的引号
})
}
out, err := service.Hitokoto().GetList(ctx, &model.GetHitokotoV1SchemaListInput{
Page: req.Page,
PageSize: req.PageSize,
Order: req.Order,
UUID: req.UUID,
UUIDs: req.UUIDs,
Keywords: req.Keywords,
Creator: req.Creator,
From: req.From,
Expand Down
6 changes: 4 additions & 2 deletions internal/logic/hitokoto/hitokoto.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ func (s *sHitokoto) GetList(ctx context.Context, in *model.GetHitokotoV1SchemaLi
}
}

if in.UUID != nil {
query = query.Where(dao.Sentence.Columns().Uuid, *in.UUID)
if len(in.UUIDs) > 0 {
for _, uuid := range in.UUIDs {
query = query.WhereOr(dao.Sentence.Columns().Uuid, uuid)
}
goto startQuery // 跳过后续的查询条件
}

Expand Down
3 changes: 3 additions & 0 deletions internal/logic/poll/ruling.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ func (s *sPoll) DoRuling(
e = dao.Pending.Ctx(ctx).TX(tx).Where(dao.Pending.Columns().Uuid, poll.SentenceUuid).Scan(&pending)
if e != nil {
return gerror.Wrapf(e, "获取句子 %s 的 pending 信息失败", poll.SentenceUuid)
} else if pending == nil {
return gerror.Newf("获取句子 %s 的 pending 信息失败", poll.SentenceUuid)
}

if target == consts.PollStatusApproved || target == consts.PollStatusRejected {
// 移动句子
_, e = dao.Pending.Ctx(ctx).TX(tx).Where(dao.Pending.Columns().Uuid, poll.SentenceUuid).Delete()
Expand Down
2 changes: 1 addition & 1 deletion internal/model/hitokoto.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type GetHitokotoV1SchemaListInput struct {
PageSize int `json:"page_size" v:"min:0|max:1000" d:"30" dc:"每页数量"`
Order string `json:"order" v:"in:desc,asc" d:"desc" dc:"排序方式"`
// 搜索参数
UUID *string `json:"uuid" dc:"句子 UUID"`
UUIDs []string `json:"uuids" dc:"句子 UUID"`
Keywords *string `json:"keyword" dc:"句子内容"`
Creator *string `json:"creator" dc:"句子创建者(或 ID)"`
From *string `json:"from" dc:"句子来源"`
Expand Down

0 comments on commit 11f3a83

Please sign in to comment.