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
@@ -26,6 +26,7 @@ import (
type ProjectFlockKandangService interface {
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, error)
GetAllNameWithPeriode(ctx *fiber.Ctx, params *validation.Query) ([]ProjectFlockKandangNameWithPeriode, int64, error)
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, error)
CheckClosing(ctx *fiber.Ctx, id uint) (*ClosingCheckResult, error)
Closing(ctx *fiber.Ctx, id uint, req *validation.Closing) (*entity.ProjectFlockKandang, error)
@@ -51,6 +52,12 @@ type ClosingCheckResult struct {
Expenses []ExpenseSummary `json:"expenses"`
}
type ProjectFlockKandangNameWithPeriode struct {
Id uint
KandangName string
Period int
}
type StockRemainingDetail struct {
FlagName string `json:"flag_name"`
ProductWarehouseId uint `json:"product_warehouse_id"`
@@ -133,6 +140,36 @@ func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Quer
return projectFlockKandangs, total, nil
}
func (s projectFlockKandangService) GetAllNameWithPeriode(c *fiber.Ctx, params *validation.Query) ([]ProjectFlockKandangNameWithPeriode, int64, error) {
if err := s.Validate.Struct(params); err != nil {
return nil, 0, err
}
scope, err := m.ResolveLocationScope(c, s.Repository.DB())
if err != nil {
return nil, 0, err
}
offset := (params.Page - 1) * params.Limit
rows, total, err := s.Repository.GetAllNameWithPeriodeScoped(c.Context(), offset, params.Limit, params, scope.IDs, scope.Restrict)
if err != nil {
s.Log.Errorf("Failed to get projectFlockKandangs name_with_periode: %+v", err)
return nil, 0, err
}
results := make([]ProjectFlockKandangNameWithPeriode, 0, len(rows))
for _, row := range rows {
results = append(results, ProjectFlockKandangNameWithPeriode{
Id: row.Id,
KandangName: row.KandangName,
Period: row.Period,
})
}
return results, total, nil
}
func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, error) {
scope, err := m.ResolveLocationScope(c, s.Repository.DB())
if err != nil {