From bec22dd0b5b374f5637932134d5fb6d59af1327b Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 25 Mar 2024 11:30:06 +0300 Subject: [PATCH] add new AllServiceStatistics query --- dal/db_query/queries.sql | 23 ++++++++++++++++++++++- repository/statistics/statistics.go | 11 +++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index 08b9f90..d7ca343 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -610,4 +610,25 @@ WHERE question.quiz_id = $1 AND deleted = false; -- name: GetQidOwner :one -SELECT accountid FROM quiz where qid=$1; \ No newline at end of file +SELECT accountid FROM quiz where qid=$1; + +-- name: AllServiceStatistics :one +WITH Registrations AS ( + SELECT COUNT(*) AS registration_count + FROM account + WHERE created_at >= to_timestamp($1) AND created_at <= to_timestamp($2) +), + Quizes AS ( + SELECT COUNT(*) AS quiz_count + FROM quiz + WHERE deleted = false AND created_at >= to_timestamp($1) AND created_at <= to_timestamp($2) + ), + Results AS ( + SELECT COUNT(*) AS result_count + FROM answer + WHERE result = true AND created_at >= to_timestamp($1) AND created_at <= to_timestamp($2) + ) +SELECT + (SELECT registration_count FROM Registrations) AS registrations, + (SELECT quiz_count FROM Quizes) AS quizes, + (SELECT result_count FROM Results) AS results; \ No newline at end of file diff --git a/repository/statistics/statistics.go b/repository/statistics/statistics.go index 77ad210..e3bbad7 100644 --- a/repository/statistics/statistics.go +++ b/repository/statistics/statistics.go @@ -145,3 +145,14 @@ func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req D return resp, nil } + +type StatisticResp struct { + // от from до to + Registrations uint64 // количество зарегестрированных аккаунтов + Quizes uint64 // количество созданных не удаленных квизов + Results uint64 // количество ответов с result = true +} + +func (r *StatisticsRepository) AllServiceStatistics(ctx context.Context, from, to uint64) (StatisticResp, error) { + allSvcStats, err := r.queries.AllServiceStatistics +}