init new statistic route
This commit is contained in:
parent
d20e1696de
commit
92f64fa246
53
app/app.go
53
app/app.go
@ -8,13 +8,8 @@ import (
|
||||
"github.com/skeris/appInit"
|
||||
"github.com/themakers/hlog"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/penahub_common/privilege"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/healthchecks"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/service"
|
||||
)
|
||||
|
||||
@ -49,13 +44,13 @@ type Options struct {
|
||||
NumberPort string `env:"PORT" default:"1488"`
|
||||
CrtFile string `env:"CRT" default:"server.crt"`
|
||||
KeyFile string `env:"KEY" default:"server.key"`
|
||||
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
HubAdminUrl string `env:"HUB_ADMIN_URL"`
|
||||
ServiceName string `env:"SERVICE_NAME" default:"squiz"`
|
||||
AuthServiceURL string `env:"AUTH_URL"`
|
||||
RedirectURL string `env:"REDIRECT_URL" default:"https://squiz.pena.digital"`
|
||||
PubKey string `env:"PUBLIC_KEY"`
|
||||
PrivKey string `env:"PRIVATE_KEY"`
|
||||
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
//HubAdminUrl string `env:"HUB_ADMIN_URL"`
|
||||
ServiceName string `env:"SERVICE_NAME" default:"squiz"`
|
||||
//AuthServiceURL string `env:"AUTH_URL"`
|
||||
RedirectURL string `env:"REDIRECT_URL" default:"https://squiz.pena.digital"`
|
||||
//PubKey string `env:"PUBLIC_KEY"`
|
||||
//PrivKey string `env:"PRIVATE_KEY"`
|
||||
}
|
||||
|
||||
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
|
||||
@ -92,9 +87,9 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
|
||||
logger := hlog.New(zapLogger)
|
||||
logger.Emit(InfoSvcStarted{})
|
||||
|
||||
authClient := auth.NewAuthClient(options.AuthServiceURL)
|
||||
//authClient := auth.NewAuthClient(options.AuthServiceURL)
|
||||
|
||||
pgdal, err := dal.New(ctx, options.PostgresCredentials, authClient)
|
||||
pgdal, err := dal.New(ctx, options.PostgresCredentials, nil)
|
||||
if err != nil {
|
||||
fmt.Println("NEW", err)
|
||||
return nil, err
|
||||
@ -105,28 +100,28 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clientData := privilege.Client{
|
||||
URL: options.HubAdminUrl,
|
||||
ServiceName: options.ServiceName,
|
||||
Privileges: model.Privileges,
|
||||
}
|
||||
fiberClient := &fiber.Client{}
|
||||
privilegeController := privilege.NewPrivilege(clientData, fiberClient)
|
||||
err = privilegeController.PublishPrivileges()
|
||||
if err != nil {
|
||||
fmt.Println("Failed to publish privileges", err)
|
||||
}
|
||||
|
||||
encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
|
||||
//clientData := privilege.Client{
|
||||
// URL: options.HubAdminUrl,
|
||||
// ServiceName: options.ServiceName,
|
||||
// Privileges: model.Privileges,
|
||||
//}
|
||||
//fiberClient := &fiber.Client{}
|
||||
//privilegeController := privilege.NewPrivilege(clientData, fiberClient)
|
||||
//err = privilegeController.PublishPrivileges()
|
||||
//if err != nil {
|
||||
// fmt.Println("Failed to publish privileges", err)
|
||||
//}
|
||||
//
|
||||
//encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
|
||||
app := fiber.New()
|
||||
app.Use(middleware.JWTAuth())
|
||||
//app.Use(middleware.JWTAuth())
|
||||
app.Get("/liveness", healthchecks.Liveness)
|
||||
app.Get("/readiness", healthchecks.Readiness(&workerErr)) //todo parametrized readiness. should discuss ready reason
|
||||
|
||||
svc := service.New(service.Deps{
|
||||
Dal: pgdal,
|
||||
RedirectURl: options.RedirectURL,
|
||||
Encrypt: encrypt,
|
||||
Encrypt: nil,
|
||||
})
|
||||
|
||||
svc.Register(app)
|
||||
|
2
go.mod
2
go.mod
@ -15,7 +15,7 @@ require (
|
||||
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf
|
||||
go.uber.org/zap v1.26.0
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240325084116-830f54870853
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -188,5 +188,7 @@ penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5 h1:c9/hwlNC5nd/6M61ULCWg9BQl5wWeK21oQIaEEEGe8c=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240325084116-830f54870853 h1:wr7r6meuCAunxE/KCg93hM4XDzpII96pya4RYrwxHmc=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240325084116-830f54870853/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3 h1:BLHIUnJAttW9OAW7A63H9ON/HPhXdpBa/YPUQWD4ORA=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3/go.mod h1:/BFcX4F10DRuFuAHlwkKO+1QAXPL4i49x1tsrTwxlqE=
|
||||
|
@ -63,4 +63,5 @@ func (s *Service) Register(app *fiber.App) {
|
||||
app.Post("/statistic/:quizID/devices", s.GetDeviceStatistics)
|
||||
app.Post("/statistic/:quizID/general", s.GetGeneralStatistics)
|
||||
app.Post("/statistic/:quizID/questions", s.GetQuestionsStatistics)
|
||||
app.Post("/statistic", s.AllServiceStatistics)
|
||||
}
|
||||
|
@ -87,3 +87,21 @@ func (s *Service) GetQuestionsStatistics(ctx *fiber.Ctx) error {
|
||||
|
||||
return ctx.Status(fiber.StatusOK).JSON(questionsStats)
|
||||
}
|
||||
|
||||
type StatisticReq struct {
|
||||
From, To uint64 // временные границы выбора статистики
|
||||
}
|
||||
|
||||
func (s *Service) AllServiceStatistics(ctx *fiber.Ctx) error {
|
||||
var req StatisticReq
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
ctx.Status(fiber.StatusBadRequest).SendString("Invalid request data")
|
||||
}
|
||||
|
||||
allSvcStats, err := s.dal.StatisticsRepo.AllServiceStatistics(ctx.Context(), req.From, req.To)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||
}
|
||||
|
||||
return ctx.Status(fiber.StatusOK).JSON(allSvcStats)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user