tercul-backend/internal/jobs/trending/trending.go
google-labs-jules[bot] 52101fbeda Refactor: Expose Analytics Service via GraphQL
This commit refactors the analytics service to align with the new DDD architecture and exposes it through the GraphQL API.

Key changes:
- A new `AnalyticsService` has been created in `internal/application/services` to encapsulate analytics-related business logic.
- The GraphQL resolver has been updated to use the new `AnalyticsService`, providing a clean and maintainable API.
- The old analytics service and its related files have been removed, reducing code duplication and confusion.
- The `bookmark`, `like`, and `work` services have been refactored to remove their dependencies on the old analytics repository.
- Unit tests have been added for the new `AnalyticsService`, and existing tests have been updated to reflect the refactoring.
2025-10-03 04:10:16 +00:00

42 lines
1016 B
Go

package trending
import (
"context"
"encoding/json"
"fmt"
"tercul/internal/application/services"
"github.com/hibiken/asynq"
)
const (
TaskUpdateTrending = "task:trending:update"
)
type UpdateTrendingPayload struct {
// No payload needed for now
}
func NewUpdateTrendingTask() (*asynq.Task, error) {
payload, err := json.Marshal(UpdateTrendingPayload{})
if err != nil {
return nil, err
}
return asynq.NewTask(TaskUpdateTrending, payload), nil
}
func HandleUpdateTrendingTask(analyticsService services.AnalyticsService) asynq.HandlerFunc {
return func(ctx context.Context, t *asynq.Task) error {
var p UpdateTrendingPayload
if err := json.Unmarshal(t.Payload(), &p); err != nil {
return err
}
// return analyticsService.UpdateTrending(ctx)
panic(fmt.Errorf("not implemented: Analytics - analytics"))
}
}
func RegisterTrendingHandlers(mux *asynq.ServeMux, analyticsService services.AnalyticsService) {
mux.HandleFunc(TaskUpdateTrending, HandleUpdateTrendingTask(analyticsService))
}