Fix practice completion lookup for progress endpoint.
Accept either question-set IDs or LMS practice IDs and recognize LMS owner types so valid practice completions no longer return practice-not-found responses. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
eae87b40b5
commit
c711df68b9
|
|
@ -731,7 +731,7 @@ func isSequenceGatedPractice(set domain.QuestionSet) bool {
|
|||
return false
|
||||
}
|
||||
ot := strings.ToUpper(strings.TrimSpace(*set.OwnerType))
|
||||
return ot == "SUB_COURSE" || ot == "SUB_MODULE"
|
||||
return ot == "SUB_COURSE" || ot == "SUB_MODULE" || ot == "COURSE" || ot == "MODULE" || ot == "LESSON"
|
||||
}
|
||||
|
||||
func (h *Handler) enforcePracticeSequenceForStudent(c *fiber.Ctx, set domain.QuestionSet) error {
|
||||
|
|
@ -1539,7 +1539,7 @@ func (h *Handler) CompletePractice(c *fiber.Ctx) error {
|
|||
}
|
||||
userID := c.Locals("user_id").(int64)
|
||||
|
||||
setID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
||||
Message: "Invalid practice ID",
|
||||
|
|
@ -1547,13 +1547,24 @@ func (h *Handler) CompletePractice(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
set, err := h.questionsSvc.GetQuestionSetByID(c.Context(), setID)
|
||||
set, err := h.questionsSvc.GetQuestionSetByID(c.Context(), id)
|
||||
if err != nil {
|
||||
// Backward/UX compatibility: accept either question_set.id or lms_practices.id.
|
||||
practice, practiceErr := h.practiceSvc.GetByID(c.Context(), id)
|
||||
if practiceErr != nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Practice not found",
|
||||
Error: err.Error(),
|
||||
})
|
||||
}
|
||||
set, err = h.questionsSvc.GetQuestionSetByID(c.Context(), practice.QuestionSetID)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Practice not found",
|
||||
Error: err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
if !isSequenceGatedPractice(set) || !strings.EqualFold(set.Status, "PUBLISHED") {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Practice not found",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user