Add internal/service/enterprise.go
This commit is contained in:
66
internal/service/enterprise.go
Normal file
66
internal/service/enterprise.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gotest/internal/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EnterpriseService 企业信息服务
|
||||||
|
type EnterpriseService struct {
|
||||||
|
repo *repository.EnterpriseRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEnterpriseService 创建企业服务实例
|
||||||
|
func NewEnterpriseService(repo *repository.EnterpriseRepository) *EnterpriseService {
|
||||||
|
return &EnterpriseService{repo: repo}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllData 一次性获取企业官网所需的全部数据(公司、服务、新闻、团队)
|
||||||
|
func (s *EnterpriseService) GetAllData() (map[string]interface{}, error) {
|
||||||
|
company, err := s.repo.GetCompany()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
services, err := s.repo.ListServices()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
news, err := s.repo.ListNews("", 6)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
team, err := s.repo.ListTeam()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]interface{}{
|
||||||
|
"company": company,
|
||||||
|
"services": services,
|
||||||
|
"news": news,
|
||||||
|
"team": team,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompany 获取企业信息
|
||||||
|
func (s *EnterpriseService) GetCompany() (interface{}, error) {
|
||||||
|
return s.repo.GetCompany()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListServices 获取服务列表
|
||||||
|
func (s *EnterpriseService) ListServices() (interface{}, error) {
|
||||||
|
return s.repo.ListServices()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListNews 获取新闻列表
|
||||||
|
func (s *EnterpriseService) ListNews(category string, limit int) (interface{}, error) {
|
||||||
|
return s.repo.ListNews(category, limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNews 获取新闻详情
|
||||||
|
func (s *EnterpriseService) GetNews(id uint) (interface{}, error) {
|
||||||
|
return s.repo.GetNews(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListTeam 获取团队列表
|
||||||
|
func (s *EnterpriseService) ListTeam() (interface{}, error) {
|
||||||
|
return s.repo.ListTeam()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user