90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package service
|
|
|
|
import (
|
|
"gitea.pena/SQuiz/common/dal"
|
|
"gitea.pena/SQuiz/core/brokers"
|
|
"gitea.pena/SQuiz/core/clients/auth"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// Service is an entity for http requests handling
|
|
type Service struct {
|
|
dal *dal.DAL
|
|
authClient *auth.AuthClient
|
|
producer *brokers.Producer
|
|
serviceName string
|
|
chDAL *dal.ClickHouseDAL
|
|
s3Prefix string
|
|
producerGigaChat *brokers.Producer
|
|
}
|
|
|
|
type Deps struct {
|
|
Dal *dal.DAL
|
|
AuthClient *auth.AuthClient
|
|
Producer *brokers.Producer
|
|
ServiceName string
|
|
ChDAL *dal.ClickHouseDAL
|
|
S3Prefix string
|
|
ProducerGigaChat *brokers.Producer
|
|
}
|
|
|
|
func New(deps Deps) *Service {
|
|
return &Service{
|
|
dal: deps.Dal,
|
|
authClient: deps.AuthClient,
|
|
producer: deps.Producer,
|
|
serviceName: deps.ServiceName,
|
|
chDAL: deps.ChDAL,
|
|
s3Prefix: deps.S3Prefix,
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
app.Post("/quiz/move", s.QuizMove)
|
|
app.Post("/quiz/template", s.TemplateCopy)
|
|
|
|
app.Post("/quiz/:quizID/auditory", s.CreateQuizAuditory)
|
|
app.Get("/quiz/:quizID/auditory", s.GetQuizAuditory)
|
|
app.Delete("/quiz/:quizID/auditory", s.DeleteQuizAuditory)
|
|
|
|
// 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)
|
|
app.Post("/account/manualdone", s.ManualDone)
|
|
|
|
// 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)
|
|
|
|
// statistics handlers
|
|
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)
|
|
app.Get("/statistics/:quizID/pipelines", s.GetPipelinesStatistics)
|
|
}
|