mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51:34 +00:00
This commit addresses several high-priority tasks from the TASKS.md file, including: - **Fix Background Job Panic:** Replaced `log.Fatalf` with `log.Printf` in the `asynq` server to prevent crashes. - **Refactor API Server Setup:** Consolidated the GraphQL Playground and Prometheus metrics endpoints into the main API server. - **Implement `DeleteUser` Mutation:** Implemented the `DeleteUser` resolver. - **Implement `CreateContribution` Mutation:** Implemented the `CreateContribution` resolver and its required application service. Additionally, this commit includes a major refactoring of the configuration management system to fix a broken build. The global `config.Cfg` variable has been removed and replaced with a dependency injection approach, where the configuration object is passed to all components that require it. This change has been applied across the entire codebase, including the test suite, to ensure a stable and testable application.
110 lines
4.1 KiB
Go
110 lines
4.1 KiB
Go
package app
|
|
|
|
import (
|
|
"tercul/internal/app/analytics"
|
|
"tercul/internal/app/auth"
|
|
"tercul/internal/app/author"
|
|
"tercul/internal/app/authz"
|
|
"tercul/internal/app/book"
|
|
"tercul/internal/app/bookmark"
|
|
"tercul/internal/app/category"
|
|
"tercul/internal/app/collection"
|
|
"tercul/internal/app/comment"
|
|
"tercul/internal/app/contribution"
|
|
"tercul/internal/app/like"
|
|
"tercul/internal/app/localization"
|
|
"tercul/internal/app/tag"
|
|
"tercul/internal/app/translation"
|
|
"tercul/internal/app/user"
|
|
"tercul/internal/app/work"
|
|
"tercul/internal/domain"
|
|
auth_domain "tercul/internal/domain/auth"
|
|
localization_domain "tercul/internal/domain/localization"
|
|
"tercul/internal/domain/search"
|
|
work_domain "tercul/internal/domain/work"
|
|
platform_auth "tercul/internal/platform/auth"
|
|
)
|
|
|
|
// Dependencies holds all external dependencies for the application.
|
|
type Dependencies struct {
|
|
WorkRepo work_domain.WorkRepository
|
|
UserRepo domain.UserRepository
|
|
AuthorRepo domain.AuthorRepository
|
|
TranslationRepo domain.TranslationRepository
|
|
CommentRepo domain.CommentRepository
|
|
LikeRepo domain.LikeRepository
|
|
BookmarkRepo domain.BookmarkRepository
|
|
CollectionRepo domain.CollectionRepository
|
|
TagRepo domain.TagRepository
|
|
CategoryRepo domain.CategoryRepository
|
|
BookRepo domain.BookRepository
|
|
PublisherRepo domain.PublisherRepository
|
|
SourceRepo domain.SourceRepository
|
|
CopyrightRepo domain.CopyrightRepository
|
|
MonetizationRepo domain.MonetizationRepository
|
|
ContributionRepo domain.ContributionRepository
|
|
AnalyticsRepo analytics.Repository
|
|
AuthRepo auth_domain.AuthRepository
|
|
LocalizationRepo localization_domain.LocalizationRepository
|
|
SearchClient search.SearchClient
|
|
AnalyticsService analytics.Service
|
|
JWTManager platform_auth.JWTManagement
|
|
}
|
|
|
|
// Application is a container for all the application-layer services.
|
|
type Application struct {
|
|
Author *author.Service
|
|
Book *book.Service
|
|
Bookmark *bookmark.Service
|
|
Category *category.Service
|
|
Collection *collection.Service
|
|
Comment *comment.Service
|
|
Contribution *contribution.Service
|
|
Like *like.Service
|
|
Tag *tag.Service
|
|
Translation *translation.Service
|
|
User *user.Service
|
|
Localization *localization.Service
|
|
Auth *auth.Service
|
|
Authz *authz.Service
|
|
Work *work.Service
|
|
Analytics analytics.Service
|
|
}
|
|
|
|
func NewApplication(deps Dependencies) *Application {
|
|
authzService := authz.NewService(deps.WorkRepo, deps.TranslationRepo)
|
|
authorService := author.NewService(deps.AuthorRepo)
|
|
bookService := book.NewService(deps.BookRepo, authzService)
|
|
bookmarkService := bookmark.NewService(deps.BookmarkRepo, deps.AnalyticsService)
|
|
categoryService := category.NewService(deps.CategoryRepo)
|
|
collectionService := collection.NewService(deps.CollectionRepo)
|
|
commentService := comment.NewService(deps.CommentRepo, authzService, deps.AnalyticsService)
|
|
contributionCommands := contribution.NewCommands(deps.ContributionRepo, authzService)
|
|
contributionService := contribution.NewService(contributionCommands)
|
|
likeService := like.NewService(deps.LikeRepo, deps.AnalyticsService)
|
|
tagService := tag.NewService(deps.TagRepo)
|
|
translationService := translation.NewService(deps.TranslationRepo, authzService)
|
|
userService := user.NewService(deps.UserRepo, authzService)
|
|
localizationService := localization.NewService(deps.LocalizationRepo)
|
|
authService := auth.NewService(deps.UserRepo, deps.JWTManager)
|
|
workService := work.NewService(deps.WorkRepo, deps.SearchClient, authzService)
|
|
|
|
return &Application{
|
|
Author: authorService,
|
|
Book: bookService,
|
|
Bookmark: bookmarkService,
|
|
Category: categoryService,
|
|
Collection: collectionService,
|
|
Comment: commentService,
|
|
Contribution: contributionService,
|
|
Like: likeService,
|
|
Tag: tagService,
|
|
Translation: translationService,
|
|
User: userService,
|
|
Localization: localizationService,
|
|
Auth: authService,
|
|
Authz: authzService,
|
|
Work: workService,
|
|
Analytics: deps.AnalyticsService,
|
|
}
|
|
} |