adjust api get all project flock kandang with periode

This commit is contained in:
giovanni
2026-04-10 14:09:31 +07:00
parent ddcf13e2ff
commit 3d75251c96
5 changed files with 210 additions and 24 deletions
@@ -24,22 +24,49 @@ func NewProjectFlockKandangController(projectFlockKandangService service.Project
func (u *ProjectFlockKandangController) GetAll(c *fiber.Ctx) error {
query := &validation.Query{
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: c.Query("search", ""),
ProjectFlockId: uint(c.QueryInt("project_flock_id", 0)),
KandangId: uint(c.QueryInt("kandang_id", 0)),
Category: c.Query("category", ""),
AreaId: uint(c.QueryInt("area_id", 0)),
SortBy: c.Query("sort_by", ""),
SortOrder: c.Query("sort_order", ""),
StepName: c.Query("step_name", ""),
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: c.Query("search", ""),
NameWithPeriode: c.QueryBool("name_with_periode", false),
ProjectFlockId: uint(c.QueryInt("project_flock_id", 0)),
KandangId: uint(c.QueryInt("kandang_id", 0)),
Category: c.Query("category", ""),
AreaId: uint(c.QueryInt("area_id", 0)),
SortBy: c.Query("sort_by", ""),
SortOrder: c.Query("sort_order", ""),
StepName: c.Query("step_name", ""),
}
if query.Page < 1 || query.Limit < 1 {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
}
if query.NameWithPeriode {
results, totalResults, err := u.ProjectFlockKandangService.GetAllNameWithPeriode(c, query)
if err != nil {
return err
}
data := make([]dto.ProjectFlockKandangNameWithPeriodDTO, 0, len(results))
for _, result := range results {
data = append(data, dto.ToProjectFlockKandangNameWithPeriodDTOValues(result.Id, result.KandangName, result.Period))
}
return c.Status(fiber.StatusOK).
JSON(response.SuccessWithPaginate[dto.ProjectFlockKandangNameWithPeriodDTO]{
Code: fiber.StatusOK,
Status: "success",
Message: "Get all projectFlockKandangs successfully",
Meta: response.Meta{
Page: query.Page,
Limit: query.Limit,
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
TotalResults: totalResults,
},
Data: data,
})
}
results, totalResults, err := u.ProjectFlockKandangService.GetAll(c, query)
if err != nil {
return err