85 lines
2.0 KiB
Go
85 lines
2.0 KiB
Go
package user
|
|
|
|
import (
|
|
"busniess-user-center/internal/models"
|
|
"busniess-user-center/internal/service/user"
|
|
|
|
ginUtil "busniess-user-center/pkg/utils/gin"
|
|
"busniess-user-center/server/user/proto"
|
|
"context"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/samber/do"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func init() {
|
|
do.Provide(nil, NewUserServer)
|
|
}
|
|
|
|
type UserServer struct {
|
|
userService user.UserService
|
|
logger *zap.SugaredLogger
|
|
}
|
|
|
|
func NewUserServer(i *do.Injector) (*UserServer, error) {
|
|
return &UserServer{
|
|
userService: do.MustInvoke[user.UserService](i),
|
|
logger: do.MustInvoke[*zap.SugaredLogger](i),
|
|
}, nil
|
|
}
|
|
|
|
func RegisterRoute(api *gin.RouterGroup) {
|
|
server := do.MustInvoke[*UserServer](nil)
|
|
api.POST("/add", ginUtil.Wrap(server.Add))
|
|
api.POST("/login", ginUtil.WrapNoRsp(server.Login))
|
|
api.POST("/logout", ginUtil.WrapNo(server.Logout))
|
|
api.POST("/modify", ginUtil.WrapNoRsp(server.Modify))
|
|
api.GET("/search", ginUtil.WrapNoRsp(server.Modify))
|
|
}
|
|
|
|
func (u *UserServer) Add(ctx context.Context, req *models.AddInfo) (rsp proto.AddResponse, err error) {
|
|
// 转换dto
|
|
id, err := u.userService.Add(ctx, req)
|
|
if err != nil {
|
|
u.logger.Errorf("add user err:", err.Error())
|
|
return
|
|
}
|
|
|
|
rsp.Id = id
|
|
rsp.Account = req.Account
|
|
rsp.Name = req.Name
|
|
|
|
return
|
|
}
|
|
|
|
func (u *UserServer) Login(ctx context.Context, req *proto.LoginRequest) (err error) {
|
|
// 转换dto
|
|
info := models.LoginInfo{
|
|
Account: req.Account,
|
|
Pwd: req.Pwd,
|
|
}
|
|
|
|
return u.userService.Login(ctx, info)
|
|
}
|
|
|
|
func (u *UserServer) Logout(ctx context.Context) error {
|
|
return u.userService.Logout(ctx)
|
|
}
|
|
|
|
func (u *UserServer) Modify(ctx context.Context, req *models.ModifyInfo) error {
|
|
return u.userService.Modify(ctx, req)
|
|
}
|
|
|
|
func (u *UserServer) Disable(ctx context.Context) error {
|
|
return u.userService.Disable(ctx)
|
|
}
|
|
|
|
func (u *UserServer) Enable(ctx context.Context) error {
|
|
return u.userService.Enable(ctx)
|
|
}
|
|
|
|
func (u *UserServer) Search(ctx context.Context, query *models.Query) ([]models.User, error) {
|
|
return u.userService.Search(ctx, query)
|
|
}
|