mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11: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.
151 lines
6.3 KiB
Go
151 lines
6.3 KiB
Go
package monetization
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/domain/work"
|
|
)
|
|
|
|
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 {
|
|
work.WorkRepository
|
|
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*work.Work, error)
|
|
}
|
|
|
|
func (m *mockWorkRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*work.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
|
|
}
|