分类:Model/Repo/Service/Controller + 管理后台树形页面 + 首页导航栏
标签:Model/Repo/Service/Controller + /tags/{slug} 落地页 + 写文章页输入
Post 加 CategoryID,Create/Update 支持分类和标签
SQL 迁移含 categories/tags/post_tags 表及预设未分类
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package controller
|
||
|
||
import (
|
||
"metazone.cc/mce/internal/model"
|
||
"metazone.cc/mce/internal/service"
|
||
)
|
||
|
||
// trendsUseCase StudioController 对趋势服务的最小依赖(ISP)
|
||
type trendsUseCase interface {
|
||
GetTrends(userID uint, since string) (*service.TrendResult, error)
|
||
}
|
||
|
||
// tagParser ISP:标签解析
|
||
type tagParser interface {
|
||
ParseAndSave(tagStr string) ([]uint, error)
|
||
SetPostTags(postID uint, tagStr string) error
|
||
}
|
||
|
||
// StudioController 创作中心控制器(SSR 页面 + API)
|
||
type StudioController struct {
|
||
postService studioUseCase
|
||
energySvc energyDeducter
|
||
trendsSvc trendsUseCase
|
||
tagSvc tagParser
|
||
categorySvc categoryLoader
|
||
}
|
||
|
||
// categoryLoader ISP:分类叶子节点查询
|
||
type categoryLoader interface {
|
||
GetLeaves() ([]model.Category, error)
|
||
}
|
||
|
||
// NewStudioController 构造函数
|
||
func NewStudioController(ps studioUseCase) *StudioController {
|
||
return &StudioController{postService: ps}
|
||
}
|
||
|
||
// WithEnergyService 链式注入域能服务
|
||
func (ctrl *StudioController) WithEnergyService(svc energyDeducter) *StudioController {
|
||
ctrl.energySvc = svc
|
||
return ctrl
|
||
}
|
||
|
||
// WithTrendsService 链式注入趋势服务
|
||
func (ctrl *StudioController) WithTrendsService(svc trendsUseCase) *StudioController {
|
||
ctrl.trendsSvc = svc
|
||
return ctrl
|
||
}
|
||
|
||
// WithTagService 链式注入标签服务
|
||
func (ctrl *StudioController) WithTagService(svc tagParser) *StudioController {
|
||
ctrl.tagSvc = svc
|
||
return ctrl
|
||
}
|
||
|
||
// WithCategoryService 链式注入分类服务
|
||
func (ctrl *StudioController) WithCategoryService(svc categoryLoader) *StudioController {
|
||
ctrl.categorySvc = svc
|
||
return ctrl
|
||
}
|