Fix practice completion lookup for progress endpoint.
Prioritize resolving lms_practices.id before falling back to question_set.id to avoid false 404 responses caused by cross-table ID collisions. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c711df68b9
commit
86ab4e53d4
|
|
@ -1547,29 +1547,25 @@ func (h *Handler) CompletePractice(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
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(),
|
||||
})
|
||||
}
|
||||
// Prefer LMS practice ID resolution to avoid accidental collisions with question_set IDs.
|
||||
practice, practiceErr := h.practiceSvc.GetByID(c.Context(), id)
|
||||
var set domain.QuestionSet
|
||||
var setErr error
|
||||
if practiceErr == nil {
|
||||
set, setErr = h.questionsSvc.GetQuestionSetByID(c.Context(), practice.QuestionSetID)
|
||||
} else {
|
||||
// Backward compatibility: also accept question_set.id directly.
|
||||
set, setErr = h.questionsSvc.GetQuestionSetByID(c.Context(), id)
|
||||
}
|
||||
if !isSequenceGatedPractice(set) || !strings.EqualFold(set.Status, "PUBLISHED") {
|
||||
if setErr != nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Practice not found",
|
||||
Error: setErr.Error(),
|
||||
})
|
||||
}
|
||||
if !strings.EqualFold(set.SetType, string(domain.QuestionSetTypePractice)) || !strings.EqualFold(set.Status, "PUBLISHED") {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{Message: "Practice not found"})
|
||||
}
|
||||
|
||||
if err := h.enforcePracticeSequenceForStudent(c, set); err != nil {
|
||||
return c.Status(fiber.StatusForbidden).JSON(domain.ErrorResponse{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user