mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This commit introduces a new application layer to the codebase, which decouples the GraphQL resolvers from the data layer. The resolvers now call application services, which in turn call the repositories. This change improves the separation of concerns and makes the code more testable and maintainable. Additionally, this commit introduces dataloaders to solve the N+1 problem in the GraphQL resolvers. The dataloaders are used to batch and cache database queries, which significantly improves the performance of the API. The following changes were made: - Created application services for most of the domains. - Refactored the GraphQL resolvers to use the new application services. - Implemented dataloaders for the `Author` aggregate. - Updated the `app.Application` struct to hold the application services instead of the repositories. - Fixed a large number of compilation errors in the test files that arose from these changes. There are still some compilation errors in the `internal/adapters/graphql/integration_test.go` file. These errors are due to the test files still trying to access the repositories directly from the `app.Application` struct. The remaining work is to update these tests to use the new application services.
60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"tercul/internal/app/analytics"
|
|
"tercul/internal/app/auth"
|
|
"tercul/internal/app/copyright"
|
|
"tercul/internal/app/localization"
|
|
"tercul/internal/app/monetization"
|
|
"tercul/internal/app/author"
|
|
"tercul/internal/app/collection"
|
|
"tercul/internal/app/bookmark"
|
|
"tercul/internal/app/comment"
|
|
"tercul/internal/app/like"
|
|
"tercul/internal/app/search"
|
|
"tercul/internal/app/category"
|
|
"tercul/internal/app/tag"
|
|
"tercul/internal/app/translation"
|
|
"tercul/internal/app/user"
|
|
"tercul/internal/app/work"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// Application is a container for all the application-layer services.
|
|
// It's used for dependency injection into the presentation layer (e.g., GraphQL resolvers).
|
|
type Application struct {
|
|
AnalyticsService analytics.Service
|
|
AuthCommands *auth.AuthCommands
|
|
AuthQueries *auth.AuthQueries
|
|
AuthorCommands *author.AuthorCommands
|
|
AuthorQueries *author.AuthorQueries
|
|
BookmarkCommands *bookmark.BookmarkCommands
|
|
BookmarkQueries *bookmark.BookmarkQueries
|
|
CategoryQueries *category.CategoryQueries
|
|
CollectionCommands *collection.CollectionCommands
|
|
CollectionQueries *collection.CollectionQueries
|
|
CommentCommands *comment.CommentCommands
|
|
CommentQueries *comment.CommentQueries
|
|
CopyrightCommands *copyright.CopyrightCommands
|
|
CopyrightQueries *copyright.CopyrightQueries
|
|
LikeCommands *like.LikeCommands
|
|
LikeQueries *like.LikeQueries
|
|
Localization localization.Service
|
|
Search search.IndexService
|
|
TagQueries *tag.TagQueries
|
|
UserQueries *user.UserQueries
|
|
WorkCommands *work.WorkCommands
|
|
WorkQueries *work.WorkQueries
|
|
TranslationCommands *translation.TranslationCommands
|
|
TranslationQueries *translation.TranslationQueries
|
|
|
|
// Repositories - to be refactored into app services
|
|
BookRepo domain.BookRepository
|
|
PublisherRepo domain.PublisherRepository
|
|
SourceRepo domain.SourceRepository
|
|
MonetizationQueries *monetization.MonetizationQueries
|
|
MonetizationCommands *monetization.MonetizationCommands
|
|
CopyrightRepo domain.CopyrightRepository
|
|
MonetizationRepo domain.MonetizationRepository
|
|
}
|