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
|
||||
FROM sub_module_practices smp
|
||||
JOIN question_sets qs ON qs.id = smp.question_set_id
|
||||
WHERE smp.id = $1
|
||||
AND smp.is_active = TRUE;
|
||||
WHERE 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
|
||||
SELECT
|
||||
|
|
|
|||
|
|
@ -1609,8 +1609,10 @@ SELECT
|
|||
(SELECT COUNT(*) FROM question_set_items qsi WHERE qsi.set_id = qs.id) AS question_count
|
||||
FROM sub_module_practices smp
|
||||
JOIN question_sets qs ON qs.id = smp.question_set_id
|
||||
WHERE smp.id = $1
|
||||
AND smp.is_active = TRUE
|
||||
WHERE 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 {
|
||||
|
|
|
|||
|
|
@ -2246,11 +2246,11 @@ func (h *Handler) GetSubModulePractices(c *fiber.Ctx) error {
|
|||
|
||||
// GetSubModulePracticeByID godoc
|
||||
// @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
|
||||
// @Accept 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
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
|
|
@ -2275,16 +2275,18 @@ func (h *Handler) GetSubModulePracticeByID(c *fiber.Ctx) error {
|
|||
|
||||
return c.JSON(domain.Response{
|
||||
Message: "Practice retrieved successfully",
|
||||
Success: true,
|
||||
StatusCode: fiber.StatusOK,
|
||||
Data: practice,
|
||||
})
|
||||
}
|
||||
|
||||
// GetSubModulePracticeDetail godoc
|
||||
// @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
|
||||
// @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
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
|
|
@ -2324,6 +2326,8 @@ func (h *Handler) GetSubModulePracticeDetail(c *fiber.Ctx) error {
|
|||
}
|
||||
return c.JSON(domain.Response{
|
||||
Message: "Practice retrieved successfully",
|
||||
Success: true,
|
||||
StatusCode: fiber.StatusOK,
|
||||
Data: map[string]interface{}{
|
||||
"practice": practice,
|
||||
"questions": questionSetItemsToRes(allItems),
|
||||
|
|
|
|||
|
|
@ -909,6 +909,8 @@ func (h *Handler) GetQuestionSetsByOwner(c *fiber.Ctx) error {
|
|||
|
||||
return c.JSON(domain.Response{
|
||||
Message: "Question sets retrieved successfully",
|
||||
Success: true,
|
||||
StatusCode: fiber.StatusOK,
|
||||
Data: setResponses,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user