Allow completion for existing practice sets.

Treat existing PRACTICE sets as completable even when not published, while keeping sequence enforcement only for published practices.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Yared Yemane 2026-05-13 03:43:50 -07:00
parent 86ab4e53d4
commit 4ada908555

View File

@ -1563,16 +1563,19 @@ func (h *Handler) CompletePractice(c *fiber.Ctx) error {
Error: setErr.Error(), Error: setErr.Error(),
}) })
} }
if !strings.EqualFold(set.SetType, string(domain.QuestionSetTypePractice)) || !strings.EqualFold(set.Status, "PUBLISHED") { if !strings.EqualFold(set.SetType, string(domain.QuestionSetTypePractice)) {
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{Message: "Practice not found"}) return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{Message: "Practice not found"})
} }
// Enforce sequential gating only for published practices.
if strings.EqualFold(set.Status, "PUBLISHED") {
if err := h.enforcePracticeSequenceForStudent(c, set); err != nil { if err := h.enforcePracticeSequenceForStudent(c, set); err != nil {
return c.Status(fiber.StatusForbidden).JSON(domain.ErrorResponse{ return c.Status(fiber.StatusForbidden).JSON(domain.ErrorResponse{
Message: "You must complete previous practices first", Message: "You must complete previous practices first",
Error: err.Error(), Error: err.Error(),
}) })
} }
}
if err := h.lmsProgressSvc.CompletePracticeForUser(c.Context(), userID, set.ID); err != nil { if err := h.lmsProgressSvc.CompletePracticeForUser(c.Context(), userID, set.ID); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{ return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{