fix: query
This commit is contained in:
@@ -1,22 +1,17 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/fields"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/samber/lo"
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/types"
|
||||
)
|
||||
|
||||
type ListQuery struct {
|
||||
Keyword *string `query:"keyword"`
|
||||
}
|
||||
|
||||
// @provider
|
||||
type posts struct{}
|
||||
|
||||
@@ -25,18 +20,12 @@ type posts struct{}
|
||||
// @Summary 作品列表
|
||||
// @Tags Admin 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 /admin/v1/posts [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
|
||||
conds := []gen.Condition{}
|
||||
if query.Keyword != nil && *query.Keyword != "" {
|
||||
conds = append(conds, models.PostQuery.Title.Like(database.WrapLike(*query.Keyword)))
|
||||
}
|
||||
pager, err := services.Posts.List(ctx, pagination, conds...)
|
||||
func (ctl *posts) List(ctx fiber.Ctx, query *dto.PostListQuery) (*requests.Pager, error) {
|
||||
pager, err := services.Posts.List(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user