first commit api production-result

This commit is contained in:
MacBook Air M1
2026-01-02 11:24:26 +07:00
parent 10f42ed9c4
commit 39909d1c2e
8 changed files with 523 additions and 3 deletions
@@ -2,6 +2,7 @@ package controller
import (
"math"
"strconv"
"gitlab.com/mbugroup/lti-api.git/internal/modules/repports/dto"
service "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/services"
@@ -95,8 +96,6 @@ func (c *RepportController) GetMarketing(ctx *fiber.Ctx) error {
if err != nil {
return err
}
total := dto.ToSummaryFromDTOItems(result)
return ctx.Status(fiber.StatusOK).
@@ -187,3 +186,44 @@ func (c *RepportController) GetHppPerKandang(ctx *fiber.Ctx) error {
return ctx.Status(fiber.StatusOK).JSON(resp)
}
func (c *RepportController) GetProductionResult(ctx *fiber.Ctx) error {
idParam := ctx.Params("idProjectFlockKandang")
if idParam == "" {
return fiber.NewError(fiber.StatusBadRequest, "idProjectFlockKandang is required")
}
projectFlockKandangID, err := strconv.ParseUint(idParam, 10, 64)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "invalid idProjectFlockKandang")
}
query := &validation.ProductionResultQuery{
Page: ctx.QueryInt("page", 1),
Limit: ctx.QueryInt("limit", 10),
ProjectFlockKandangID: uint(projectFlockKandangID),
}
if query.Page < 1 || query.Limit < 1 {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
}
data, totalResults, err := c.RepportService.GetProductionResult(ctx, query)
if err != nil {
return err
}
return ctx.Status(fiber.StatusOK).
JSON(response.SuccessWithPaginate[dto.ProductionResultDTO]{
Code: fiber.StatusOK,
Status: "success",
Message: "Get Laporan Hasil Produksi successfully",
Meta: response.Meta{
Page: query.Page,
Limit: query.Limit,
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
TotalResults: totalResults,
},
Data: data,
})
}