fix: query
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
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/providers/ali"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -21,19 +20,12 @@ type medias struct {
|
||||
// @Summary 媒体列表
|
||||
// @Tags Admin Medias
|
||||
// @Produce json
|
||||
// @Param pagination query requests.Pagination false "分页参数"
|
||||
// @Param query query ListQuery false "筛选条件"
|
||||
// @Success 200 {object} requests.Pager{items=models.Medium} "成功"
|
||||
// @Router /admin/v1/medias [get]
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *medias) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
|
||||
conds := []gen.Condition{}
|
||||
if query.Keyword != nil {
|
||||
conds = append(conds, models.MediumQuery.Name.Like(database.WrapLike(*query.Keyword)))
|
||||
}
|
||||
|
||||
return services.Media.List(ctx, pagination, conds...)
|
||||
func (ctl *medias) List(ctx fiber.Ctx, query *dto.ListQuery) (*requests.Pager, error) {
|
||||
return services.Media.List(ctx, query)
|
||||
}
|
||||
|
||||
// Show media
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/admin/dto"
|
||||
"quyun/v2/app/http/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ package admin
|
||||
|
||||
import (
|
||||
"go.ipao.vip/gen/field"
|
||||
"quyun/v2/app/http/admin/dto"
|
||||
"quyun/v2/app/http/dto"
|
||||
"quyun/v2/app/middlewares"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
@@ -66,10 +66,9 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
},
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /admin/v1/medias -> medias.List")
|
||||
router.Get("/admin/v1/medias"[len(r.Path()):], DataFunc2(
|
||||
router.Get("/admin/v1/medias"[len(r.Path()):], DataFunc1(
|
||||
r.medias.List,
|
||||
Query[requests.Pagination]("pagination"),
|
||||
Query[ListQuery]("query"),
|
||||
Query[dto.ListQuery]("query"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /admin/v1/medias/:id -> medias.Show")
|
||||
router.Get("/admin/v1/medias/:id"[len(r.Path()):], Func1(
|
||||
@@ -103,10 +102,9 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
},
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /admin/v1/posts -> posts.List")
|
||||
router.Get("/admin/v1/posts"[len(r.Path()):], DataFunc2(
|
||||
router.Get("/admin/v1/posts"[len(r.Path()):], DataFunc1(
|
||||
r.posts.List,
|
||||
Query[requests.Pagination]("pagination"),
|
||||
Query[ListQuery]("query"),
|
||||
Query[dto.PostListQuery]("query"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /admin/v1/posts/:id -> posts.Show")
|
||||
router.Get("/admin/v1/posts/:id"[len(r.Path()):], DataFunc1(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/admin/dto"
|
||||
"quyun/v2/app/http/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
8
backend_v1/app/http/dto/common.go
Normal file
8
backend_v1/app/http/dto/common.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package dto
|
||||
|
||||
import "quyun/v2/app/requests"
|
||||
|
||||
type ListQuery struct {
|
||||
*requests.Pagination
|
||||
Keyword *string `query:"keyword"`
|
||||
}
|
||||
8
backend_v1/app/http/dto/post.go
Normal file
8
backend_v1/app/http/dto/post.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package dto
|
||||
|
||||
import "quyun/v2/app/requests"
|
||||
|
||||
type PostListQuery struct {
|
||||
*requests.Pagination
|
||||
Keyword *string `query:"keyword"`
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -6,6 +6,7 @@ package http
|
||||
|
||||
import (
|
||||
"go.ipao.vip/gen/field"
|
||||
"quyun/v2/app/http/dto"
|
||||
"quyun/v2/app/middlewares"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
@@ -58,10 +59,9 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
))
|
||||
// Register routes for controller: posts
|
||||
r.log.Debugf("Registering route: Get /v1/posts -> posts.List")
|
||||
router.Get("/v1/posts"[len(r.Path()):], DataFunc3(
|
||||
router.Get("/v1/posts"[len(r.Path()):], DataFunc2(
|
||||
r.posts.List,
|
||||
Query[requests.Pagination]("pagination"),
|
||||
Query[ListQuery]("query"),
|
||||
Query[dto.PostListQuery]("query"),
|
||||
Local[*models.User]("user"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /v1/posts/:id/play -> posts.Play")
|
||||
|
||||
Reference in New Issue
Block a user