Files
quyun/backend_v1/app/http/admin/routes.gen.go
Rogee df6a8de61d
Some checks failed
build quyun / Build (push) Failing after 10s
feat: 更新路由绑定,使用模型作为参数以简化控制器逻辑
2025-12-19 23:53:15 +08:00

199 lines
7.3 KiB
Go

// Code generated by atomctl. DO NOT EDIT.
// Package admin provides HTTP route definitions and registration
// for the quyun/v2 application.
package admin
import (
"go.ipao.vip/gen/field"
"quyun/v2/app/middlewares"
"quyun/v2/app/requests"
"quyun/v2/database/models"
"github.com/gofiber/fiber/v3"
log "github.com/sirupsen/logrus"
_ "go.ipao.vip/atom"
_ "go.ipao.vip/atom/contracts"
. "go.ipao.vip/atom/fen"
)
// Routes implements the HttpRoute contract and provides route registration
// for all controllers in the admin module.
//
// @provider contracts.HttpRoute atom.GroupRoutes
type Routes struct {
log *log.Entry `inject:"false"`
middlewares *middlewares.Middlewares
// Controller instances
auth *auth
medias *medias
orders *orders
posts *posts
statistics *statistics
uploads *uploads
users *users
}
// Prepare initializes the routes provider with logging configuration.
func (r *Routes) Prepare() error {
r.log = log.WithField("module", "routes.admin")
r.log.Info("Initializing routes module")
return nil
}
// Name returns the unique identifier for this routes provider.
func (r *Routes) Name() string {
return "admin"
}
// Register registers all HTTP routes with the provided fiber router.
// Each route is registered with its corresponding controller action and parameter bindings.
func (r *Routes) Register(router fiber.Router) {
// Register routes for controller: auth
r.log.Debugf("Registering route: Post /admin/auth -> auth.Login")
router.Post("/admin/auth"[len(r.Path()):], DataFunc1(
r.auth.Login,
Body[AuthBody]("body"),
))
// Register routes for controller: medias
r.log.Debugf("Registering route: Delete /admin/medias/:id -> medias.Delete")
router.Delete("/admin/medias/:id"[len(r.Path()):], Func1(
r.medias.Delete,
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")
router.Get("/admin/medias"[len(r.Path()):], DataFunc2(
r.medias.List,
Query[requests.Pagination]("pagination"),
Query[ListQuery]("query"),
))
r.log.Debugf("Registering route: Get /admin/medias/:id -> medias.Show")
router.Get("/admin/medias/:id"[len(r.Path()):], Func1(
r.medias.Show,
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
r.log.Debugf("Registering route: Get /admin/orders -> orders.List")
router.Get("/admin/orders"[len(r.Path()):], DataFunc2(
r.orders.List,
Query[requests.Pagination]("pagination"),
Query[OrderListQuery]("query"),
))
r.log.Debugf("Registering route: Post /admin/orders/:id/refund -> orders.Refund")
router.Post("/admin/orders/:id/refund"[len(r.Path()):], Func1(
r.orders.Refund,
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
r.log.Debugf("Registering route: Delete /admin/posts/:id -> posts.Delete")
router.Delete("/admin/posts/:id"[len(r.Path()):], Func1(
r.posts.Delete,
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")
router.Get("/admin/posts"[len(r.Path()):], DataFunc2(
r.posts.List,
Query[requests.Pagination]("pagination"),
Query[ListQuery]("query"),
))
r.log.Debugf("Registering route: Get /admin/posts/:id -> posts.Show")
router.Get("/admin/posts/:id"[len(r.Path()):], DataFunc1(
r.posts.Show,
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")
router.Post("/admin/posts"[len(r.Path()):], Func1(
r.posts.Create,
Body[PostForm]("form"),
))
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(
r.posts.SendTo,
func(ctx fiber.Ctx) (*models.Post, error) {
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")
router.Put("/admin/posts/:id"[len(r.Path()):], Func2(
r.posts.Update,
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"),
))
// Register routes for controller: statistics
r.log.Debugf("Registering route: Get /admin/statistics -> statistics.statistics")
router.Get("/admin/statistics"[len(r.Path()):], DataFunc0(
r.statistics.statistics,
))
// Register routes for controller: uploads
r.log.Debugf("Registering route: Get /admin/uploads/pre-uploaded-check/:md5.:ext -> uploads.PreUploadCheck")
router.Get("/admin/uploads/pre-uploaded-check/:md5.:ext"[len(r.Path()):], DataFunc3(
r.uploads.PreUploadCheck,
PathParam[string]("md5"),
PathParam[string]("ext"),
QueryParam[string]("mime"),
))
r.log.Debugf("Registering route: Post /admin/uploads/post-uploaded-action -> uploads.PostUploadedAction")
router.Post("/admin/uploads/post-uploaded-action"[len(r.Path()):], Func1(
r.uploads.PostUploadedAction,
Body[PostUploadedForm]("body"),
))
// Register routes for controller: users
r.log.Debugf("Registering route: Get /admin/users -> users.List")
router.Get("/admin/users"[len(r.Path()):], DataFunc2(
r.users.List,
Query[requests.Pagination]("pagination"),
Query[UserListQuery]("query"),
))
r.log.Debugf("Registering route: Get /admin/users/:id -> users.Show")
router.Get("/admin/users/:id"[len(r.Path()):], DataFunc1(
r.users.Show,
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")
router.Get("/admin/users/:id/articles"[len(r.Path()):], DataFunc2(
r.users.Articles,
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"),
))
r.log.Debugf("Registering route: Post /admin/users/:id/balance -> users.Balance")
router.Post("/admin/users/:id/balance"[len(r.Path()):], Func2(
r.users.Balance,
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"),
))
r.log.Info("Successfully registered all routes")
}