Files
kurious/internal/kurious/app/query/listorganizationstats.go
Aleksandr Trushkin c0f45d98c2 count courses by school
2024-06-16 23:55:49 +03:00

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
}