mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
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.
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package collection
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// CollectionQueries contains the query handlers for the collection aggregate.
|
|
type CollectionQueries struct {
|
|
repo domain.CollectionRepository
|
|
}
|
|
|
|
// NewCollectionQueries creates a new CollectionQueries handler.
|
|
func NewCollectionQueries(repo domain.CollectionRepository) *CollectionQueries {
|
|
return &CollectionQueries{repo: repo}
|
|
}
|
|
|
|
// Collection returns a collection by ID.
|
|
func (q *CollectionQueries) Collection(ctx context.Context, id uint) (*domain.Collection, error) {
|
|
return q.repo.GetByID(ctx, id)
|
|
}
|
|
|
|
// CollectionsByUserID returns all collections for a user.
|
|
func (q *CollectionQueries) CollectionsByUserID(ctx context.Context, userID uint) ([]domain.Collection, error) {
|
|
return q.repo.ListByUserID(ctx, userID)
|
|
}
|
|
|
|
// PublicCollections returns all public collections.
|
|
func (q *CollectionQueries) PublicCollections(ctx context.Context) ([]domain.Collection, error) {
|
|
return q.repo.ListPublic(ctx)
|
|
}
|
|
|
|
// CollectionsByWorkID returns all collections for a work.
|
|
func (q *CollectionQueries) CollectionsByWorkID(ctx context.Context, workID uint) ([]domain.Collection, error) {
|
|
return q.repo.ListByWorkID(ctx, workID)
|
|
}
|
|
|
|
// Collections returns all collections.
|
|
func (q *CollectionQueries) Collections(ctx context.Context) ([]domain.Collection, error) {
|
|
return q.repo.ListAll(ctx)
|
|
}
|