feat: 实现用户注册功能,包括数据库表结构、gRPC 服务和业务逻辑
This commit is contained in:
39
backend/services/user-svc/internal/service/service.go
Normal file
39
backend/services/user-svc/internal/service/service.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"backend/services/user-svc/internal/domain"
|
||||
"backend/services/user-svc/internal/repository"
|
||||
"backend/shared/pkg/errors"
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
repo *repository.UserRepository
|
||||
}
|
||||
|
||||
func NewUserService(repo *repository.UserRepository) *UserService {
|
||||
return &UserService{repo: repo}
|
||||
}
|
||||
|
||||
// Register 用户注册
|
||||
func (s *UserService) Register(req *domain.RegisterRequest) (*domain.RegisterResponse, error) {
|
||||
// 验证请求参数
|
||||
if req.Account == "" {
|
||||
return nil, errors.ErrInvalidInput
|
||||
}
|
||||
|
||||
if len(req.Password) < 6 {
|
||||
return nil, errors.ErrInvalidInput
|
||||
}
|
||||
|
||||
// 调用仓库层注册用户
|
||||
return s.repo.Register(req)
|
||||
}
|
||||
|
||||
// GetUserByAccount 根据账号获取用户信息
|
||||
func (s *UserService) GetUserByAccount(account string) (*domain.User, *domain.UserLoginAccount, *domain.UserLoginPassword, error) {
|
||||
if account == "" {
|
||||
return nil, nil, nil, errors.ErrInvalidInput
|
||||
}
|
||||
|
||||
return s.repo.GetUserByAccount(account)
|
||||
}
|
||||
Reference in New Issue
Block a user