cslms-api/internal/services/user.go
2023-12-27 17:31:49 +09:00

49 lines
1.2 KiB
Go

package services
import (
"learnsteam/cslms-api/internal/models"
"learnsteam/cslms-api/internal/repositories"
)
type userService struct {
repository repositories.UserRepository
tokenRepository repositories.TokenRepository
}
type UserService interface {
List(string, int, int) (*[]models.User, error)
Total(string) (int64, error)
Find(int64) (*models.User, error)
FindByUsername(string) (*models.User, error)
Create(*models.User) (*models.User, error)
}
func NewUserService(repository repositories.UserRepository, tokenRepository repositories.TokenRepository) UserService {
return &userService{
repository: repository,
tokenRepository: tokenRepository,
}
}
func (s *userService) List(q string, page int, limit int) (*[]models.User, error) {
return s.repository.List(q, page, limit)
}
func (s *userService) Total(q string) (int64, error) {
return s.repository.Total(q)
}
func (s *userService) Find(id int64) (*models.User, error) {
return s.repository.Find(id)
}
func (s *userService) FindByUsername(username string) (*models.User, error) {
return s.repository.FindByUsername(username)
}
func (s *userService) Create(user *models.User) (*models.User, error) {
result, err := s.repository.Create(user)
return result, err
}