feat: 更新路由绑定,使用模型作为参数以简化控制器逻辑
Some checks failed
build quyun / Build (push) Failing after 10s

This commit is contained in:
2025-12-19 23:53:15 +08:00
parent 7b18a6a0e6
commit df6a8de61d
7 changed files with 96 additions and 113 deletions

View File

@@ -5,6 +5,7 @@
package http
import (
"go.ipao.vip/gen/field"
"quyun/v2/app/middlewares"
"quyun/v2/app/requests"
"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")
router.Get("/posts/:id/play"[len(r.Path()):], DataFunc2(
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"),
))
r.log.Debugf("Registering route: Get /posts/:id/show -> posts.Show")
router.Get("/posts/:id/show"[len(r.Path()):], DataFunc2(
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"),
))
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")
router.Post("/posts/:id/buy"[len(r.Path()):], DataFunc2(
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"),
))
// Register routes for controller: users