From 24f1aca97abef1411a7608e71f841e691f2b0a7c Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Sat, 18 Apr 2026 02:54:47 -0700 Subject: [PATCH] fix: return updated lesson from UpdateSubModuleLesson after is_active false GetSubModuleLessonByID filters is_active=true, so refetch failed with 500 after soft-deactivating. Use RETURNING row from the update instead. Made-with: Cursor --- .../web_server/handlers/hierarchy_handler.go | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/internal/web_server/handlers/hierarchy_handler.go b/internal/web_server/handlers/hierarchy_handler.go index 23fc869..26a4468 100644 --- a/internal/web_server/handlers/hierarchy_handler.go +++ b/internal/web_server/handlers/hierarchy_handler.go @@ -35,11 +35,11 @@ type createCourseReq struct { } type updateCourseReq struct { - Title *string `json:"title"` - Description *string `json:"description"` - Thumbnail *string `json:"thumbnail"` + Title *string `json:"title"` + Description *string `json:"description"` + Thumbnail *string `json:"thumbnail"` IntroVideoURL *string `json:"intro_video_url"` - IsActive *bool `json:"is_active"` + IsActive *bool `json:"is_active"` } type updateCourseThumbnailReq struct { @@ -1239,16 +1239,16 @@ func (h *Handler) UnifiedHierarchyByCourse(c *fiber.Ctx) error { Message: "Course hierarchy retrieved successfully", Data: []map[string]interface{}{ { - "course_id": course.ID, - "course_title": course.Title, - "level_id": nil, - "cefr_level": nil, - "level_title": nil, - "level_description": nil, - "level_thumbnail": nil, - "module_id": nil, - "module_title": nil, - "module_icon_url": nil, + "course_id": course.ID, + "course_title": course.Title, + "level_id": nil, + "cefr_level": nil, + "level_title": nil, + "level_description": nil, + "level_thumbnail": nil, + "module_id": nil, + "module_title": nil, + "module_icon_url": nil, "sub_module_id": nil, "sub_module_title": nil, "sub_module_description": nil, @@ -1956,7 +1956,7 @@ func (h *Handler) UpdateSubModuleLesson(c *fiber.Ctx) error { targetIsActive = *req.IsActive } - if _, err := h.analyticsDB.UpdateSubModuleLesson(c.Context(), dbgen.UpdateSubModuleLessonParams{ + updatedLesson, err := h.analyticsDB.UpdateSubModuleLesson(c.Context(), dbgen.UpdateSubModuleLessonParams{ SubModuleID: targetSubModuleID, Title: targetTitle, Description: targetDescription, @@ -1968,17 +1968,10 @@ func (h *Handler) UpdateSubModuleLesson(c *fiber.Ctx) error { DisplayOrder: targetDisplayOrder, IsActive: targetIsActive, ID: lessonID, - }); err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{ - Message: "Failed to update lesson", - Error: err.Error(), - }) - } - - updatedLesson, err := h.analyticsDB.GetSubModuleLessonByID(c.Context(), lessonID) + }) if err != nil { return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{ - Message: "Lesson updated but failed to fetch latest detail", + Message: "Failed to update lesson", Error: err.Error(), }) } @@ -2989,4 +2982,3 @@ func (h *Handler) DeleteModuleCapstone(c *fiber.Ctx) error { } return c.JSON(domain.Response{Message: "Module capstone deleted"}) } -