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.
225 lines
9.4 KiB
Go
225 lines
9.4 KiB
Go
package copyright
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
type mockCopyrightRepository struct {
|
|
createFunc func(ctx context.Context, copyright *domain.Copyright) error
|
|
updateFunc func(ctx context.Context, copyright *domain.Copyright) error
|
|
deleteFunc func(ctx context.Context, id uint) error
|
|
addCopyrightToWorkFunc func(ctx context.Context, workID uint, copyrightID uint) error
|
|
removeCopyrightFromWorkFunc func(ctx context.Context, workID uint, copyrightID uint) error
|
|
addCopyrightToAuthorFunc func(ctx context.Context, authorID uint, copyrightID uint) error
|
|
removeCopyrightFromAuthorFunc func(ctx context.Context, authorID uint, copyrightID uint) error
|
|
addCopyrightToBookFunc func(ctx context.Context, bookID uint, copyrightID uint) error
|
|
removeCopyrightFromBookFunc func(ctx context.Context, bookID uint, copyrightID uint) error
|
|
addCopyrightToPublisherFunc func(ctx context.Context, publisherID uint, copyrightID uint) error
|
|
removeCopyrightFromPublisherFunc func(ctx context.Context, publisherID uint, copyrightID uint) error
|
|
addCopyrightToSourceFunc func(ctx context.Context, sourceID uint, copyrightID uint) error
|
|
removeCopyrightFromSourceFunc func(ctx context.Context, sourceID uint, copyrightID uint) error
|
|
addTranslationFunc func(ctx context.Context, translation *domain.CopyrightTranslation) error
|
|
getByIDFunc func(ctx context.Context, id uint) (*domain.Copyright, error)
|
|
listAllFunc func(ctx context.Context) ([]domain.Copyright, error)
|
|
getTranslationsFunc func(ctx context.Context, copyrightID uint) ([]domain.CopyrightTranslation, error)
|
|
getTranslationByLanguageFunc func(ctx context.Context, copyrightID uint, languageCode string) (*domain.CopyrightTranslation, error)
|
|
}
|
|
|
|
func (m *mockCopyrightRepository) Create(ctx context.Context, copyright *domain.Copyright) error {
|
|
if m.createFunc != nil {
|
|
return m.createFunc(ctx, copyright)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) Update(ctx context.Context, copyright *domain.Copyright) error {
|
|
if m.updateFunc != nil {
|
|
return m.updateFunc(ctx, copyright)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) Delete(ctx context.Context, id uint) error {
|
|
if m.deleteFunc != nil {
|
|
return m.deleteFunc(ctx, id)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) AddCopyrightToWork(ctx context.Context, workID uint, copyrightID uint) error {
|
|
if m.addCopyrightToWorkFunc != nil {
|
|
return m.addCopyrightToWorkFunc(ctx, workID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) RemoveCopyrightFromWork(ctx context.Context, workID uint, copyrightID uint) error {
|
|
if m.removeCopyrightFromWorkFunc != nil {
|
|
return m.removeCopyrightFromWorkFunc(ctx, workID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) AddCopyrightToAuthor(ctx context.Context, authorID uint, copyrightID uint) error {
|
|
if m.addCopyrightToAuthorFunc != nil {
|
|
return m.addCopyrightToAuthorFunc(ctx, authorID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) RemoveCopyrightFromAuthor(ctx context.Context, authorID uint, copyrightID uint) error {
|
|
if m.removeCopyrightFromAuthorFunc != nil {
|
|
return m.removeCopyrightFromAuthorFunc(ctx, authorID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) AddCopyrightToBook(ctx context.Context, bookID uint, copyrightID uint) error {
|
|
if m.addCopyrightToBookFunc != nil {
|
|
return m.addCopyrightToBookFunc(ctx, bookID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) RemoveCopyrightFromBook(ctx context.Context, bookID uint, copyrightID uint) error {
|
|
if m.removeCopyrightFromBookFunc != nil {
|
|
return m.removeCopyrightFromBookFunc(ctx, bookID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) AddCopyrightToPublisher(ctx context.Context, publisherID uint, copyrightID uint) error {
|
|
if m.addCopyrightToPublisherFunc != nil {
|
|
return m.addCopyrightToPublisherFunc(ctx, publisherID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) RemoveCopyrightFromPublisher(ctx context.Context, publisherID uint, copyrightID uint) error {
|
|
if m.removeCopyrightFromPublisherFunc != nil {
|
|
return m.removeCopyrightFromPublisherFunc(ctx, publisherID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) AddCopyrightToSource(ctx context.Context, sourceID uint, copyrightID uint) error {
|
|
if m.addCopyrightToSourceFunc != nil {
|
|
return m.addCopyrightToSourceFunc(ctx, sourceID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) RemoveCopyrightFromSource(ctx context.Context, sourceID uint, copyrightID uint) error {
|
|
if m.removeCopyrightFromSourceFunc != nil {
|
|
return m.removeCopyrightFromSourceFunc(ctx, sourceID, copyrightID)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) AddTranslation(ctx context.Context, translation *domain.CopyrightTranslation) error {
|
|
if m.addTranslationFunc != nil {
|
|
return m.addTranslationFunc(ctx, translation)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) GetByID(ctx context.Context, id uint) (*domain.Copyright, error) {
|
|
if m.getByIDFunc != nil {
|
|
return m.getByIDFunc(ctx, id)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) ListAll(ctx context.Context) ([]domain.Copyright, error) {
|
|
if m.listAllFunc != nil {
|
|
return m.listAllFunc(ctx)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) GetTranslations(ctx context.Context, copyrightID uint) ([]domain.CopyrightTranslation, error) {
|
|
if m.getTranslationsFunc != nil {
|
|
return m.getTranslationsFunc(ctx, copyrightID)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) GetTranslationByLanguage(ctx context.Context, copyrightID uint, languageCode string) (*domain.CopyrightTranslation, error) {
|
|
if m.getTranslationByLanguageFunc != nil {
|
|
return m.getTranslationByLanguageFunc(ctx, copyrightID, languageCode)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// Implement the rest of the CopyrightRepository interface with empty methods.
|
|
func (m *mockCopyrightRepository) List(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[domain.Copyright], error) {
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) Count(ctx context.Context) (int64, error) { return 0, nil }
|
|
func (m *mockCopyrightRepository) CreateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Copyright) error {
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Copyright, error) {
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) UpdateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Copyright) error {
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) DeleteInTx(ctx context.Context, tx *gorm.DB, id uint) error {
|
|
return nil
|
|
}
|
|
func (m *mockCopyrightRepository) ListWithOptions(ctx context.Context, options *domain.QueryOptions) ([]domain.Copyright, error) {
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) CountWithOptions(ctx context.Context, options *domain.QueryOptions) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
func (m *mockCopyrightRepository) FindWithPreload(ctx context.Context, preloads []string, id uint) (*domain.Copyright, error) {
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) GetAllForSync(ctx context.Context, batchSize, offset int) ([]domain.Copyright, error) {
|
|
return nil, nil
|
|
}
|
|
func (m *mockCopyrightRepository) Exists(ctx context.Context, id uint) (bool, error) { return false, nil }
|
|
func (m *mockCopyrightRepository) BeginTx(ctx context.Context) (*gorm.DB, error) { return nil, nil }
|
|
func (m *mockCopyrightRepository) WithTx(ctx context.Context, fn func(tx *gorm.DB) error) error {
|
|
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
|
|
}
|