feat: update post list
Some checks failed
build quyun / Build (push) Failing after 1m39s

This commit is contained in:
2025-12-20 21:49:34 +08:00
parent be8a57c649
commit 619834a673
4 changed files with 31 additions and 45 deletions

View File

@@ -1,8 +1,12 @@
package dto
import "quyun/v2/app/requests"
import (
"quyun/v2/app/requests"
"quyun/v2/pkg/fields"
)
type PostListQuery struct {
*requests.Pagination
Keyword *string `query:"keyword"`
Keyword *string `query:"keyword"`
Status fields.PostStatus `query:"status"`
}

View File

@@ -9,7 +9,6 @@ import (
"quyun/v2/app/jobs"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"quyun/v2/database"
"quyun/v2/database/models"
"quyun/v2/pkg/fields"
"quyun/v2/providers/ali"
@@ -21,7 +20,6 @@ import (
"github.com/pkg/errors"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"go.ipao.vip/gen"
)
type ListQuery struct {
@@ -46,6 +44,8 @@ type posts struct {
// @Bind query query
// @Bind user local
func (ctl *posts) List(ctx fiber.Ctx, query *dto.PostListQuery, user *models.User) (*requests.Pager, error) {
query.Status = fields.PostStatusPublished
pager, err := services.Posts.List(ctx, query)
if err != nil {
log.WithError(err).Errorf("post list err: %v", err)
@@ -232,31 +232,19 @@ func (ctl *posts) Play(ctx fiber.Ctx, post *models.Post, user *models.User) (*Pl
// @Summary 我的已购作品
// @Tags Posts
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
// @Router /v1/posts/mine [get]
// @Bind pagination query
// @Bind query query
// @Bind user local
func (ctl *posts) Mine(
ctx fiber.Ctx,
pagination *requests.Pagination,
query *ListQuery,
query *dto.PostListQuery,
user *models.User,
) (*requests.Pager, error) {
log.Infof("Fetching posts for user with pagination: %+v and keyword: %v", pagination, query.Keyword)
log.Infof("Fetching posts for user with keyword: %v", query.Keyword)
conds := []gen.Condition{
models.PostQuery.Status.Eq(fields.PostStatusPublished),
}
if query.Keyword != nil && *query.Keyword != "" {
conds = append(conds,
models.PostQuery.Title.Like(database.WrapLike(*query.Keyword)),
)
}
pager, err := services.Users.PostList(ctx, user.ID, pagination, conds...)
pager, err := services.Users.PostList(ctx, user.ID, query)
if err != nil {
log.WithError(err).Errorf("post list err: %v", err)
return nil, err

View File

@@ -8,7 +8,6 @@ import (
"go.ipao.vip/gen/field"
"quyun/v2/app/http/dto"
"quyun/v2/app/middlewares"
"quyun/v2/app/requests"
"quyun/v2/database/models"
"github.com/gofiber/fiber/v3"
@@ -83,10 +82,9 @@ func (r *Routes) Register(router fiber.Router) {
Local[*models.User]("user"),
))
r.log.Debugf("Registering route: Get /v1/posts/mine -> posts.Mine")
router.Get("/v1/posts/mine"[len(r.Path()):], DataFunc3(
router.Get("/v1/posts/mine"[len(r.Path()):], DataFunc2(
r.posts.Mine,
Query[requests.Pagination]("pagination"),
Query[ListQuery]("query"),
Query[dto.PostListQuery]("query"),
Local[*models.User]("user"),
))
r.log.Debugf("Registering route: Post /v1/posts/:id/buy -> posts.Buy")