mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
This commit isolates the `Work` aggregate into its own package at `internal/domain/work`, following the first step of the refactoring plan in `refactor.md`. - The `Work` struct, related types, and the `WorkRepository` interface have been moved to the new package. - A circular dependency between `domain` and `work` was resolved by moving the `AnalyticsRepository` to the `app` layer. - All references to the moved types have been updated across the entire codebase to fix compilation errors. - Test files, including mocks and integration tests, have been updated to reflect the new structure.
93 lines
3.2 KiB
Go
93 lines
3.2 KiB
Go
package work
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/domain/work"
|
|
)
|
|
|
|
type mockWorkRepository struct {
|
|
work.WorkRepository
|
|
createFunc func(ctx context.Context, work *work.Work) error
|
|
updateFunc func(ctx context.Context, work *work.Work) error
|
|
deleteFunc func(ctx context.Context, id uint) error
|
|
getByIDFunc func(ctx context.Context, id uint) (*work.Work, error)
|
|
listFunc func(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[work.Work], error)
|
|
getWithTranslationsFunc func(ctx context.Context, id uint) (*work.Work, error)
|
|
findByTitleFunc func(ctx context.Context, title string) ([]work.Work, error)
|
|
findByAuthorFunc func(ctx context.Context, authorID uint) ([]work.Work, error)
|
|
findByCategoryFunc func(ctx context.Context, categoryID uint) ([]work.Work, error)
|
|
findByLanguageFunc func(ctx context.Context, language string, page, pageSize int) (*domain.PaginatedResult[work.Work], error)
|
|
}
|
|
|
|
func (m *mockWorkRepository) Create(ctx context.Context, work *work.Work) error {
|
|
if m.createFunc != nil {
|
|
return m.createFunc(ctx, work)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockWorkRepository) Update(ctx context.Context, work *work.Work) error {
|
|
if m.updateFunc != nil {
|
|
return m.updateFunc(ctx, work)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockWorkRepository) Delete(ctx context.Context, id uint) error {
|
|
if m.deleteFunc != nil {
|
|
return m.deleteFunc(ctx, id)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockWorkRepository) GetByID(ctx context.Context, id uint) (*work.Work, error) {
|
|
if m.getByIDFunc != nil {
|
|
return m.getByIDFunc(ctx, id)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockWorkRepository) List(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[work.Work], error) {
|
|
if m.listFunc != nil {
|
|
return m.listFunc(ctx, page, pageSize)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockWorkRepository) GetWithTranslations(ctx context.Context, id uint) (*work.Work, error) {
|
|
if m.getWithTranslationsFunc != nil {
|
|
return m.getWithTranslationsFunc(ctx, id)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockWorkRepository) FindByTitle(ctx context.Context, title string) ([]work.Work, error) {
|
|
if m.findByTitleFunc != nil {
|
|
return m.findByTitleFunc(ctx, title)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockWorkRepository) FindByAuthor(ctx context.Context, authorID uint) ([]work.Work, error) {
|
|
if m.findByAuthorFunc != nil {
|
|
return m.findByAuthorFunc(ctx, authorID)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockWorkRepository) FindByCategory(ctx context.Context, categoryID uint) ([]work.Work, error) {
|
|
if m.findByCategoryFunc != nil {
|
|
return m.findByCategoryFunc(ctx, categoryID)
|
|
}
|
|
return nil, nil
|
|
}
|
|
func (m *mockWorkRepository) FindByLanguage(ctx context.Context, language string, page, pageSize int) (*domain.PaginatedResult[work.Work], error) {
|
|
if m.findByLanguageFunc != nil {
|
|
return m.findByLanguageFunc(ctx, language, page, pageSize)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
type mockSearchClient struct {
|
|
indexWorkFunc func(ctx context.Context, work *work.Work, pipeline string) error
|
|
}
|
|
|
|
func (m *mockSearchClient) IndexWork(ctx context.Context, work *work.Work, pipeline string) error {
|
|
if m.indexWorkFunc != nil {
|
|
return m.indexWorkFunc(ctx, work, pipeline)
|
|
}
|
|
return nil
|
|
} |