Add internal/service/app.go
This commit is contained in:
70
internal/service/app.go
Normal file
70
internal/service/app.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gotest/internal/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AppService 应用服务
|
||||||
|
type AppService struct {
|
||||||
|
repo *repository.AppRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAppService 创建应用服务实例
|
||||||
|
func NewAppService(repo *repository.AppRepository) *AppService {
|
||||||
|
return &AppService{repo: repo}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListCategories 获取应用分类
|
||||||
|
func (s *AppService) ListCategories() (interface{}, error) {
|
||||||
|
return s.repo.ListCategories()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListApps 获取应用列表
|
||||||
|
func (s *AppService) ListApps(categoryID uint, keyword, sort string, page, pageSize int) (map[string]interface{}, error) {
|
||||||
|
apps, total, err := s.repo.ListApps(categoryID, keyword, sort, page, pageSize)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]interface{}{
|
||||||
|
"list": apps,
|
||||||
|
"total": total,
|
||||||
|
"page": page,
|
||||||
|
"page_size": pageSize,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetApp 获取应用详情
|
||||||
|
func (s *AppService) GetApp(id uint) (interface{}, error) {
|
||||||
|
return s.repo.GetApp(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListFeatured 获取精选应用
|
||||||
|
func (s *AppService) ListFeatured(limit int) (interface{}, error) {
|
||||||
|
return s.repo.ListFeaturedApps(limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListNew 获取新上架应用
|
||||||
|
func (s *AppService) ListNew(limit int) (interface{}, error) {
|
||||||
|
return s.repo.ListNewApps(limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHomeData 获取应用首页数据(分类 + 精选 + 新上架)
|
||||||
|
func (s *AppService) GetHomeData() (map[string]interface{}, error) {
|
||||||
|
categories, err := s.repo.ListCategories()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
featured, err := s.repo.ListFeaturedApps(8)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
newApps, err := s.repo.ListNewApps(4)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]interface{}{
|
||||||
|
"categories": categories,
|
||||||
|
"featured": featured,
|
||||||
|
"new": newApps,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user