add article
This commit is contained in:
@@ -2,6 +2,7 @@ package container
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.uber.org/fx"
|
||||
@@ -9,11 +10,14 @@ import (
|
||||
"go.uber.org/zap/zapcore"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"tyapi-server/internal/application/article"
|
||||
"tyapi-server/internal/application/certification"
|
||||
"tyapi-server/internal/application/finance"
|
||||
"tyapi-server/internal/application/product"
|
||||
"tyapi-server/internal/application/user"
|
||||
"tyapi-server/internal/config"
|
||||
domain_article_repo "tyapi-server/internal/domains/article/repositories"
|
||||
article_service "tyapi-server/internal/domains/article/services"
|
||||
domain_certification_repo "tyapi-server/internal/domains/certification/repositories"
|
||||
certification_service "tyapi-server/internal/domains/certification/services"
|
||||
domain_finance_repo "tyapi-server/internal/domains/finance/repositories"
|
||||
@@ -23,6 +27,7 @@ import (
|
||||
user_service "tyapi-server/internal/domains/user/services"
|
||||
"tyapi-server/internal/infrastructure/cache"
|
||||
"tyapi-server/internal/infrastructure/database"
|
||||
article_repo "tyapi-server/internal/infrastructure/database/repositories/article"
|
||||
certification_repo "tyapi-server/internal/infrastructure/database/repositories/certification"
|
||||
finance_repo "tyapi-server/internal/infrastructure/database/repositories/finance"
|
||||
product_repo "tyapi-server/internal/infrastructure/database/repositories/product"
|
||||
@@ -38,6 +43,7 @@ import (
|
||||
"tyapi-server/internal/infrastructure/external/zhicha"
|
||||
"tyapi-server/internal/infrastructure/http/handlers"
|
||||
"tyapi-server/internal/infrastructure/http/routes"
|
||||
"tyapi-server/internal/infrastructure/task"
|
||||
shared_database "tyapi-server/internal/shared/database"
|
||||
"tyapi-server/internal/shared/esign"
|
||||
"tyapi-server/internal/shared/events"
|
||||
@@ -511,6 +517,25 @@ func NewContainer() *Container {
|
||||
),
|
||||
),
|
||||
|
||||
// 仓储层 - 文章域
|
||||
fx.Provide(
|
||||
// 文章仓储 - 同时注册具体类型和接口类型
|
||||
fx.Annotate(
|
||||
article_repo.NewGormArticleRepository,
|
||||
fx.As(new(domain_article_repo.ArticleRepository)),
|
||||
),
|
||||
// 分类仓储 - 同时注册具体类型和接口类型
|
||||
fx.Annotate(
|
||||
article_repo.NewGormCategoryRepository,
|
||||
fx.As(new(domain_article_repo.CategoryRepository)),
|
||||
),
|
||||
// 标签仓储 - 同时注册具体类型和接口类型
|
||||
fx.Annotate(
|
||||
article_repo.NewGormTagRepository,
|
||||
fx.As(new(domain_article_repo.TagRepository)),
|
||||
),
|
||||
),
|
||||
|
||||
// API域仓储层
|
||||
fx.Provide(
|
||||
fx.Annotate(
|
||||
@@ -576,6 +601,8 @@ func NewContainer() *Container {
|
||||
infra_events.NewInvoiceEventHandler,
|
||||
certification_service.NewCertificationAggregateService,
|
||||
certification_service.NewEnterpriseInfoSubmitRecordService,
|
||||
// 文章领域服务
|
||||
article_service.NewArticleService,
|
||||
),
|
||||
|
||||
// API域服务层
|
||||
@@ -591,6 +618,15 @@ func NewContainer() *Container {
|
||||
api_app.NewApiApplicationService,
|
||||
),
|
||||
|
||||
// 任务系统
|
||||
fx.Provide(
|
||||
// Asynq 客户端
|
||||
func(cfg *config.Config, logger *zap.Logger) *task.AsynqClient {
|
||||
redisAddr := fmt.Sprintf("%s:%d", cfg.Redis.Host, cfg.Redis.Port)
|
||||
return task.NewAsynqClient(redisAddr, logger)
|
||||
},
|
||||
),
|
||||
|
||||
// 应用服务
|
||||
fx.Provide(
|
||||
// 用户应用服务 - 绑定到接口
|
||||
@@ -642,6 +678,11 @@ func NewContainer() *Container {
|
||||
product.NewSubscriptionApplicationService,
|
||||
fx.As(new(product.SubscriptionApplicationService)),
|
||||
),
|
||||
// 文章应用服务 - 绑定到接口
|
||||
fx.Annotate(
|
||||
article.NewArticleApplicationService,
|
||||
fx.As(new(article.ArticleApplicationService)),
|
||||
),
|
||||
),
|
||||
|
||||
// HTTP处理器
|
||||
@@ -658,6 +699,15 @@ func NewContainer() *Container {
|
||||
handlers.NewProductAdminHandler,
|
||||
// API Handler
|
||||
handlers.NewApiHandler,
|
||||
// 文章HTTP处理器
|
||||
func(
|
||||
appService article.ArticleApplicationService,
|
||||
responseBuilder interfaces.ResponseBuilder,
|
||||
validator interfaces.RequestValidator,
|
||||
logger *zap.Logger,
|
||||
) *handlers.ArticleHandler {
|
||||
return handlers.NewArticleHandler(appService, responseBuilder, validator, logger)
|
||||
},
|
||||
),
|
||||
|
||||
// 路由注册
|
||||
@@ -673,6 +723,8 @@ func NewContainer() *Container {
|
||||
// 产品管理员路由
|
||||
routes.NewProductAdminRoutes,
|
||||
// API路由
|
||||
// 文章路由
|
||||
routes.NewArticleRoutes,
|
||||
routes.NewApiRoutes,
|
||||
),
|
||||
|
||||
@@ -766,6 +818,7 @@ func RegisterRoutes(
|
||||
financeRoutes *routes.FinanceRoutes,
|
||||
productRoutes *routes.ProductRoutes,
|
||||
productAdminRoutes *routes.ProductAdminRoutes,
|
||||
articleRoutes *routes.ArticleRoutes,
|
||||
apiRoutes *routes.ApiRoutes,
|
||||
cfg *config.Config,
|
||||
logger *zap.Logger,
|
||||
@@ -781,6 +834,7 @@ func RegisterRoutes(
|
||||
financeRoutes.Register(router)
|
||||
productRoutes.Register(router)
|
||||
productAdminRoutes.Register(router)
|
||||
articleRoutes.Register(router)
|
||||
|
||||
// 打印注册的路由信息
|
||||
router.PrintRoutes()
|
||||
|
||||
Reference in New Issue
Block a user