2024-02-19 17:48:04 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
2024-06-12 13:27:42 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/core/brokers"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/core/clients/auth"
|
2024-06-30 18:02:23 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/core/clients/telegram"
|
2024-02-19 17:48:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Service is an entity for http requests handling
|
|
|
|
type Service struct {
|
2024-06-30 18:02:23 +00:00
|
|
|
dal *dal.DAL
|
|
|
|
authClient *auth.AuthClient
|
|
|
|
producer *brokers.Producer
|
|
|
|
serviceName string
|
|
|
|
chDAL *dal.ClickHouseDAL
|
|
|
|
telegramClient *telegram.TelegramClient
|
2024-02-19 17:48:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-22 12:42:52 +00:00
|
|
|
type Deps struct {
|
2024-06-30 18:02:23 +00:00
|
|
|
Dal *dal.DAL
|
|
|
|
AuthClient *auth.AuthClient
|
|
|
|
Producer *brokers.Producer
|
|
|
|
ServiceName string
|
|
|
|
ChDAL *dal.ClickHouseDAL
|
|
|
|
TelegramClient *telegram.TelegramClient
|
2024-03-22 12:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(deps Deps) *Service {
|
2024-04-16 08:56:47 +00:00
|
|
|
return &Service{
|
2024-06-30 18:02:23 +00:00
|
|
|
dal: deps.Dal,
|
|
|
|
authClient: deps.AuthClient,
|
|
|
|
producer: deps.Producer,
|
|
|
|
serviceName: deps.ServiceName,
|
|
|
|
chDAL: deps.ChDAL,
|
|
|
|
telegramClient: deps.TelegramClient,
|
2024-04-16 08:56:47 +00:00
|
|
|
}
|
2024-02-19 17:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Register is a function for add handlers of service to external multiplexer
|
|
|
|
func (s *Service) Register(app *fiber.App) {
|
|
|
|
// quiz manipulating handlers
|
|
|
|
app.Post("/quiz/create", s.CreateQuiz)
|
|
|
|
app.Post("/quiz/getList", s.GetQuizList)
|
|
|
|
app.Patch("/quiz/edit", s.UpdateQuiz)
|
|
|
|
app.Post("/quiz/copy", s.CopyQuiz)
|
|
|
|
app.Post("/quiz/history", s.GetQuizHistory)
|
|
|
|
app.Delete("/quiz/delete", s.DeleteQuiz)
|
|
|
|
app.Patch("/quiz/archive", s.ArchiveQuiz)
|
2024-03-19 17:29:34 +00:00
|
|
|
app.Post("/quiz/move", s.QuizMove)
|
2024-05-13 11:15:06 +00:00
|
|
|
app.Post("/quiz/template", s.TemplateCopy)
|
2024-02-19 17:48:04 +00:00
|
|
|
|
|
|
|
// question manipulating handlers
|
|
|
|
app.Post("/question/create", s.CreateQuestion)
|
|
|
|
app.Post("/question/getList", s.GetQuestionList)
|
|
|
|
app.Patch("/question/edit", s.UpdateQuestion)
|
|
|
|
app.Post("/question/copy", s.CopyQuestion)
|
|
|
|
app.Post("/question/history", s.GetQuestionHistory)
|
|
|
|
app.Delete("/question/delete", s.DeleteQuestion)
|
|
|
|
|
|
|
|
// account handlers
|
|
|
|
app.Get("/account/get", s.getCurrentAccount)
|
|
|
|
app.Post("/account/create", s.createAccount)
|
|
|
|
app.Delete("/account/delete", s.deleteAccount)
|
|
|
|
app.Get("/accounts", s.getAccounts)
|
|
|
|
app.Get("/privilege/:userId", s.getPrivilegeByUserID)
|
|
|
|
app.Delete("/account/:userId", s.deleteAccountByUserID)
|
2024-06-03 13:21:21 +00:00
|
|
|
app.Post("/account/manualdone", s.ManualDone)
|
2024-06-10 17:15:18 +00:00
|
|
|
app.Post("/account/leadtarget", s.PostLeadTarget)
|
|
|
|
app.Delete("/account/leadtarget/:id", s.DeleteLeadTarget)
|
2024-06-11 15:16:18 +00:00
|
|
|
app.Get("/account/leadtarget/:quizID", s.GetLeadTarget)
|
2024-06-10 17:15:18 +00:00
|
|
|
app.Put("/account/leadtarget", s.UpdateLeadTarget)
|
2024-02-19 17:48:04 +00:00
|
|
|
|
|
|
|
// result handlers
|
|
|
|
app.Post("/results/getResults/:quizId", s.GetResultsByQuizID)
|
|
|
|
app.Delete("/results/delete/:resultId", s.DelResultByID)
|
|
|
|
app.Patch("/result/seen", s.SetStatus)
|
|
|
|
app.Post("/results/:quizID/export", s.ExportResultsToCSV)
|
|
|
|
app.Get("/result/:resultID", s.GetResultAnswers)
|
2024-03-15 13:45:00 +00:00
|
|
|
|
|
|
|
// statistics handlers
|
|
|
|
app.Post("/statistic/:quizID/devices", s.GetDeviceStatistics)
|
2024-03-15 17:44:37 +00:00
|
|
|
app.Post("/statistic/:quizID/general", s.GetGeneralStatistics)
|
2024-03-17 19:44:08 +00:00
|
|
|
app.Post("/statistic/:quizID/questions", s.GetQuestionsStatistics)
|
2024-03-25 09:45:04 +00:00
|
|
|
app.Post("/statistic", s.AllServiceStatistics)
|
2024-06-20 12:46:14 +00:00
|
|
|
app.Get("/statistics/:quizID/pipelines", s.GetPipelinesStatistics)
|
2024-06-27 13:27:16 +00:00
|
|
|
|
|
|
|
//telegram handlers
|
2024-06-30 18:02:23 +00:00
|
|
|
app.Get("/telegram/pool", s.GetPoolTgAccounts)
|
|
|
|
app.Post("/telegram/create", s.AddingTgAccount)
|
|
|
|
app.Delete("/telegram/:id", s.DeleteTgAccountByID)
|
|
|
|
app.Post("/telegram/setCode", s.SettingTgCode)
|
2024-02-19 17:48:04 +00:00
|
|
|
}
|