fix: query

This commit is contained in:
2025-12-20 21:41:41 +08:00
parent 3313c3aa7d
commit be8a57c649
15 changed files with 65 additions and 81 deletions

View File

@@ -5,6 +5,7 @@ import (
"strconv"
"time"
"quyun/v2/app/http/dto"
"quyun/v2/app/jobs"
"quyun/v2/app/requests"
"quyun/v2/app/services"
@@ -39,30 +40,13 @@ type posts struct {
// @Summary 作品列表
// @Tags Posts
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Param query query dto.PostListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
// @Router /v1/posts [get]
// @Bind pagination query
// @Bind query query
// @Bind user local
func (ctl *posts) List(
ctx fiber.Ctx,
pagination *requests.Pagination,
query *ListQuery,
user *models.User,
) (*requests.Pager, error) {
tbl, _ := models.PostQuery.QueryContext(ctx)
conds := []gen.Condition{
tbl.Status.Eq(fields.PostStatusPublished),
}
if query.Keyword != nil && *query.Keyword != "" {
conds = append(conds,
tbl.Title.Like(database.WrapLike(*query.Keyword)),
)
}
pager, err := services.Posts.List(ctx, pagination, conds...)
func (ctl *posts) List(ctx fiber.Ctx, query *dto.PostListQuery, user *models.User) (*requests.Pager, error) {
pager, err := services.Posts.List(ctx, query)
if err != nil {
log.WithError(err).Errorf("post list err: %v", err)
return nil, err