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
This commit is contained in:
Yared Yemane 2026-04-18 02:54:47 -07:00
parent ce1b827768
commit 24f1aca97a

View File

@ -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"})
}