feat: 实现用户注册功能,包括数据库表结构、gRPC 服务和业务逻辑

This commit is contained in:
fish
2026-03-28 20:11:54 +08:00
parent e4bb25d1ac
commit 4ff974439f
9 changed files with 529 additions and 0 deletions

View 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)
}