package controller import ( "strconv" "web-qudo-be/app/module/hero_section/service" "github.com/gofiber/fiber/v2" ) type HeroSectionController struct { Service *service.HeroSectionService } type Controller struct { HeroSection *HeroSectionController } func NewController(service *service.HeroSectionService) *Controller { return &Controller{ HeroSection: &HeroSectionController{ Service: service, }, } } // GET func (c *HeroSectionController) Get(ctx *fiber.Ctx) error { data, err := c.Service.Get(ctx.Context()) if err != nil { return ctx.Status(500).JSON(fiber.Map{ "message": err.Error(), }) } return ctx.JSON(fiber.Map{ "data": data, }) } // CREATE func (c *HeroSectionController) Create(ctx *fiber.Ctx) error { err := c.Service.Create(ctx.Context(), ctx) if err != nil { return ctx.Status(500).JSON(fiber.Map{ "message": err.Error(), }) } return ctx.JSON(fiber.Map{ "message": "Hero section created successfully", }) } // UPDATE func (c *HeroSectionController) Update(ctx *fiber.Ctx) error { id, err := strconv.Atoi(ctx.Params("id")) if err != nil { return ctx.Status(400).JSON(fiber.Map{ "message": "Invalid ID", }) } err = c.Service.Update(ctx.Context(), id, ctx) if err != nil { return ctx.Status(500).JSON(fiber.Map{ "message": err.Error(), }) } return ctx.JSON(fiber.Map{ "message": "Hero section updated successfully", }) } // DELETE func (c *HeroSectionController) Delete(ctx *fiber.Ctx) error { id, err := strconv.Atoi(ctx.Params("id")) if err != nil { return ctx.Status(400).JSON(fiber.Map{ "message": "Invalid ID", }) } err = c.Service.Delete(ctx.Context(), id) if err != nil { return ctx.Status(500).JSON(fiber.Map{ "message": err.Error(), }) } return ctx.JSON(fiber.Map{ "message": "Hero section deleted successfully", }) }