Files
asset_helper/backend/services/user-svc/internal/service/service.go

41 lines
916 B
Go

package service
import (
"user-svc/internal/domain"
"user-svc/internal/repository"
"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)
}