core/service/service.go

67 lines
2.2 KiB
Go
Raw Normal View History

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-03-22 12:42:52 +00:00
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
2024-02-19 17:48:04 +00:00
)
// Service is an entity for http requests handling
type Service struct {
2024-03-22 12:42:52 +00:00
dal *dal.DAL
redirectURl string
encrypt *utils.Encrypt
2024-02-19 17:48:04 +00:00
}
2024-03-22 12:42:52 +00:00
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}
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-03-22 12:42:52 +00:00
app.Get("/quiz/logo", s.MiniPart)
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)
// 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)
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-02-19 17:48:04 +00:00
}