38 lines
999 B
Go
38 lines
999 B
Go
|
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)
|
||
|
}
|