diff --git a/db/query/hierarchy.sql b/db/query/hierarchy.sql index 13ec333..2b84005 100644 --- a/db/query/hierarchy.sql +++ b/db/query/hierarchy.sql @@ -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 diff --git a/gen/db/hierarchy.sql.go b/gen/db/hierarchy.sql.go index a25df45..07d955f 100644 --- a/gen/db/hierarchy.sql.go +++ b/gen/db/hierarchy.sql.go @@ -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 { diff --git a/internal/web_server/handlers/hierarchy_handler.go b/internal/web_server/handlers/hierarchy_handler.go index fbb66f8..75de9e6 100644 --- a/internal/web_server/handlers/hierarchy_handler.go +++ b/internal/web_server/handlers/hierarchy_handler.go @@ -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 @@ -2274,17 +2274,19 @@ func (h *Handler) GetSubModulePracticeByID(c *fiber.Ctx) error { } return c.JSON(domain.Response{ - Message: "Practice retrieved successfully", - Data: practice, + 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 @@ -2323,7 +2325,9 @@ func (h *Handler) GetSubModulePracticeDetail(c *fiber.Ctx) error { offset += pageSize } return c.JSON(domain.Response{ - Message: "Practice retrieved successfully", + Message: "Practice retrieved successfully", + Success: true, + StatusCode: fiber.StatusOK, Data: map[string]interface{}{ "practice": practice, "questions": questionSetItemsToRes(allItems), diff --git a/internal/web_server/handlers/questions.go b/internal/web_server/handlers/questions.go index e9cceea..6dc0b3a 100644 --- a/internal/web_server/handlers/questions.go +++ b/internal/web_server/handlers/questions.go @@ -908,8 +908,10 @@ func (h *Handler) GetQuestionSetsByOwner(c *fiber.Ctx) error { } return c.JSON(domain.Response{ - Message: "Question sets retrieved successfully", - Data: setResponses, + Message: "Question sets retrieved successfully", + Success: true, + StatusCode: fiber.StatusOK, + Data: setResponses, }) }