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.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package like
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// LikeQueries contains the query handlers for the like aggregate.
|
|
type LikeQueries struct {
|
|
repo domain.LikeRepository
|
|
}
|
|
|
|
// NewLikeQueries creates a new LikeQueries handler.
|
|
func NewLikeQueries(repo domain.LikeRepository) *LikeQueries {
|
|
return &LikeQueries{repo: repo}
|
|
}
|
|
|
|
// Like returns a like by ID.
|
|
func (q *LikeQueries) Like(ctx context.Context, id uint) (*domain.Like, error) {
|
|
return q.repo.GetByID(ctx, id)
|
|
}
|
|
|
|
// LikesByUserID returns all likes for a user.
|
|
func (q *LikeQueries) LikesByUserID(ctx context.Context, userID uint) ([]domain.Like, error) {
|
|
return q.repo.ListByUserID(ctx, userID)
|
|
}
|
|
|
|
// LikesByWorkID returns all likes for a work.
|
|
func (q *LikeQueries) LikesByWorkID(ctx context.Context, workID uint) ([]domain.Like, error) {
|
|
return q.repo.ListByWorkID(ctx, workID)
|
|
}
|
|
|
|
// LikesByTranslationID returns all likes for a translation.
|
|
func (q *LikeQueries) LikesByTranslationID(ctx context.Context, translationID uint) ([]domain.Like, error) {
|
|
return q.repo.ListByTranslationID(ctx, translationID)
|
|
}
|
|
|
|
// LikesByCommentID returns all likes for a comment.
|
|
func (q *LikeQueries) LikesByCommentID(ctx context.Context, commentID uint) ([]domain.Like, error) {
|
|
return q.repo.ListByCommentID(ctx, commentID)
|
|
}
|
|
|
|
// Likes returns all likes.
|
|
func (q *LikeQueries) Likes(ctx context.Context) ([]domain.Like, error) {
|
|
return q.repo.ListAll(ctx)
|
|
}
|