package controller import ( "math" "strconv" "gitlab.com/mbugroup/lti-api.git/internal/modules/closings/dto" service "gitlab.com/mbugroup/lti-api.git/internal/modules/closings/services" validation "gitlab.com/mbugroup/lti-api.git/internal/modules/closings/validations" "gitlab.com/mbugroup/lti-api.git/internal/response" "github.com/gofiber/fiber/v2" ) type ClosingController struct { ClosingService service.ClosingService } func NewClosingController(closingService service.ClosingService) *ClosingController { return &ClosingController{ ClosingService: closingService, } } func (u *ClosingController) GetAll(c *fiber.Ctx) error { query := &validation.Query{ Page: c.QueryInt("page", 1), Limit: c.QueryInt("limit", 10), Search: c.Query("search", ""), } if query.Page < 1 || query.Limit < 1 { return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0") } result, totalResults, err := u.ClosingService.GetAll(c, query) if err != nil { return err } return c.Status(fiber.StatusOK). JSON(response.SuccessWithPaginate[dto.ClosingListDTO]{ Code: fiber.StatusOK, Status: "success", Message: "Get all closings successfully", Meta: response.Meta{ Page: query.Page, Limit: query.Limit, TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))), TotalResults: totalResults, }, Data: dto.ToClosingListDTOs(result), }) } func (u *ClosingController) GetClosingSummary(c *fiber.Ctx) error { param := c.Params("projectFlockId") id, err := strconv.Atoi(param) if err != nil || id <= 0 { return fiber.NewError(fiber.StatusBadRequest, "Invalid projectFlockId") } result, err := u.ClosingService.GetClosingSummary(c, uint(id)) if err != nil { return err } return c.Status(fiber.StatusOK). JSON(response.Success{ Code: fiber.StatusOK, Status: "success", Message: "Retrieved project information successfully", Data: result, }) } func (u *ClosingController) GetPenjualan(c *fiber.Ctx) error { param := c.Params("project_flock_id") projectFlockID, err := strconv.Atoi(param) if err != nil { return fiber.NewError(fiber.StatusBadRequest, "Invalid Project Flock Id") } projectFlock, err := u.ClosingService.GetOne(c, uint(projectFlockID)) if err != nil { return err } result, err := u.ClosingService.GetPenjualan(c, uint(projectFlockID)) if err != nil { return err } return c.Status(fiber.StatusOK). JSON(response.Success{ Code: fiber.StatusOK, Status: "success", Message: "Get closing penjualan successfully", Data: dto.ToPenjualanRealisasiResponseDTO(projectFlock.Category, uint(projectFlockID), result), }) }