package handlers import ( "strconv" "Yimaru-Backend/internal/domain" "github.com/gofiber/fiber/v2" ) // GetMyLMSProgress godoc // @Summary Get my LMS completion history // @Description Returns completed lesson, module, course, and program IDs for the authenticated user (ordered by completion time, then id). // @Tags lms // @Produce json // @Success 200 {object} domain.Response // @Failure 500 {object} domain.ErrorResponse // @Router /api/v1/lms/progress [get] func (h *Handler) GetMyLMSProgress(c *fiber.Ctx) error { uid := c.Locals("user_id").(int64) prog, err := h.lmsProgressSvc.GetMyProgress(c.Context(), uid) if err != nil { return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{ Message: "Failed to load learning progress", Error: err.Error(), }) } return c.JSON(domain.Response{ Message: "LMS progress retrieved successfully", Data: prog, Success: true, StatusCode: fiber.StatusOK, }) } // AdminGetUserLMSLearningActivity godoc // @Summary Get a user's nested LMS learning activity (admin) // @Description Returns programs, courses, modules, and lessons with completion details and completed practices. Only persisted completion signals are included (completed lessons, completed published practices, and rollup completion timestamps—not partial or in-progress attempts). // @Tags lms // @Produce json // @Security Bearer // @Param user_id path int true "Target user ID" // @Success 200 {object} domain.Response // @Failure 400 {object} domain.ErrorResponse // @Failure 500 {object} domain.ErrorResponse // @Router /api/v1/admin/users/{user_id}/lms-learning-activity [get] func (h *Handler) AdminGetUserLMSLearningActivity(c *fiber.Ctx) error { targetIDStr := c.Params("user_id") targetID, err := strconv.ParseInt(targetIDStr, 10, 64) if err != nil { return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{ Message: "Invalid user ID", Error: err.Error(), }) } if targetID <= 0 { return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{ Message: "Invalid user ID", Error: "user ID must be a positive integer", }) } tree, err := h.lmsProgressSvc.AdminUserLearningActivityTree(c.Context(), targetID) if err != nil { return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{ Message: "Failed to load LMS learning activity", Error: err.Error(), }) } return c.JSON(domain.Response{ Message: "LMS learning activity retrieved successfully", Data: tree, Success: true, StatusCode: fiber.StatusOK, }) }