fix: resolve practice by question set id; set Response flags on question-sets by-owner
- GetSubModulePracticeByID matches sub_module_practices.id or question_set_id - Prefer primary id when both could match (ORDER BY + LIMIT 1) - Set Success/StatusCode on practice GET/detail and GetQuestionSetsByOwner Made-with: Cursor
This commit is contained in:
parent
6839d1aa0d
commit
5fbca53534
|
|
@ -138,8 +138,10 @@ SELECT
|
||||||
(SELECT COUNT(*) FROM question_set_items qsi WHERE qsi.set_id = qs.id) AS question_count
|
(SELECT COUNT(*) FROM question_set_items qsi WHERE qsi.set_id = qs.id) AS question_count
|
||||||
FROM sub_module_practices smp
|
FROM sub_module_practices smp
|
||||||
JOIN question_sets qs ON qs.id = smp.question_set_id
|
JOIN question_sets qs ON qs.id = smp.question_set_id
|
||||||
WHERE smp.id = $1
|
WHERE smp.is_active = TRUE
|
||||||
AND smp.is_active = TRUE;
|
AND (smp.id = $1 OR smp.question_set_id = $1)
|
||||||
|
ORDER BY (smp.id = $1) DESC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
-- name: GetSubModuleCapstones :many
|
-- name: GetSubModuleCapstones :many
|
||||||
SELECT
|
SELECT
|
||||||
|
|
|
||||||
|
|
@ -1609,8 +1609,10 @@ SELECT
|
||||||
(SELECT COUNT(*) FROM question_set_items qsi WHERE qsi.set_id = qs.id) AS question_count
|
(SELECT COUNT(*) FROM question_set_items qsi WHERE qsi.set_id = qs.id) AS question_count
|
||||||
FROM sub_module_practices smp
|
FROM sub_module_practices smp
|
||||||
JOIN question_sets qs ON qs.id = smp.question_set_id
|
JOIN question_sets qs ON qs.id = smp.question_set_id
|
||||||
WHERE smp.id = $1
|
WHERE smp.is_active = TRUE
|
||||||
AND smp.is_active = TRUE
|
AND (smp.id = $1 OR smp.question_set_id = $1)
|
||||||
|
ORDER BY (smp.id = $1) DESC
|
||||||
|
LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetSubModulePracticeByIDRow struct {
|
type GetSubModulePracticeByIDRow struct {
|
||||||
|
|
|
||||||
|
|
@ -2246,11 +2246,11 @@ func (h *Handler) GetSubModulePractices(c *fiber.Ctx) error {
|
||||||
|
|
||||||
// GetSubModulePracticeByID godoc
|
// GetSubModulePracticeByID godoc
|
||||||
// @Summary Get practice detail
|
// @Summary Get practice detail
|
||||||
// @Description Returns one active practice by practice ID
|
// @Description Returns one active practice. practiceId may be sub_module_practices.id or the linked question_sets.id.
|
||||||
// @Tags course-management
|
// @Tags course-management
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param practiceId path int true "Practice ID"
|
// @Param practiceId path int true "Practice row id or question set id"
|
||||||
// @Success 200 {object} domain.Response
|
// @Success 200 {object} domain.Response
|
||||||
// @Failure 400 {object} domain.ErrorResponse
|
// @Failure 400 {object} domain.ErrorResponse
|
||||||
// @Failure 404 {object} domain.ErrorResponse
|
// @Failure 404 {object} domain.ErrorResponse
|
||||||
|
|
@ -2274,17 +2274,19 @@ func (h *Handler) GetSubModulePracticeByID(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(domain.Response{
|
return c.JSON(domain.Response{
|
||||||
Message: "Practice retrieved successfully",
|
Message: "Practice retrieved successfully",
|
||||||
Data: practice,
|
Success: true,
|
||||||
|
StatusCode: fiber.StatusOK,
|
||||||
|
Data: practice,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSubModulePracticeDetail godoc
|
// GetSubModulePracticeDetail godoc
|
||||||
// @Summary Get practice with full question list
|
// @Summary Get practice with full question list
|
||||||
// @Description Returns one active practice with question-set fields and the ordered question list (full item detail)
|
// @Description Returns one active practice with question-set fields and the ordered question list (full item detail). practiceId may be sub_module_practices.id or the linked question_sets.id.
|
||||||
// @Tags course-management
|
// @Tags course-management
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param practiceId path int true "Practice ID (sub_module_practices.id)"
|
// @Param practiceId path int true "Practice row id or question set id"
|
||||||
// @Success 200 {object} domain.Response
|
// @Success 200 {object} domain.Response
|
||||||
// @Failure 400 {object} domain.ErrorResponse
|
// @Failure 400 {object} domain.ErrorResponse
|
||||||
// @Failure 404 {object} domain.ErrorResponse
|
// @Failure 404 {object} domain.ErrorResponse
|
||||||
|
|
@ -2323,7 +2325,9 @@ func (h *Handler) GetSubModulePracticeDetail(c *fiber.Ctx) error {
|
||||||
offset += pageSize
|
offset += pageSize
|
||||||
}
|
}
|
||||||
return c.JSON(domain.Response{
|
return c.JSON(domain.Response{
|
||||||
Message: "Practice retrieved successfully",
|
Message: "Practice retrieved successfully",
|
||||||
|
Success: true,
|
||||||
|
StatusCode: fiber.StatusOK,
|
||||||
Data: map[string]interface{}{
|
Data: map[string]interface{}{
|
||||||
"practice": practice,
|
"practice": practice,
|
||||||
"questions": questionSetItemsToRes(allItems),
|
"questions": questionSetItemsToRes(allItems),
|
||||||
|
|
|
||||||
|
|
@ -908,8 +908,10 @@ func (h *Handler) GetQuestionSetsByOwner(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(domain.Response{
|
return c.JSON(domain.Response{
|
||||||
Message: "Question sets retrieved successfully",
|
Message: "Question sets retrieved successfully",
|
||||||
Data: setResponses,
|
Success: true,
|
||||||
|
StatusCode: fiber.StatusOK,
|
||||||
|
Data: setResponses,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user