You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1.2 KiB

package service
import (
"context"
"gofaster/internal/auth/model"
"gofaster/internal/auth/repository"
)
type UserService struct {
repo repository.UserRepository
}
func NewUserService(repo repository.UserRepository) *UserService {
return &UserService{repo: repo}
}
func (s *UserService) CreateUser(ctx context.Context, user *model.User) error {
return s.repo.Create(ctx, user)
}
func (s *UserService) GetUserByID(ctx context.Context, id uint) (*model.User, error) {
return s.repo.GetByID(ctx, id)
}
func (s *UserService) UpdateUser(ctx context.Context, user *model.User) error {
return s.repo.Update(ctx, user)
}
func (s *UserService) DeleteUser(ctx context.Context, id uint) error {
return s.repo.Delete(ctx, id)
}
func (s *UserService) ListUsers(ctx context.Context, page, pageSize int) ([]*model.User, int64, error) {
return s.repo.List(ctx, page, pageSize)
}
// GetByID 根据ID获取用户(无context版本,用于密码服务)
func (s *UserService) GetByID(id uint) (*model.User, error) {
ctx := context.Background()
return s.repo.GetByID(ctx, id)
}
// Update 更新用户(无context版本,用于密码服务)
func (s *UserService) Update(user *model.User) error {
ctx := context.Background()
return s.repo.Update(ctx, user)
}