feat[BE]: add flock response to project flock and projectflockkandang getone and getall API

This commit is contained in:
aguhh18
2025-11-11 12:16:39 +07:00
parent fd0943dfaf
commit 6b5d27ae8e
7 changed files with 220 additions and 58 deletions
@@ -4,6 +4,7 @@ import (
"math"
"strconv"
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
"gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/dto"
service "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/services"
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/validations"
@@ -40,14 +41,18 @@ func (u *ProjectFlockKandangController) GetAll(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
}
results, totalResults, err := u.ProjectFlockKandangService.GetAll(c, query)
results, totalResults, flockMap, err := u.ProjectFlockKandangService.GetAll(c, query)
if err != nil {
return err
}
data := make([]dto.ProjectFlockKandangListDTO, 0)
for _, result := range results {
data = append(data, dto.ToProjectFlockKandangListDTO(result))
var flock *flockDTO.FlockBaseDTO
if flockMap != nil {
flock = flockMap[result.ProjectFlock.Id]
}
data = append(data, dto.ToProjectFlockKandangListDTOWithFlock(result, flock))
}
return c.Status(fiber.StatusOK).
@@ -73,7 +78,7 @@ func (u *ProjectFlockKandangController) GetOne(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
}
result, availableQtys, productWarehouses, err := u.ProjectFlockKandangService.GetOne(c, uint(id))
result, availableQtys, productWarehouses, flock, err := u.ProjectFlockKandangService.GetOne(c, uint(id))
if err != nil {
return err
}
@@ -83,6 +88,6 @@ func (u *ProjectFlockKandangController) GetOne(c *fiber.Ctx) error {
Code: fiber.StatusOK,
Status: "success",
Message: "Get projectFlockKandang successfully",
Data: dto.ToProjectFlockKandangDetailDTOWithAvailableQty(*result, availableQtys, productWarehouses),
Data: dto.ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(*result, availableQtys, productWarehouses, flock),
})
}