mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This commit marks the completion of a major refactoring effort to stabilize the codebase, improve its structure, and prepare it for production. The key changes include: - **Domain Layer Consolidation:** The `Work` entity and its related types, along with all other domain entities and repository interfaces, have been consolidated into the main `internal/domain` package. This eliminates import cycles and provides a single, coherent source of truth for the domain model. - **Data Access Layer Refactoring:** The repository implementations in `internal/data/sql` have been updated to align with the new domain layer. The `BaseRepositoryImpl` has been corrected to use pointer receivers, and all concrete repositories now correctly embed it, ensuring consistent and correct behavior. - **Application Layer Stabilization:** All application services in `internal/app` have been updated to use the new domain types and repository interfaces. Dependency injection has been corrected throughout the application, ensuring that all services are initialized with the correct dependencies. - **GraphQL Adapter Fixes:** The GraphQL resolver implementation in `internal/adapters/graphql` has been updated to correctly handle the new domain types and service methods. The auto-generated GraphQL code has been regenerated to ensure it is in sync with the schema and runtime. - **Test Suite Overhaul:** All test suites have been fixed to correctly implement their respective interfaces and use the updated domain model. Mock repositories and test suites have been corrected to properly embed the `testify` base types, resolving numerous build and linter errors. - **Dependency Management:** The Go modules have been tidied, and the module cache has been cleaned to ensure a consistent and correct dependency graph. - **Code Quality and Verification:** The entire codebase now passes all builds, tests, and linter checks, ensuring a high level of quality and stability. This comprehensive effort has resulted in a more robust, maintainable, and production-ready application.
150 lines
6.2 KiB
Go
150 lines
6.2 KiB
Go
package monetization
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
type mockMonetizationRepository struct {
|
|
domain.MonetizationRepository
|
|
addMonetizationToWorkFunc func(ctx context.Context, workID uint, monetizationID uint) error
|
|
removeMonetizationFromWorkFunc func(ctx context.Context, workID uint, monetizationID uint) error
|
|
addMonetizationToAuthorFunc func(ctx context.Context, authorID uint, monetizationID uint) error
|
|
removeMonetizationFromAuthorFunc func(ctx context.Context, authorID uint, monetizationID uint) error
|
|
addMonetizationToBookFunc func(ctx context.Context, bookID uint, monetizationID uint) error
|
|
removeMonetizationFromBookFunc func(ctx context.Context, bookID uint, monetizationID uint) error
|
|
addMonetizationToPublisherFunc func(ctx context.Context, publisherID uint, monetizationID uint) error
|
|
removeMonetizationFromPublisherFunc func(ctx context.Context, publisherID uint, monetizationID uint) error
|
|
addMonetizationToSourceFunc func(ctx context.Context, sourceID uint, monetizationID uint) error
|
|
removeMonetizationFromSourceFunc func(ctx context.Context, sourceID uint, monetizationID uint) error
|
|
getByIDFunc func(ctx context.Context, id uint) (*domain.Monetization, error)
|
|
listAllFunc func(ctx context.Context) ([]domain.Monetization, error)
|
|
}
|
|
|
|
func (m *mockMonetizationRepository) GetByID(ctx context.Context, id uint) (*domain.Monetization, error) {
|
|
if m.getByIDFunc != nil {
|
|
return m.getByIDFunc(ctx, id)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *mockMonetizationRepository) ListAll(ctx context.Context) ([]domain.Monetization, error) {
|
|
if m.listAllFunc != nil {
|
|
return m.listAllFunc(ctx)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *mockMonetizationRepository) AddMonetizationToWork(ctx context.Context, workID uint, monetizationID uint) error {
|
|
if m.addMonetizationToWorkFunc != nil {
|
|
return m.addMonetizationToWorkFunc(ctx, workID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) RemoveMonetizationFromWork(ctx context.Context, workID uint, monetizationID uint) error {
|
|
if m.removeMonetizationFromWorkFunc != nil {
|
|
return m.removeMonetizationFromWorkFunc(ctx, workID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) AddMonetizationToAuthor(ctx context.Context, authorID uint, monetizationID uint) error {
|
|
if m.addMonetizationToAuthorFunc != nil {
|
|
return m.addMonetizationToAuthorFunc(ctx, authorID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) RemoveMonetizationFromAuthor(ctx context.Context, authorID uint, monetizationID uint) error {
|
|
if m.removeMonetizationFromAuthorFunc != nil {
|
|
return m.removeMonetizationFromAuthorFunc(ctx, authorID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) AddMonetizationToBook(ctx context.Context, bookID uint, monetizationID uint) error {
|
|
if m.addMonetizationToBookFunc != nil {
|
|
return m.addMonetizationToBookFunc(ctx, bookID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) RemoveMonetizationFromBook(ctx context.Context, bookID uint, monetizationID uint) error {
|
|
if m.removeMonetizationFromBookFunc != nil {
|
|
return m.removeMonetizationFromBookFunc(ctx, bookID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) AddMonetizationToPublisher(ctx context.Context, publisherID uint, monetizationID uint) error {
|
|
if m.addMonetizationToPublisherFunc != nil {
|
|
return m.addMonetizationToPublisherFunc(ctx, publisherID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) RemoveMonetizationFromPublisher(ctx context.Context, publisherID uint, monetizationID uint) error {
|
|
if m.removeMonetizationFromPublisherFunc != nil {
|
|
return m.removeMonetizationFromPublisherFunc(ctx, publisherID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) AddMonetizationToSource(ctx context.Context, sourceID uint, monetizationID uint) error {
|
|
if m.addMonetizationToSourceFunc != nil {
|
|
return m.addMonetizationToSourceFunc(ctx, sourceID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockMonetizationRepository) RemoveMonetizationFromSource(ctx context.Context, sourceID uint, monetizationID uint) error {
|
|
if m.removeMonetizationFromSourceFunc != nil {
|
|
return m.removeMonetizationFromSourceFunc(ctx, sourceID, monetizationID)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type mockWorkRepository struct {
|
|
domain.WorkRepository
|
|
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Work, error)
|
|
}
|
|
|
|
func (m *mockWorkRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Work, error) {
|
|
if m.getByIDWithOptionsFunc != nil {
|
|
return m.getByIDWithOptionsFunc(ctx, id, options)
|
|
}
|
|
return nil, nil
|
|
}
|
|
type mockAuthorRepository struct {
|
|
domain.AuthorRepository
|
|
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Author, error)
|
|
}
|
|
func (m *mockAuthorRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Author, error) {
|
|
if m.getByIDWithOptionsFunc != nil {
|
|
return m.getByIDWithOptionsFunc(ctx, id, options)
|
|
}
|
|
return nil, nil
|
|
}
|
|
type mockBookRepository struct {
|
|
domain.BookRepository
|
|
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Book, error)
|
|
}
|
|
func (m *mockBookRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Book, error) {
|
|
if m.getByIDWithOptionsFunc != nil {
|
|
return m.getByIDWithOptionsFunc(ctx, id, options)
|
|
}
|
|
return nil, nil
|
|
}
|
|
type mockPublisherRepository struct {
|
|
domain.PublisherRepository
|
|
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Publisher, error)
|
|
}
|
|
func (m *mockPublisherRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Publisher, error) {
|
|
if m.getByIDWithOptionsFunc != nil {
|
|
return m.getByIDWithOptionsFunc(ctx, id, options)
|
|
}
|
|
return nil, nil
|
|
}
|
|
type mockSourceRepository struct {
|
|
domain.SourceRepository
|
|
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Source, error)
|
|
}
|
|
func (m *mockSourceRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Source, error) {
|
|
if m.getByIDWithOptionsFunc != nil {
|
|
return m.getByIDWithOptionsFunc(ctx, id, options)
|
|
}
|
|
return nil, nil
|
|
}
|