/
statistic.go
45 lines (38 loc) · 1.21 KB
/
statistic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package dal
import (
"database/sql"
"github.com/freonservice/freon/internal/dao"
api "github.com/freonservice/freon/pkg/freonApi"
)
// count localizations
// count identifiers
// count users
// count completed translations by localizations
// count categories
func (r *Repo) GetStatistic(ctx Ctx) (*dao.Statistic, error) {
var stat dao.Statistic
_ = r.DB.QueryRowContext(ctx, sqlStatCountCategories).Scan(&stat.CountCategories)
_ = r.DB.QueryRowContext(ctx, sqlStatCountUsers, api.Status_ACTIVE).Scan(&stat.CountUsers)
_ = r.DB.QueryRowContext(ctx, sqlStatCountIdentifiers, api.Status_ACTIVE).Scan(&stat.CountIdentifiers)
_ = r.DB.QueryRowContext(ctx, sqlStatCountLocalizations, api.Status_ACTIVE).Scan(&stat.CountLocalizations)
rows, err := r.DB.QueryContext(ctx, sqlStatTranslations)
if err != nil {
return nil, err
} else if rows.Err() != nil {
return nil, rows.Err()
}
defer rows.Close()
var stats []*dao.StatTranslation
for rows.Next() {
var entity dao.StatTranslation
if err = rows.Scan(&entity.Fulfilled, &entity.LangName); err != nil {
break
}
stats = append(stats, &entity)
}
if err != nil && err != sql.ErrNoRows {
return nil, err
}
stat.StatTranslations = stats
return &stat, nil
}