From 3a162972ba2dfbb85ff882dc6ca073a356a729e3 Mon Sep 17 00:00:00 2001 From: ragilap Date: Fri, 24 Oct 2025 12:46:43 +0700 Subject: [PATCH] feat/BE/US-76/TASK-122,133,121,120 Recording add create delete edit --- .../controllers/recording.controller.go | 23 +++++++++++++++++++ .../modules/production/recordings/route.go | 1 + .../recordings/services/recording.service.go | 16 +++++++++++++ 3 files changed, 40 insertions(+) diff --git a/internal/modules/production/recordings/controllers/recording.controller.go b/internal/modules/production/recordings/controllers/recording.controller.go index 47f82068..a924eb18 100644 --- a/internal/modules/production/recordings/controllers/recording.controller.go +++ b/internal/modules/production/recordings/controllers/recording.controller.go @@ -75,6 +75,29 @@ func (u *RecordingController) GetOne(c *fiber.Ctx) error { }) } +func (u *RecordingController) GetNextDay(c *fiber.Ctx) error { + projectFlockID := c.QueryInt("project_flock_kandang_id", 0) + if projectFlockID <= 0 { + return fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required") + } + + nextDay, err := u.RecordingService.GetNextDay(c, uint(projectFlockID)) + if err != nil { + return err + } + + return c.Status(fiber.StatusOK). + JSON(response.Success{ + Code: fiber.StatusOK, + Status: "success", + Message: "Get next recording day successfully", + Data: fiber.Map{ + "project_flock_kandang_id": projectFlockID, + "next_day": nextDay, + }, + }) +} + func (u *RecordingController) CreateOne(c *fiber.Ctx) error { req := new(validation.Create) diff --git a/internal/modules/production/recordings/route.go b/internal/modules/production/recordings/route.go index 6852a1ba..3af2b9cf 100644 --- a/internal/modules/production/recordings/route.go +++ b/internal/modules/production/recordings/route.go @@ -21,6 +21,7 @@ func RecordingRoutes(v1 fiber.Router, u user.UserService, s recording.RecordingS // route.Delete("/:id", m.Auth(u), ctrl.DeleteOne) route.Get("/", ctrl.GetAll) + route.Get("/next-day", ctrl.GetNextDay) route.Post("/", ctrl.CreateOne) route.Get("/:id", ctrl.GetOne) route.Patch("/:id", ctrl.UpdateOne) diff --git a/internal/modules/production/recordings/services/recording.service.go b/internal/modules/production/recordings/services/recording.service.go index 6deea620..46ba36cc 100644 --- a/internal/modules/production/recordings/services/recording.service.go +++ b/internal/modules/production/recordings/services/recording.service.go @@ -24,6 +24,7 @@ import ( type RecordingService interface { GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.Recording, int64, error) GetOne(ctx *fiber.Ctx, id uint) (*entity.Recording, error) + GetNextDay(ctx *fiber.Ctx, projectFlockKandangId uint) (int, error) CreateOne(ctx *fiber.Ctx, req *validation.Create) (*entity.Recording, error) UpdateOne(ctx *fiber.Ctx, req *validation.Update, id uint) (*entity.Recording, error) DeleteOne(ctx *fiber.Ctx, id uint) error @@ -104,6 +105,21 @@ func (s recordingService) GetOne(c *fiber.Ctx, id uint) (*entity.Recording, erro return recording, nil } +func (s recordingService) GetNextDay(c *fiber.Ctx, projectFlockKandangId uint) (int, error) { + if projectFlockKandangId == 0 { + return 0, fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required") + } + + db := s.Repository.DB().WithContext(c.Context()) + next, err := s.generateNextDay(db, projectFlockKandangId) + if err != nil { + s.Log.Errorf("Failed to compute next recording day for project_flock_kandang_id=%d: %+v", projectFlockKandangId, err) + return 0, err + } + + return next, nil +} + func (s *recordingService) CreateOne(c *fiber.Ctx, req *validation.Create) (*entity.Recording, error) { if err := s.Validate.Struct(req); err != nil { return nil, err