core/service/service.go
2024-03-25 12:45:04 +03:00

68 lines
2.2 KiB
Go

package service
import (
"github.com/gofiber/fiber/v2"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
)
// Service is an entity for http requests handling
type Service struct {
dal *dal.DAL
redirectURl string
encrypt *utils.Encrypt
}
type Deps struct {
Dal *dal.DAL
RedirectURl string
Encrypt *utils.Encrypt
}
func New(deps Deps) *Service {
return &Service{dal: deps.Dal, redirectURl: deps.RedirectURl, encrypt: deps.Encrypt}
}
// 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.Get("/quiz/logo", s.MiniPart)
// 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)
// 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)
}