fix: issues

This commit is contained in:
yanghao05
2025-04-25 21:19:03 +08:00
parent b35abb2090
commit 5bc3ae468d
15 changed files with 129 additions and 64 deletions

View File

@@ -29,11 +29,13 @@ type posts struct {
}
// List posts
// @Router /api/posts [get]
// @Router /posts [get]
// @Bind pagination query
// @Bind query query
// @Bind user local
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
log.Infof("ok", pagination, query.Keyword, user.ID)
cond := models.Posts.BuildConditionWithKey(query.Keyword)
pager, err := models.Posts.List(ctx.Context(), pagination, cond, func(item model.Posts) model.Posts {
item.Assets = fields.ToJson([]fields.MediaAsset{})
@@ -41,6 +43,7 @@ func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
return item
})
if err != nil {
log.WithError(err).Errorf("post list err: %v", err)
return nil, err
}
@@ -55,6 +58,7 @@ func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
mediaUrls := lo.FilterMap(medias, func(item model.Medias, _ int) (string, bool) {
url, err := ctl.oss.GetSignedUrl(ctx.Context(), item.Path)
if err != nil {
log.WithError(err).Errorf("head image GetSignedUrl err: %v", err)
return "", false
}
@@ -93,7 +97,7 @@ type PostItem struct {
}
// Show
// @Router /api/posts/:id [get]
// @Router /posts/:id [get]
// @Bind id path
// @Bind user local
func (ctl *posts) Show(ctx fiber.Ctx, id int64, user *model.Users) (*PostItem, error) {
@@ -141,7 +145,7 @@ type PlayUrl struct {
}
// Play
// @Router /api/posts/:id/play [get]
// @Router /posts/:id/play [get]
// @Bind id path
// @Bind user local
func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, error) {
@@ -174,7 +178,7 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
}
// Mine posts
// @Router /api/posts/mine [get]
// @Router /posts/mine [get]
// @Bind pagination query
// @Bind query query
func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
@@ -187,7 +191,7 @@ func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
}
// Buy
// @Router /api/posts/:id/buy [get]
// @Router /posts/:id/buy [get]
// @Bind id path
// @Bind user local
func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPIPayParams, error) {

View File

@@ -57,13 +57,11 @@ func Provide(opts ...opt.Option) error {
auth *auth,
pays *pays,
posts *posts,
weChat *weChat,
) (contracts.HttpRoute, error) {
obj := &Routes{
auth: auth,
pays: pays,
posts: posts,
weChat: weChat,
auth: auth,
pays: pays,
posts: posts,
}
if err := obj.Prepare(); err != nil {
return nil, err
@@ -73,12 +71,5 @@ func Provide(opts ...opt.Option) error {
}, atom.GroupRoutes); err != nil {
return err
}
if err := container.Container.Provide(func() (*weChat, error) {
obj := &weChat{}
return obj, nil
}); err != nil {
return err
}
return nil
}

View File

@@ -14,11 +14,10 @@ import (
// @provider contracts.HttpRoute atom.GroupRoutes
type Routes struct {
log *log.Entry `inject:"false"`
auth *auth
pays *pays
posts *posts
weChat *weChat
log *log.Entry `inject:"false"`
auth *auth
pays *pays
posts *posts
}
func (r *Routes) Prepare() error {
@@ -51,41 +50,35 @@ func (r *Routes) Register(router fiber.Router) {
))
// 注册路由组: posts
router.Get("/api/posts", DataFunc3(
router.Get("/posts", DataFunc3(
r.posts.List,
Query[requests.Pagination]("pagination"),
Query[ListQuery]("query"),
Local[*model.Users]("user"),
))
router.Get("/api/posts/:id", DataFunc2(
router.Get("/posts/:id", DataFunc2(
r.posts.Show,
PathParam[int64]("id"),
Local[*model.Users]("user"),
))
router.Get("/api/posts/:id/play", DataFunc2(
router.Get("/posts/:id/play", DataFunc2(
r.posts.Play,
PathParam[int64]("id"),
Local[*model.Users]("user"),
))
router.Get("/api/posts/mine", DataFunc2(
router.Get("/posts/mine", DataFunc2(
r.posts.Mine,
Query[requests.Pagination]("pagination"),
Query[ListQuery]("query"),
))
router.Get("/api/posts/:id/buy", DataFunc2(
router.Get("/posts/:id/buy", DataFunc2(
r.posts.Buy,
PathParam[int64]("id"),
Local[*model.Users]("user"),
))
// 注册路由组: weChat
router.Get("/MP_verify_:code.txt", Func1(
r.weChat.Verify,
PathParam[string]("code"),
))
}

View File

@@ -1,13 +0,0 @@
package http
import "github.com/gofiber/fiber/v3"
// @provider
type weChat struct{}
// Verify
// @Router /MP_verify_:code.txt [get]
// @Bind code path
func (*weChat) Verify(ctx fiber.Ctx, code string) error {
return ctx.SendString(code)
}