tercul-backend/internal/app/work/main_test.go
google-labs-jules[bot] 1c4dcbcf99 Refactor: Introduce service layer for application logic
This change introduces a service layer to encapsulate the business logic
for each domain aggregate. This will make the code more modular,
testable, and easier to maintain.

The following services have been created:
- author
- bookmark
- category
- collection
- comment
- like
- tag
- translation
- user

The main Application struct has been updated to use these new services.
The integration test suite has also been updated to use the new
Application struct and services.

This is a work in progress. The next step is to fix the compilation
errors and then refactor the resolvers to use the new services.
2025-09-09 02:28:25 +00:00

93 lines
3.0 KiB
Go

package work
import (
"context"
"tercul/internal/domain"
)
type mockWorkRepository struct {
domain.WorkRepository
createFunc func(ctx context.Context, work *domain.Work) error
updateFunc func(ctx context.Context, work *domain.Work) error
deleteFunc func(ctx context.Context, id uint) error
getByIDFunc func(ctx context.Context, id uint) (*domain.Work, error)
listFunc func(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[domain.Work], error)
getWithTranslationsFunc func(ctx context.Context, id uint) (*domain.Work, error)
findByTitleFunc func(ctx context.Context, title string) ([]domain.Work, error)
findByAuthorFunc func(ctx context.Context, authorID uint) ([]domain.Work, error)
findByCategoryFunc func(ctx context.Context, categoryID uint) ([]domain.Work, error)
findByLanguageFunc func(ctx context.Context, language string, page, pageSize int) (*domain.PaginatedResult[domain.Work], error)
}
func (m *mockWorkRepository) Create(ctx context.Context, work *domain.Work) error {
if m.createFunc != nil {
return m.createFunc(ctx, work)
}
return nil
}
func (m *mockWorkRepository) Update(ctx context.Context, work *domain.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) (*domain.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[domain.Work], error) {
if m.listFunc != nil {
return m.listFunc(ctx, page, pageSize)
}
return nil, nil
}
func (m *mockWorkRepository) GetWithTranslations(ctx context.Context, id uint) (*domain.Work, error) {
if m.getWithTranslationsFunc != nil {
return m.getWithTranslationsFunc(ctx, id)
}
return nil, nil
}
func (m *mockWorkRepository) FindByTitle(ctx context.Context, title string) ([]domain.Work, error) {
if m.findByTitleFunc != nil {
return m.findByTitleFunc(ctx, title)
}
return nil, nil
}
func (m *mockWorkRepository) FindByAuthor(ctx context.Context, authorID uint) ([]domain.Work, error) {
if m.findByAuthorFunc != nil {
return m.findByAuthorFunc(ctx, authorID)
}
return nil, nil
}
func (m *mockWorkRepository) FindByCategory(ctx context.Context, categoryID uint) ([]domain.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[domain.Work], error) {
if m.findByLanguageFunc != nil {
return m.findByLanguageFunc(ctx, language, page, pageSize)
}
return nil, nil
}
type mockAnalyzer struct {
analyzeWorkFunc func(ctx context.Context, workID uint) error
}
func (m *mockAnalyzer) AnalyzeWork(ctx context.Context, workID uint) error {
if m.analyzeWorkFunc != nil {
return m.analyzeWorkFunc(ctx, workID)
}
return nil
}