mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat[BE]: add flock response to project flock and projectflockkandang getone and getall API
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/services"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/validations"
|
||||
@@ -84,11 +85,20 @@ func (u *ProjectflockController) GetAll(c *fiber.Ctx) error {
|
||||
query.KandangIds = ids
|
||||
}
|
||||
|
||||
result, totalResults, err := u.ProjectflockService.GetAll(c, query)
|
||||
result, totalResults, flockMap, err := u.ProjectflockService.GetAll(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := make([]dto.ProjectFlockListDTO, 0)
|
||||
for _, projectFlock := range result {
|
||||
var flock *flockDTO.FlockBaseDTO
|
||||
if flockMap != nil {
|
||||
flock = flockMap[projectFlock.Id]
|
||||
}
|
||||
data = append(data, dto.ToProjectFlockListDTO(projectFlock, flock))
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[dto.ProjectFlockListDTO]{
|
||||
Code: fiber.StatusOK,
|
||||
@@ -100,7 +110,7 @@ func (u *ProjectflockController) GetAll(c *fiber.Ctx) error {
|
||||
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
|
||||
TotalResults: totalResults,
|
||||
},
|
||||
Data: dto.ToProjectFlockListDTOs(result),
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -112,7 +122,7 @@ func (u *ProjectflockController) GetOne(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
|
||||
}
|
||||
|
||||
result, err := u.ProjectflockService.GetOne(c, uint(id))
|
||||
result, flock, err := u.ProjectflockService.GetOne(c, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -122,7 +132,7 @@ func (u *ProjectflockController) GetOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get projectflock successfully",
|
||||
Data: dto.ToProjectFlockListDTO(*result),
|
||||
Data: dto.ToProjectFlockListDTO(*result, flock),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -143,7 +153,7 @@ func (u *ProjectflockController) CreateOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusCreated,
|
||||
Status: "success",
|
||||
Message: "Create projectflock successfully",
|
||||
Data: dto.ToProjectFlockListDTO(*result),
|
||||
Data: dto.ToProjectFlockListDTO(*result, nil),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -170,7 +180,7 @@ func (u *ProjectflockController) UpdateOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Update projectflock successfully",
|
||||
Data: dto.ToProjectFlockListDTO(*result),
|
||||
Data: dto.ToProjectFlockListDTO(*result, nil),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -210,7 +220,7 @@ func (u *ProjectflockController) Approval(c *fiber.Ctx) error {
|
||||
message = "Submit projectflock approval successfully"
|
||||
)
|
||||
if len(results) == 1 {
|
||||
data = dto.ToProjectFlockListDTO(results[0])
|
||||
data = dto.ToProjectFlockListDTO(results[0], nil)
|
||||
} else {
|
||||
message = "Submit projectflock approvals successfully"
|
||||
data = dto.ToProjectFlockListDTOs(results)
|
||||
|
||||
Reference in New Issue
Block a user