package handlers import ( "Yimaru-Backend/internal/domain" "github.com/gofiber/fiber/v2" ) func (h *Handler) learnerHasSubscriptionCategory(c *fiber.Ctx, category domain.SubscriptionCategory) (bool, error) { userID, ok := c.Locals("user_id").(int64) if !ok || userID == 0 { return false, fiber.NewError(fiber.StatusUnauthorized, "Unauthorized") } return h.subscriptionsSvc.HasActiveSubscriptionByCategory(c.Context(), userID, category) } func (h *Handler) ensureLearnerExamPrepContentAccess(c *fiber.Ctx, contentCategory string, effectiveTier domain.ContentAccessTier) error { role, _ := c.Locals("role").(domain.Role) if !role.IsCustomerLearnerRole() || domain.ExamPrepSubscriptionGateDisabled { return nil } if !domain.IsExamPrepContentCategory(contentCategory) { return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{ Message: "Catalog course not found", }) } return h.ensureLearnerPremiumContentAccess(c, effectiveTier, domain.SubscriptionCategory(contentCategory)) } func (h *Handler) blockLearnerIfNotLMSProgram(c *fiber.Ctx, program domain.Program) error { role, _ := c.Locals("role").(domain.Role) if !role.IsCustomerLearnerRole() { return nil } if !domain.IsLMSContentCategory(program.Category) { return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{ Message: "Program not found", }) } return nil } func humanizeSubscriptionCategory(category domain.SubscriptionCategory) string { switch category { case domain.SubscriptionCategoryLearnEnglish: return "learn english" case domain.SubscriptionCategoryIELTS: return "IELTS" case domain.SubscriptionCategoryDuolingo: return "Duolingo" default: return string(category) } }