init route to new device statistics method
This commit is contained in:
parent
de49fef4ba
commit
4f248ffeed
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-20240315113539-a26dce3bed0e
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315133641-4cc870989184
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -190,5 +190,7 @@ penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314133622-a34
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314133622-a34c0e2e5168/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240315113539-a26dce3bed0e h1:nd9ZkwEq2wPDG/Nc5TDh5EFNckqrUKsI6jU4es84vxU=
|
||||
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/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=
|
||||
|
@ -47,4 +47,7 @@ func (s *Service) Register(app *fiber.App) {
|
||||
app.Patch("/result/seen", s.SetStatus)
|
||||
app.Post("/results/:quizID/export", s.ExportResultsToCSV)
|
||||
app.Get("/result/:resultID", s.GetResultAnswers)
|
||||
|
||||
// statistics handlers
|
||||
app.Post("/statistic/:quizID/devices", s.GetDeviceStatistics)
|
||||
}
|
||||
|
37
service/statistic_svc.go
Normal file
37
service/statistic_svc.go
Normal file
@ -0,0 +1,37 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/statistics"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeviceStatReq struct {
|
||||
From uint64 // временные границы выбора статистики
|
||||
To uint64
|
||||
}
|
||||
|
||||
func (s *Service) GetDeviceStatistics(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")
|
||||
}
|
||||
|
||||
deviceStats, err := s.dal.StatisticsRepo.GetDeviceStatistics(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(deviceStats)
|
||||
}
|
Loading…
Reference in New Issue
Block a user