core/service/service.go

77 lines
2.4 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"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers"
2024-04-16 08:56:47 +00:00
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
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
authClient *auth.AuthClient
producer *brokers.Producer
serviceName string
2024-02-19 17:48:04 +00:00
}
2024-03-22 12:42:52 +00:00
type Deps struct {
Dal *dal.DAL
AuthClient *auth.AuthClient
Producer *brokers.Producer
ServiceName string
2024-03-22 12:42:52 +00:00
}
func New(deps Deps) *Service {
2024-04-16 08:56:47 +00:00
return &Service{
dal: deps.Dal,
authClient: deps.AuthClient,
producer: deps.Producer,
serviceName: deps.ServiceName,
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-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)
// 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-02-19 17:48:04 +00:00
}