This commit is contained in:
@@ -37,13 +37,8 @@ func (ctl *medias) List(ctx fiber.Ctx, pagination *requests.Pagination, query *L
|
|||||||
// @Param id path int64 true "媒体 ID"
|
// @Param id path int64 true "媒体 ID"
|
||||||
// @Success 302 {string} string "跳转"
|
// @Success 302 {string} string "跳转"
|
||||||
// @Router /admin/medias/:id [get]
|
// @Router /admin/medias/:id [get]
|
||||||
// @Bind id path
|
// @Bind media path key(id) model(id)
|
||||||
func (ctl *medias) Show(ctx fiber.Ctx, id int64) error {
|
func (ctl *medias) Show(ctx fiber.Ctx, media *models.Media) error {
|
||||||
media, err := services.Medias.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return ctx.SendString("Media not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
url, err := ctl.oss.GetSignedUrl(ctx, media.Path)
|
url, err := ctl.oss.GetSignedUrl(ctx, media.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -60,13 +55,8 @@ func (ctl *medias) Show(ctx fiber.Ctx, id int64) error {
|
|||||||
// @Param id path int64 true "媒体 ID"
|
// @Param id path int64 true "媒体 ID"
|
||||||
// @Success 204 {object} any "成功"
|
// @Success 204 {object} any "成功"
|
||||||
// @Router /admin/medias/:id [delete]
|
// @Router /admin/medias/:id [delete]
|
||||||
// @Bind id path
|
// @Bind media path key(id) model(id)
|
||||||
func (ctl *medias) Delete(ctx fiber.Ctx, id int64) error {
|
func (ctl *medias) Delete(ctx fiber.Ctx, media *models.Media) error {
|
||||||
media, err := services.Medias.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return ctx.SendString("Media not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := ctl.oss.Delete(ctx, media.Path); err != nil {
|
if err := ctl.oss.Delete(ctx, media.Path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type orders struct {
|
|||||||
wepay *wepay.Client
|
wepay *wepay.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// List users
|
// List
|
||||||
//
|
//
|
||||||
// @Summary 订单列表
|
// @Summary 订单列表
|
||||||
// @Tags Admin Orders
|
// @Tags Admin Orders
|
||||||
@@ -60,13 +60,8 @@ func (ctl *orders) List(
|
|||||||
// @Param id path int64 true "订单 ID"
|
// @Param id path int64 true "订单 ID"
|
||||||
// @Success 200 {object} any "成功"
|
// @Success 200 {object} any "成功"
|
||||||
// @Router /admin/orders/:id/refund [post]
|
// @Router /admin/orders/:id/refund [post]
|
||||||
// @Bind id path
|
// @Bind order path key(id) model(id)
|
||||||
func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
func (ctl *orders) Refund(ctx fiber.Ctx, order *models.Order) error {
|
||||||
order, err := services.Orders.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := services.Users.FindByID(ctx, order.UserID)
|
user, err := services.Users.FindByID(ctx, order.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -127,13 +127,9 @@ func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
|
|||||||
// @Param form body PostForm true "请求体"
|
// @Param form body PostForm true "请求体"
|
||||||
// @Success 200 {object} any "成功"
|
// @Success 200 {object} any "成功"
|
||||||
// @Router /admin/posts/:id [put]
|
// @Router /admin/posts/:id [put]
|
||||||
// @Bind id path
|
// @Bind post path key(id) model(id)
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (ctl *posts) Update(ctx fiber.Ctx, id int64, form *PostForm) error {
|
func (ctl *posts) Update(ctx fiber.Ctx, post *models.Post, form *PostForm) error {
|
||||||
post, err := services.Posts.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
post.Title = form.Title
|
post.Title = form.Title
|
||||||
post.HeadImages = types.NewJSONType(form.HeadImages)
|
post.HeadImages = types.NewJSONType(form.HeadImages)
|
||||||
post.Price = form.Price
|
post.Price = form.Price
|
||||||
@@ -172,16 +168,8 @@ func (ctl *posts) Update(ctx fiber.Ctx, id int64, form *PostForm) error {
|
|||||||
// @Param id path int64 true "作品 ID"
|
// @Param id path int64 true "作品 ID"
|
||||||
// @Success 204 {object} any "成功"
|
// @Success 204 {object} any "成功"
|
||||||
// @Router /admin/posts/:id [delete]
|
// @Router /admin/posts/:id [delete]
|
||||||
// @Bind id path
|
// @Bind post path key(id) model(id)
|
||||||
func (ctl *posts) Delete(ctx fiber.Ctx, id int64) error {
|
func (ctl *posts) Delete(ctx fiber.Ctx, post *models.Post) error {
|
||||||
post, err := services.Posts.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if post == nil {
|
|
||||||
return fiber.ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := post.ForceDelete(ctx); err != nil {
|
if _, err := post.ForceDelete(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -202,13 +190,8 @@ type PostItem struct {
|
|||||||
// @Param id path int64 true "作品 ID"
|
// @Param id path int64 true "作品 ID"
|
||||||
// @Success 200 {object} PostItem "成功"
|
// @Success 200 {object} PostItem "成功"
|
||||||
// @Router /admin/posts/:id [get]
|
// @Router /admin/posts/:id [get]
|
||||||
// @Bind id path
|
// @Bind post path key(id) model(id)
|
||||||
func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
|
func (ctl *posts) Show(ctx fiber.Ctx, post *models.Post) (*PostItem, error) {
|
||||||
post, err := services.Posts.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
medias, err := services.Medias.GetByIds(ctx, lo.Map(post.Assets.Data(), func(asset fields.MediaAsset, _ int) int64 {
|
medias, err := services.Medias.GetByIds(ctx, lo.Map(post.Assets.Data(), func(asset fields.MediaAsset, _ int) int64 {
|
||||||
return asset.Media
|
return asset.Media
|
||||||
}))
|
}))
|
||||||
@@ -230,19 +213,9 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) {
|
|||||||
// @Param userId path int64 true "用户 ID"
|
// @Param userId path int64 true "用户 ID"
|
||||||
// @Success 200 {object} any "成功"
|
// @Success 200 {object} any "成功"
|
||||||
// @Router /admin/posts/:id/send-to/:userId [post]
|
// @Router /admin/posts/:id/send-to/:userId [post]
|
||||||
// @Bind id path
|
// @Bind post path key(id) model(id)
|
||||||
// @Bind userId path
|
// @Bind user path key(userId) model(id)
|
||||||
func (ctl *posts) SendTo(ctx fiber.Ctx, id, userId int64) error {
|
func (ctl *posts) SendTo(ctx fiber.Ctx, post *models.Post, user *models.User) error {
|
||||||
post, err := services.Posts.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := services.Users.FindByID(ctx, userId)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := services.Posts.SendTo(ctx, post.ID, user.ID); err != nil {
|
if err := services.Posts.SendTo(ctx, post.ID, user.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@
|
|||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.ipao.vip/gen/field"
|
||||||
"quyun/v2/app/middlewares"
|
"quyun/v2/app/middlewares"
|
||||||
"quyun/v2/app/requests"
|
"quyun/v2/app/requests"
|
||||||
|
"quyun/v2/database/models"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -57,7 +59,10 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Delete /admin/medias/:id -> medias.Delete")
|
r.log.Debugf("Registering route: Delete /admin/medias/:id -> medias.Delete")
|
||||||
router.Delete("/admin/medias/:id"[len(r.Path()):], Func1(
|
router.Delete("/admin/medias/:id"[len(r.Path()):], Func1(
|
||||||
r.medias.Delete,
|
r.medias.Delete,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Media, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.MediaQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /admin/medias -> medias.List")
|
r.log.Debugf("Registering route: Get /admin/medias -> medias.List")
|
||||||
router.Get("/admin/medias"[len(r.Path()):], DataFunc2(
|
router.Get("/admin/medias"[len(r.Path()):], DataFunc2(
|
||||||
@@ -68,7 +73,10 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Get /admin/medias/:id -> medias.Show")
|
r.log.Debugf("Registering route: Get /admin/medias/:id -> medias.Show")
|
||||||
router.Get("/admin/medias/:id"[len(r.Path()):], Func1(
|
router.Get("/admin/medias/:id"[len(r.Path()):], Func1(
|
||||||
r.medias.Show,
|
r.medias.Show,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Media, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.MediaQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
// Register routes for controller: orders
|
// Register routes for controller: orders
|
||||||
r.log.Debugf("Registering route: Get /admin/orders -> orders.List")
|
r.log.Debugf("Registering route: Get /admin/orders -> orders.List")
|
||||||
@@ -80,13 +88,19 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Post /admin/orders/:id/refund -> orders.Refund")
|
r.log.Debugf("Registering route: Post /admin/orders/:id/refund -> orders.Refund")
|
||||||
router.Post("/admin/orders/:id/refund"[len(r.Path()):], Func1(
|
router.Post("/admin/orders/:id/refund"[len(r.Path()):], Func1(
|
||||||
r.orders.Refund,
|
r.orders.Refund,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Order, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.OrderQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
// Register routes for controller: posts
|
// Register routes for controller: posts
|
||||||
r.log.Debugf("Registering route: Delete /admin/posts/:id -> posts.Delete")
|
r.log.Debugf("Registering route: Delete /admin/posts/:id -> posts.Delete")
|
||||||
router.Delete("/admin/posts/:id"[len(r.Path()):], Func1(
|
router.Delete("/admin/posts/:id"[len(r.Path()):], Func1(
|
||||||
r.posts.Delete,
|
r.posts.Delete,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Post, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /admin/posts -> posts.List")
|
r.log.Debugf("Registering route: Get /admin/posts -> posts.List")
|
||||||
router.Get("/admin/posts"[len(r.Path()):], DataFunc2(
|
router.Get("/admin/posts"[len(r.Path()):], DataFunc2(
|
||||||
@@ -97,7 +111,10 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Get /admin/posts/:id -> posts.Show")
|
r.log.Debugf("Registering route: Get /admin/posts/:id -> posts.Show")
|
||||||
router.Get("/admin/posts/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/admin/posts/:id"[len(r.Path()):], DataFunc1(
|
||||||
r.posts.Show,
|
r.posts.Show,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Post, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /admin/posts -> posts.Create")
|
r.log.Debugf("Registering route: Post /admin/posts -> posts.Create")
|
||||||
router.Post("/admin/posts"[len(r.Path()):], Func1(
|
router.Post("/admin/posts"[len(r.Path()):], Func1(
|
||||||
@@ -107,13 +124,22 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Post /admin/posts/:id/send-to/:userId -> posts.SendTo")
|
r.log.Debugf("Registering route: Post /admin/posts/:id/send-to/:userId -> posts.SendTo")
|
||||||
router.Post("/admin/posts/:id/send-to/:userId"[len(r.Path()):], Func2(
|
router.Post("/admin/posts/:id/send-to/:userId"[len(r.Path()):], Func2(
|
||||||
r.posts.SendTo,
|
r.posts.SendTo,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Post, error) {
|
||||||
PathParam[int64]("userId"),
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
|
func(ctx fiber.Ctx) (*models.User, error) {
|
||||||
|
v := fiber.Params[int](ctx, "userId")
|
||||||
|
return models.UserQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Put /admin/posts/:id -> posts.Update")
|
r.log.Debugf("Registering route: Put /admin/posts/:id -> posts.Update")
|
||||||
router.Put("/admin/posts/:id"[len(r.Path()):], Func2(
|
router.Put("/admin/posts/:id"[len(r.Path()):], Func2(
|
||||||
r.posts.Update,
|
r.posts.Update,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Post, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
Body[PostForm]("form"),
|
Body[PostForm]("form"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: statistics
|
// Register routes for controller: statistics
|
||||||
@@ -144,18 +170,27 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Get /admin/users/:id -> users.Show")
|
r.log.Debugf("Registering route: Get /admin/users/:id -> users.Show")
|
||||||
router.Get("/admin/users/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/admin/users/:id"[len(r.Path()):], DataFunc1(
|
||||||
r.users.Show,
|
r.users.Show,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.User, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.UserQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /admin/users/:id/articles -> users.Articles")
|
r.log.Debugf("Registering route: Get /admin/users/:id/articles -> users.Articles")
|
||||||
router.Get("/admin/users/:id/articles"[len(r.Path()):], DataFunc2(
|
router.Get("/admin/users/:id/articles"[len(r.Path()):], DataFunc2(
|
||||||
r.users.Articles,
|
r.users.Articles,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.User, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.UserQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
Query[requests.Pagination]("pagination"),
|
Query[requests.Pagination]("pagination"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /admin/users/:id/balance -> users.Balance")
|
r.log.Debugf("Registering route: Post /admin/users/:id/balance -> users.Balance")
|
||||||
router.Post("/admin/users/:id/balance"[len(r.Path()):], Func2(
|
router.Post("/admin/users/:id/balance"[len(r.Path()):], Func2(
|
||||||
r.users.Balance,
|
r.users.Balance,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.User, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.UserQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
Body[UserBalance]("balance"),
|
Body[UserBalance]("balance"),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ func (ctl *users) List(ctx fiber.Ctx, pagination *requests.Pagination, query *Us
|
|||||||
// @Param id path int64 true "用户 ID"
|
// @Param id path int64 true "用户 ID"
|
||||||
// @Success 200 {object} models.User "成功"
|
// @Success 200 {object} models.User "成功"
|
||||||
// @Router /admin/users/:id [get]
|
// @Router /admin/users/:id [get]
|
||||||
// @Bind id path
|
// @Bind user path key(id) model(id)
|
||||||
func (ctl *users) Show(ctx fiber.Ctx, id int64) (*models.User, error) {
|
func (ctl *users) Show(ctx fiber.Ctx, user *models.User) (*models.User, error) {
|
||||||
return services.Users.FindByID(ctx, id)
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Articles show user bought articles
|
// Articles show user bought articles
|
||||||
@@ -57,10 +57,10 @@ func (ctl *users) Show(ctx fiber.Ctx, id int64) (*models.User, error) {
|
|||||||
// @Param pagination query requests.Pagination false "分页参数"
|
// @Param pagination query requests.Pagination false "分页参数"
|
||||||
// @Success 200 {object} requests.Pager{items=models.Post} "成功"
|
// @Success 200 {object} requests.Pager{items=models.Post} "成功"
|
||||||
// @Router /admin/users/:id/articles [get]
|
// @Router /admin/users/:id/articles [get]
|
||||||
// @Bind id path
|
// @Bind user path key(id) model(id)
|
||||||
// @Bind pagination query
|
// @Bind pagination query
|
||||||
func (ctl *users) Articles(ctx fiber.Ctx, id int64, pagination *requests.Pagination) (*requests.Pager, error) {
|
func (ctl *users) Articles(ctx fiber.Ctx, user *models.User, pagination *requests.Pagination) (*requests.Pager, error) {
|
||||||
return services.Posts.Bought(ctx, id, pagination)
|
return services.Posts.Bought(ctx, user.ID, pagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserBalance struct {
|
type UserBalance struct {
|
||||||
@@ -77,12 +77,8 @@ type UserBalance struct {
|
|||||||
// @Param balance body UserBalance true "请求体"
|
// @Param balance body UserBalance true "请求体"
|
||||||
// @Success 200 {object} any "成功"
|
// @Success 200 {object} any "成功"
|
||||||
// @Router /admin/users/:id/balance [post]
|
// @Router /admin/users/:id/balance [post]
|
||||||
// @Bind id path
|
// @Bind user path key(id) model(id)
|
||||||
// @Bind balance body
|
// @Bind balance body
|
||||||
func (ctl *users) Balance(ctx fiber.Ctx, id int64, balance *UserBalance) error {
|
func (ctl *users) Balance(ctx fiber.Ctx, user *models.User, balance *UserBalance) error {
|
||||||
user, err := services.Users.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return services.Users.AddBalance(ctx, user.ID, balance.Balance)
|
return services.Users.AddBalance(ctx, user.ID, balance.Balance)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,19 +135,13 @@ type PostItem struct {
|
|||||||
// @Param id path int64 true "作品 ID"
|
// @Param id path int64 true "作品 ID"
|
||||||
// @Success 200 {object} PostItem "成功"
|
// @Success 200 {object} PostItem "成功"
|
||||||
// @Router /posts/:id/show [get]
|
// @Router /posts/:id/show [get]
|
||||||
// @Bind id path
|
// @Bind post path key(id) model(id)
|
||||||
// @Bind user local
|
// @Bind user local
|
||||||
func (ctl *posts) Show(ctx fiber.Ctx, id int64, user *models.User) (*PostItem, error) {
|
func (ctl *posts) Show(ctx fiber.Ctx, post *models.Post, user *models.User) (*PostItem, error) {
|
||||||
log.Infof("Fetching post with ID: %d", id)
|
log.Infof("Fetching post with ID: %d", post.ID)
|
||||||
|
|
||||||
post, err := services.Posts.FindByID(
|
if post.Status != fields.PostStatusPublished {
|
||||||
ctx,
|
return nil, fiber.ErrNotFound
|
||||||
id,
|
|
||||||
models.PostQuery.Status.Eq(fields.PostStatusPublished),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Errorf("GetByID err: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bought, err := services.Users.HasBought(ctx, user.ID, post.ID)
|
bought, err := services.Users.HasBought(ctx, user.ID, post.ID)
|
||||||
@@ -196,26 +190,21 @@ type PlayUrl struct {
|
|||||||
// @Param id path int64 true "作品 ID"
|
// @Param id path int64 true "作品 ID"
|
||||||
// @Success 200 {object} PlayUrl "成功"
|
// @Success 200 {object} PlayUrl "成功"
|
||||||
// @Router /posts/:id/play [get]
|
// @Router /posts/:id/play [get]
|
||||||
// @Bind id path
|
// @Bind post path key(id) model(id)
|
||||||
// @Bind user local
|
// @Bind user local
|
||||||
func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *models.User) (*PlayUrl, error) {
|
func (ctl *posts) Play(ctx fiber.Ctx, post *models.Post, user *models.User) (*PlayUrl, error) {
|
||||||
log := log.WithField("PlayPostID", strconv.FormatInt(id, 10))
|
log := log.WithField("PlayPostID", strconv.FormatInt(post.ID, 10))
|
||||||
// return &PlayUrl{
|
// return &PlayUrl{
|
||||||
// Url: "https://github.com/mediaelement/mediaelement-files/raw/refs/heads/master/big_buck_bunny.mp4",
|
// Url: "https://github.com/mediaelement/mediaelement-files/raw/refs/heads/master/big_buck_bunny.mp4",
|
||||||
// }, nil
|
// }, nil
|
||||||
|
|
||||||
preview := false
|
preview := false
|
||||||
bought, err := services.Users.HasBought(ctx, user.ID, id)
|
bought, err := services.Users.HasBought(ctx, user.ID, post.ID)
|
||||||
if !bought || err != nil {
|
if !bought || err != nil {
|
||||||
preview = true
|
preview = true
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Fetching play URL for post ID: %d", id)
|
log.Infof("Fetching play URL for post ID: %d", post.ID)
|
||||||
post, err := services.Posts.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Errorf("GetByID err: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
go services.Posts.IncrViewCount(ctx, post.ID)
|
go services.Posts.IncrViewCount(ctx, post.ID)
|
||||||
|
|
||||||
for _, asset := range post.Assets.Data() {
|
for _, asset := range post.Assets.Data() {
|
||||||
@@ -320,10 +309,10 @@ func (ctl *posts) Mine(
|
|||||||
// @Param id path int64 true "作品 ID"
|
// @Param id path int64 true "作品 ID"
|
||||||
// @Success 200 {object} wechat.JSAPIPayParams "成功(余额支付返回 AppId=balance)"
|
// @Success 200 {object} wechat.JSAPIPayParams "成功(余额支付返回 AppId=balance)"
|
||||||
// @Router /posts/:id/buy [post]
|
// @Router /posts/:id/buy [post]
|
||||||
// @Bind id path
|
// @Bind post path key(id) model(id)
|
||||||
// @Bind user local
|
// @Bind user local
|
||||||
func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *models.User) (*wechat.JSAPIPayParams, error) {
|
func (ctl *posts) Buy(ctx fiber.Ctx, post *models.Post, user *models.User) (*wechat.JSAPIPayParams, error) {
|
||||||
bought, err := services.Users.HasBought(ctx, user.ID, id)
|
bought, err := services.Users.HasBought(ctx, user.ID, post.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("查询购买失败")
|
return nil, errors.New("查询购买失败")
|
||||||
}
|
}
|
||||||
@@ -331,11 +320,6 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *models.User) (*wechat.JSAPI
|
|||||||
if bought {
|
if bought {
|
||||||
return nil, errors.New("已经购买过了")
|
return nil, errors.New("已经购买过了")
|
||||||
}
|
}
|
||||||
|
|
||||||
post, err := services.Posts.FindByID(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, " failed to get post: %d", id)
|
|
||||||
}
|
|
||||||
// payPrice := post.PayPrice()
|
// payPrice := post.PayPrice()
|
||||||
|
|
||||||
order, err := services.Orders.CreateFromUserPostID(ctx, user.ID, post.ID)
|
order, err := services.Orders.CreateFromUserPostID(ctx, user.ID, post.ID)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.ipao.vip/gen/field"
|
||||||
"quyun/v2/app/middlewares"
|
"quyun/v2/app/middlewares"
|
||||||
"quyun/v2/app/requests"
|
"quyun/v2/app/requests"
|
||||||
"quyun/v2/database/models"
|
"quyun/v2/database/models"
|
||||||
@@ -54,13 +55,19 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Get /posts/:id/play -> posts.Play")
|
r.log.Debugf("Registering route: Get /posts/:id/play -> posts.Play")
|
||||||
router.Get("/posts/:id/play"[len(r.Path()):], DataFunc2(
|
router.Get("/posts/:id/play"[len(r.Path()):], DataFunc2(
|
||||||
r.posts.Play,
|
r.posts.Play,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Post, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
Local[*models.User]("user"),
|
Local[*models.User]("user"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /posts/:id/show -> posts.Show")
|
r.log.Debugf("Registering route: Get /posts/:id/show -> posts.Show")
|
||||||
router.Get("/posts/:id/show"[len(r.Path()):], DataFunc2(
|
router.Get("/posts/:id/show"[len(r.Path()):], DataFunc2(
|
||||||
r.posts.Show,
|
r.posts.Show,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Post, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
Local[*models.User]("user"),
|
Local[*models.User]("user"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /posts/mine -> posts.Mine")
|
r.log.Debugf("Registering route: Get /posts/mine -> posts.Mine")
|
||||||
@@ -73,7 +80,10 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.log.Debugf("Registering route: Post /posts/:id/buy -> posts.Buy")
|
r.log.Debugf("Registering route: Post /posts/:id/buy -> posts.Buy")
|
||||||
router.Post("/posts/:id/buy"[len(r.Path()):], DataFunc2(
|
router.Post("/posts/:id/buy"[len(r.Path()):], DataFunc2(
|
||||||
r.posts.Buy,
|
r.posts.Buy,
|
||||||
PathParam[int64]("id"),
|
func(ctx fiber.Ctx) (*models.Post, error) {
|
||||||
|
v := fiber.Params[int](ctx, "id")
|
||||||
|
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
|
||||||
|
},
|
||||||
Local[*models.User]("user"),
|
Local[*models.User]("user"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: users
|
// Register routes for controller: users
|
||||||
|
|||||||
Reference in New Issue
Block a user