From 8a403e803c5c3d67557a7665372bc2afd8fb7a36 Mon Sep 17 00:00:00 2001 From: giovanni Date: Fri, 30 Jan 2026 14:47:13 +0700 Subject: [PATCH 1/2] fix filter by kandang --- .../modules/closings/services/closing.service.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/modules/closings/services/closing.service.go b/internal/modules/closings/services/closing.service.go index a3cfb2cc..923a2b1c 100644 --- a/internal/modules/closings/services/closing.service.go +++ b/internal/modules/closings/services/closing.service.go @@ -367,7 +367,7 @@ func (s closingService) GetClosingSapronak(c *fiber.Ctx, projectFlockID uint, pa return nil, 0, fiber.NewError(fiber.StatusBadRequest, "type must be either incoming or outgoing") } - warehouseIDs, err := s.getWarehouseIDsByProjectFlock(c.Context(), projectFlockID) + warehouseIDs, err := s.getWarehouseIDsByProjectFlock(c.Context(), projectFlockID, params.KandangID) if err != nil { s.Log.Errorf("Failed to fetch warehouses for project flock %d: %+v", projectFlockID, err) return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch warehouses for project flock") @@ -451,7 +451,7 @@ func (s closingService) GetClosingSapronakSummary(c *fiber.Ctx, projectFlockID u return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock") } - warehouseIDs, err := s.getWarehouseIDsByProjectFlock(c.Context(), projectFlockID) + warehouseIDs, err := s.getWarehouseIDsByProjectFlock(c.Context(), projectFlockID, params.KandangID) if err != nil { s.Log.Errorf("Failed to fetch warehouses for project flock %d: %+v", projectFlockID, err) return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch warehouses for project flock") @@ -494,13 +494,16 @@ func (s closingService) GetClosingSapronakSummary(c *fiber.Ctx, projectFlockID u return items, nil } -func (s closingService) getWarehouseIDsByProjectFlock(ctx context.Context, projectFlockID uint) ([]uint, error) { +func (s closingService) getWarehouseIDsByProjectFlock(ctx context.Context, projectFlockID uint, kandangID *uint) ([]uint, error) { var kandangIDs []uint db := s.Repository.DB().WithContext(ctx) - if err := db.Model(&entity.ProjectFlockKandang{}). - Where("project_flock_id = ?", projectFlockID). - Pluck("kandang_id", &kandangIDs).Error; err != nil { + query := db.Model(&entity.ProjectFlockKandang{}). + Where("project_flock_id = ?", projectFlockID) + if kandangID != nil && *kandangID > 0 { + query = query.Where("id = ?", *kandangID) + } + if err := query.Pluck("kandang_id", &kandangIDs).Error; err != nil { return nil, err } From c257a2cb287fb5d40b28e04debb8313c9335bd42 Mon Sep 17 00:00:00 2001 From: giovanni Date: Fri, 30 Jan 2026 15:09:23 +0700 Subject: [PATCH 2/2] add validation max size upload file 5 MB --- .../controllers/daily-checklist.controller.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/modules/daily-checklists/controllers/daily-checklist.controller.go b/internal/modules/daily-checklists/controllers/daily-checklist.controller.go index d97424fa..95848839 100644 --- a/internal/modules/daily-checklists/controllers/daily-checklist.controller.go +++ b/internal/modules/daily-checklists/controllers/daily-checklist.controller.go @@ -2,6 +2,7 @@ package controller import ( "math" + "mime/multipart" "strconv" "gitlab.com/mbugroup/lti-api.git/internal/modules/daily-checklists/dto" @@ -362,6 +363,9 @@ func (u *DailyChecklistController) UpdateOne(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, "Invalid multipart form") } req.Documents = form.File["documents"] + if err := validateDailyChecklistDocumentSizes(req.Documents); err != nil { + return err + } if err := c.BodyParser(req); err != nil { return fiber.NewError(fiber.StatusBadRequest, "Invalid request body") @@ -381,6 +385,16 @@ func (u *DailyChecklistController) UpdateOne(c *fiber.Ctx) error { }) } +func validateDailyChecklistDocumentSizes(files []*multipart.FileHeader) error { + const maxDailyChecklistDocumentBytes = 5 * 1024 * 1024 // 5MB + for _, file := range files { + if file != nil && file.Size > maxDailyChecklistDocumentBytes { + return fiber.NewError(fiber.StatusRequestEntityTooLarge, "Document size must be <= 5MB") + } + } + return nil +} + func (u *DailyChecklistController) DeleteOne(c *fiber.Ctx) error { param := c.Params("idDailyChecklist")