// Code generated by atomctl. DO NOT EDIT. // Package http provides HTTP route definitions and registration // for the quyun/v2 application. package http import ( "go.ipao.vip/gen/field" "quyun/v2/app/http/dto" "quyun/v2/app/middlewares" "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 http module. // // @provider contracts.HttpRoute atom.GroupRoutes type Routes struct { log *log.Entry `inject:"false"` middlewares *middlewares.Middlewares // Controller instances auth *auth posts *posts users *users } // Prepare initializes the routes provider with logging configuration. func (r *Routes) Prepare() error { r.log = log.WithField("module", "routes.http") r.log.Info("Initializing routes module") return nil } // Name returns the unique identifier for this routes provider. func (r *Routes) Name() string { return "http" } // 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 /v1/auth/phone -> auth.Phone") router.Post("/v1/auth/phone"[len(r.Path()):], Func1( r.auth.Phone, Body[PhoneValidationForm]("form"), )) r.log.Debugf("Registering route: Post /v1/auth/validate -> auth.Validate") router.Post("/v1/auth/validate"[len(r.Path()):], DataFunc1( r.auth.Validate, Body[PhoneValidationForm]("body"), )) // Register routes for controller: posts r.log.Debugf("Registering route: Get /v1/posts -> posts.List") router.Get("/v1/posts"[len(r.Path()):], DataFunc2( r.posts.List, Query[dto.PostListQuery]("query"), Local[*models.User]("user"), )) r.log.Debugf("Registering route: Get /v1/posts/:id/play -> posts.Play") router.Get("/v1/posts/:id/play"[len(r.Path()):], DataFunc2( r.posts.Play, 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 /v1/posts/:id/show -> posts.Show") router.Get("/v1/posts/:id/show"[len(r.Path()):], DataFunc2( 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() }, Local[*models.User]("user"), )) r.log.Debugf("Registering route: Get /v1/posts/mine -> posts.Mine") router.Get("/v1/posts/mine"[len(r.Path()):], DataFunc2( r.posts.Mine, Query[dto.PostListQuery]("query"), Local[*models.User]("user"), )) r.log.Debugf("Registering route: Post /v1/posts/:id/buy -> posts.Buy") router.Post("/v1/posts/:id/buy"[len(r.Path()):], DataFunc2( r.posts.Buy, 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 r.log.Debugf("Registering route: Get /v1/users/profile -> users.Profile") router.Get("/v1/users/profile"[len(r.Path()):], DataFunc1( r.users.Profile, Local[*models.User]("user"), )) r.log.Debugf("Registering route: Put /v1/users/username -> users.Update") router.Put("/v1/users/username"[len(r.Path()):], Func2( r.users.Update, Local[*models.User]("user"), Body[ProfileForm]("form"), )) r.log.Info("Successfully registered all routes") }