add new route to general statistics
This commit is contained in:
parent
4f248ffeed
commit
bd9cdfd7d7
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-20240315133641-4cc870989184
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315174302-9c8724561332
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -192,5 +192,7 @@ penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315113539-a26
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315113539-a26dce3bed0e/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315133641-4cc870989184 h1:tiQQbN7OHrCohzPVeA6g9M7/WZDWMTahQmEDmYO20d8=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315133641-4cc870989184/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315174302-9c8724561332 h1:AZDjQxeoDzSpzzcHg0VoX3kiofqwaiHPne9slnr4U/Q=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315174302-9c8724561332/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=
|
||||
|
@ -50,4 +50,5 @@ func (s *Service) Register(app *fiber.App) {
|
||||
|
||||
// statistics handlers
|
||||
app.Post("/statistic/:quizID/devices", s.GetDeviceStatistics)
|
||||
app.Post("/statistic/:quizID/general", s.GetGeneralStatistics)
|
||||
}
|
||||
|
@ -35,3 +35,31 @@ func (s *Service) GetDeviceStatistics(ctx *fiber.Ctx) error {
|
||||
|
||||
return ctx.Status(fiber.StatusOK).JSON(deviceStats)
|
||||
}
|
||||
|
||||
type GeneralStatsResp struct {
|
||||
Open, Result, AvTime, Conversion map[uint64]uint64
|
||||
}
|
||||
|
||||
func (s *Service) GetGeneralStatistics(ctx *fiber.Ctx) error {
|
||||
quizIDStr := ctx.Params("quizID")
|
||||
quizId, err := strconv.ParseInt(quizIDStr, 10, 64)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("Invalid quiz ID format")
|
||||
}
|
||||
|
||||
var req DeviceStatReq
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("Invalid request data")
|
||||
}
|
||||
|
||||
generalStats, err := s.dal.StatisticsRepo.GetGeneralStatistics(ctx.Context(), statistics.DeviceStatReq{
|
||||
QuizId: quizId,
|
||||
From: req.From,
|
||||
To: req.To,
|
||||
})
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||
}
|
||||
|
||||
return ctx.Status(fiber.StatusOK).JSON(generalStats)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user