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

65 lines
1.6 KiB
Go

package services
import (
"learnsteam/cslms-api/internal/models"
"learnsteam/cslms-api/internal/repositories"
)
type centerService struct {
repository repositories.CenterRepository
tokenRepository repositories.TokenRepository
}
type CenterService interface {
List(string, int, int) (*[]models.Center, error)
Total(string) (int64, error)
Find(int64) (*models.Center, error)
FindByTitle(string) (*models.Center, error)
Create(*models.Center) (*models.Center, error)
Update(*models.Center) (*models.Center, error)
Delete(int64) error
}
func NewCenterService(repository repositories.CenterRepository, tokenRepository repositories.TokenRepository) CenterService {
return &centerService{
repository: repository,
tokenRepository: tokenRepository,
}
}
func (s *centerService) List(q string, page int, limit int) (*[]models.Center, error) {
return s.repository.List(q, page, limit)
}
func (s *centerService) Total(q string) (int64, error) {
return s.repository.Total(q)
}
func (s *centerService) Find(id int64) (*models.Center, error) {
return s.repository.Find(id)
}
func (s *centerService) FindByTitle(centername string) (*models.Center, error) {
return s.repository.FindByTitle(centername)
}
func (s *centerService) Create(center *models.Center) (*models.Center, error) {
result, err := s.repository.Create(center)
return result, err
}
func (s *centerService) Update(center *models.Center) (*models.Center, error) {
result, err := s.repository.Update(center)
return result, err
}
func (s *centerService) Delete(id int64) error {
err := s.repository.Delete(id)
return err
}