package handlers import ( "Rezina-Backend/internal/domain" "github.com/gofiber/fiber/v2" ) // GetChapterQuiz godoc // @Summary Get a chapter quiz // @Description Returns a quiz shell. Learners only see published quizzes with a published question set in a published chapter and course. // @Tags quizzes // @Security Bearer // @Produce json // @Param id path int true "Quiz shell ID" // @Success 200 {object} domain.Response{data=domain.ExamPrepPractice} // @Failure 400 {object} domain.ErrorResponse "Invalid request" // @Failure 401 {object} domain.ErrorResponse "Missing or invalid access token" // @Failure 403 {object} domain.ErrorResponse "Permission, subscription, or sequence access denied" // @Failure 404 {object} domain.ErrorResponse "Quiz or published parent not found" // @Failure 500 {object} domain.ErrorResponse "Internal error" // @Router /api/v1/admin/quizzes/{id} [get] // @Router /api/v1/quizzes/{id} [get] func (h *Handler) GetChapterQuiz(c *fiber.Ctx) error { return h.GetExamPrepPracticeByID(c) } // GetChapterQuizFull godoc // @Summary Get a chapter quiz with questions // @Description Returns quiz metadata in practice, question_set settings, stimulus_blocks, and questions. // @Tags quizzes // @Security Bearer // @Produce json // @Param id path int true "Quiz shell ID" // @Success 200 {object} domain.Response{data=quizFullData} // @Failure 400 {object} domain.ErrorResponse "Invalid request" // @Failure 401 {object} domain.ErrorResponse "Missing or invalid access token" // @Failure 403 {object} domain.ErrorResponse "Permission, subscription, or sequence access denied" // @Failure 404 {object} domain.ErrorResponse "Quiz or published parent not found" // @Failure 500 {object} domain.ErrorResponse "Internal error" // @Router /api/v1/admin/quizzes/{id}/full [get] func (h *Handler) GetChapterQuizFull(c *fiber.Ctx) error { return h.GetExamPrepPracticeFull(c) } // UpdateChapterQuiz godoc // @Summary Update a chapter quiz // @Description Updates quiz metadata. A replacement question_set_id must refer to another QUIZ set. Chapter placement is immutable through this endpoint. // @Tags quizzes // @Security Bearer // @Produce json // @Param id path int true "Quiz shell ID" // @Accept json // @Param body body domain.UpdateExamPrepPracticeInput true "Quiz update" // @Success 200 {object} domain.Response{data=domain.ExamPrepPractice} // @Failure 400 {object} domain.ErrorResponse "Invalid request" // @Failure 401 {object} domain.ErrorResponse "Missing or invalid access token" // @Failure 403 {object} domain.ErrorResponse "Permission, subscription, or sequence access denied" // @Failure 404 {object} domain.ErrorResponse "Quiz or published parent not found" // @Failure 500 {object} domain.ErrorResponse "Internal error" // @Router /api/v1/admin/quizzes/{id} [put] func (h *Handler) UpdateChapterQuiz(c *fiber.Ctx) error { return h.UpdateExamPrepPractice(c) } // UpdateChapterQuizFull godoc // @Summary Update a chapter quiz and its question set // @Description Updates quiz metadata and question set settings. Omit questions to preserve memberships; an explicit empty array removes all memberships. Publish practice.publish_status and question_set.status together. // @Tags quizzes // @Security Bearer // @Produce json // @Param id path int true "Quiz shell ID" // @Accept json // @Param body body domain.FullUpdatePracticeInput true "Quiz update" // @Success 200 {object} domain.Response{data=quizFullData} // @Failure 400 {object} domain.ErrorResponse "Invalid request" // @Failure 401 {object} domain.ErrorResponse "Missing or invalid access token" // @Failure 403 {object} domain.ErrorResponse "Permission, subscription, or sequence access denied" // @Failure 404 {object} domain.ErrorResponse "Quiz or published parent not found" // @Failure 500 {object} domain.ErrorResponse "Internal error" // @Router /api/v1/admin/quizzes/{id}/full [put] func (h *Handler) UpdateChapterQuizFull(c *fiber.Ctx) error { var input domain.FullUpdatePracticeInput if err := c.BodyParser(&input); err != nil { return fiber.NewError(fiber.StatusBadRequest, "Invalid quiz update") } if input.Practice != nil && input.Practice.QuestionSetID != nil { set, err := h.questionsSvc.GetQuestionSetByID(c.Context(), *input.Practice.QuestionSetID) if err != nil { return fiber.NewError(fiber.StatusNotFound, "Question set not found") } if set.SetType != "QUIZ" { return fiber.NewError(fiber.StatusBadRequest, "Chapter quizzes require a QUIZ question set") } } return h.UpdateExamPrepPracticeFull(c) } // DeleteChapterQuiz godoc // @Summary Delete a chapter quiz // @Description Deletes the quiz shell and chapter attachment. The question set and bank questions remain independently managed. // @Tags quizzes // @Security Bearer // @Produce json // @Param id path int true "Quiz shell ID" // @Success 200 {object} MessageResponse // @Failure 400 {object} domain.ErrorResponse "Invalid request" // @Failure 401 {object} domain.ErrorResponse "Missing or invalid access token" // @Failure 403 {object} domain.ErrorResponse "Permission, subscription, or sequence access denied" // @Failure 404 {object} domain.ErrorResponse "Quiz or published parent not found" // @Failure 500 {object} domain.ErrorResponse "Internal error" // @Router /api/v1/admin/quizzes/{id} [delete] func (h *Handler) DeleteChapterQuiz(c *fiber.Ctx) error { return h.DeleteExamPrepPractice(c) } // GetChapterQuizQuestions godoc // @Summary List questions in a chapter quiz // @Description Learner endpoint. Requires a published quiz and question set, accessible chapter, subscription eligibility, and learning sequence access. // @Tags quizzes // @Security Bearer // @Produce json // @Param practiceId path int true "Quiz shell ID" // @Param question_type query string false "Question type filter" // @Param limit query int false "Page size (1-200)" default(10) // @Param offset query int false "Non-negative offset" default(0) // @Success 200 {object} domain.Response{data=paginatedQuestionSetItemsRes} // @Failure 400 {object} domain.ErrorResponse "Invalid request" // @Failure 401 {object} domain.ErrorResponse "Missing or invalid access token" // @Failure 403 {object} domain.ErrorResponse "Permission, subscription, or sequence access denied" // @Failure 404 {object} domain.ErrorResponse "Quiz or published parent not found" // @Failure 500 {object} domain.ErrorResponse "Internal error" // @Router /api/v1/quizzes/{practiceId}/questions [get] func (h *Handler) GetChapterQuizQuestions(c *fiber.Ctx) error { return h.GetQuestionsByPractice(c) } // CompleteChapterQuiz godoc // @Summary Complete a chapter quiz // @Description The id is the quiz shell ID, not question_set_id. The single chapter scope is inferred; optional scope must use CHAPTER and that chapter ID. Records completion for the authenticated learner. // @Tags quizzes // @Security Bearer // @Produce json // @Param id path int true "Quiz shell ID" // @Accept json // @Param body body domain.CompletePracticeInput false "Optional chapter scope" // @Success 200 {object} MessageResponse // @Failure 400 {object} domain.ErrorResponse "Invalid request" // @Failure 401 {object} domain.ErrorResponse "Missing or invalid access token" // @Failure 403 {object} domain.ErrorResponse "Permission, subscription, or sequence access denied" // @Failure 404 {object} domain.ErrorResponse "Quiz or published parent not found" // @Failure 500 {object} domain.ErrorResponse "Internal error" // @Router /api/v1/progress/quizzes/{id}/complete [post] func (h *Handler) CompleteChapterQuiz(c *fiber.Ctx) error { return h.CompletePractice(c) }