83 lines
3.0 KiB
Go
83 lines
3.0 KiB
Go
package routes
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
|
apphandler "github.com/break/junhong_cmp_fiber/internal/handler/app"
|
|
"github.com/break/junhong_cmp_fiber/internal/middleware"
|
|
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
|
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
|
)
|
|
|
|
// RegisterPersonalCustomerRoutes 注册个人客户路由
|
|
// 路由挂载在 /api/c/v1 下
|
|
func RegisterPersonalCustomerRoutes(router fiber.Router, doc *openapi.Generator, basePath string, handlers *bootstrap.Handlers, personalAuthMiddleware *middleware.PersonalAuthMiddleware) {
|
|
// 公开路由(不需要认证)
|
|
publicGroup := router.Group("")
|
|
|
|
// 发送验证码
|
|
Register(publicGroup, doc, basePath, "POST", "/login/send-code", handlers.PersonalCustomer.SendCode, RouteSpec{
|
|
Summary: "发送验证码",
|
|
Description: "向指定手机号发送登录验证码",
|
|
Tags: []string{"个人客户 - 认证"},
|
|
Auth: false,
|
|
Input: &apphandler.SendCodeRequest{},
|
|
Output: nil,
|
|
})
|
|
|
|
// 登录
|
|
Register(publicGroup, doc, basePath, "POST", "/login", handlers.PersonalCustomer.Login, RouteSpec{
|
|
Summary: "手机号登录",
|
|
Description: "使用手机号和验证码登录",
|
|
Tags: []string{"个人客户 - 认证"},
|
|
Auth: false,
|
|
Input: &apphandler.LoginRequest{},
|
|
Output: &apphandler.LoginResponse{},
|
|
})
|
|
|
|
// 微信 OAuth 登录(公开)
|
|
Register(publicGroup, doc, basePath, "POST", "/wechat/auth", handlers.PersonalCustomer.WechatOAuthLogin, RouteSpec{
|
|
Summary: "微信授权登录",
|
|
Description: "使用微信授权码登录,自动创建或关联用户",
|
|
Tags: []string{"个人客户 - 认证"},
|
|
Auth: false,
|
|
Input: &dto.WechatOAuthRequest{},
|
|
Output: &dto.WechatOAuthResponse{},
|
|
})
|
|
|
|
// 需要认证的路由
|
|
authGroup := router.Group("")
|
|
authGroup.Use(personalAuthMiddleware.Authenticate())
|
|
|
|
// 绑定微信
|
|
Register(authGroup, doc, basePath, "POST", "/bind-wechat", handlers.PersonalCustomer.BindWechat, RouteSpec{
|
|
Summary: "绑定微信",
|
|
Description: "绑定微信账号到当前个人客户",
|
|
Tags: []string{"个人客户 - 账户"},
|
|
Auth: true,
|
|
Input: &dto.WechatOAuthRequest{},
|
|
Output: nil,
|
|
})
|
|
|
|
// 获取个人资料
|
|
Register(authGroup, doc, basePath, "GET", "/profile", handlers.PersonalCustomer.GetProfile, RouteSpec{
|
|
Summary: "获取个人资料",
|
|
Description: "获取当前登录客户的个人资料",
|
|
Tags: []string{"个人客户 - 账户"},
|
|
Auth: true,
|
|
Input: nil,
|
|
Output: &apphandler.PersonalCustomerDTO{},
|
|
})
|
|
|
|
// 更新个人资料
|
|
Register(authGroup, doc, basePath, "PUT", "/profile", handlers.PersonalCustomer.UpdateProfile, RouteSpec{
|
|
Summary: "更新个人资料",
|
|
Description: "更新当前登录客户的昵称和头像",
|
|
Tags: []string{"个人客户 - 账户"},
|
|
Auth: true,
|
|
Input: &apphandler.UpdateProfileRequest{},
|
|
Output: nil,
|
|
})
|
|
}
|