53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"git.loyso.art/frx/kurious/internal/common/decorator"
|
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
|
)
|
|
|
|
type ListOrganizationsStats struct {
|
|
LearningTypeID string
|
|
CourseThematicID string
|
|
IDs []string
|
|
}
|
|
|
|
type ListOrganizationsStatsHandler decorator.QueryHandler[
|
|
ListOrganizationsStats,
|
|
[]domain.OrganizationStat,
|
|
]
|
|
|
|
type listOrganizationsStatsHandler struct {
|
|
repo domain.OrganizationRepository
|
|
}
|
|
|
|
func NewListOrganizationsStatsHandler(
|
|
repo domain.OrganizationRepository,
|
|
log *slog.Logger,
|
|
) ListOrganizationsStatsHandler {
|
|
h := listOrganizationsStatsHandler{
|
|
repo: repo,
|
|
}
|
|
|
|
return decorator.AddQueryDecorators(h, log)
|
|
}
|
|
|
|
func (h listOrganizationsStatsHandler) Handle(
|
|
ctx context.Context,
|
|
query ListOrganizationsStats,
|
|
) ([]domain.OrganizationStat, error) {
|
|
stats, err := h.repo.ListStats(ctx, domain.ListOrganizationsParams{
|
|
LearningTypeID: query.LearningTypeID,
|
|
CourseThematicID: query.CourseThematicID,
|
|
IDs: query.IDs,
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("listing stats: %w", err)
|
|
}
|
|
|
|
return stats, nil
|
|
}
|