mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
add filter by kandang id sapronak
This commit is contained in:
@@ -162,6 +162,14 @@ func (u *ClosingController) GetClosingSapronak(c *fiber.Ctx) error {
|
|||||||
Page: c.QueryInt("page", 1),
|
Page: c.QueryInt("page", 1),
|
||||||
Limit: c.QueryInt("limit", 10),
|
Limit: c.QueryInt("limit", 10),
|
||||||
}
|
}
|
||||||
|
if raw := c.Query("kandang_id"); raw != "" {
|
||||||
|
kandangInt, convErr := strconv.Atoi(raw)
|
||||||
|
if convErr != nil || kandangInt <= 0 {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, "Invalid kandang_id")
|
||||||
|
}
|
||||||
|
kandangUint := uint(kandangInt)
|
||||||
|
query.KandangID = &kandangUint
|
||||||
|
}
|
||||||
|
|
||||||
if query.Page < 1 || query.Limit < 1 {
|
if query.Page < 1 || query.Limit < 1 {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||||
@@ -346,6 +354,7 @@ func (u *ClosingController) GetClosingDataProduksi(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
kandangUint := uint(kandangInt)
|
kandangUint := uint(kandangInt)
|
||||||
kandangID = &kandangUint
|
kandangID = &kandangUint
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := u.ClosingService.GetClosingDataProduksi(c, uint(id), kandangID)
|
result, err := u.ClosingService.GetClosingDataProduksi(c, uint(id), kandangID)
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ func (s closingService) GetClosingSapronak(c *fiber.Ctx, projectFlockID uint, pa
|
|||||||
|
|
||||||
var projectFlockKandangIDs []uint
|
var projectFlockKandangIDs []uint
|
||||||
if params.Type == validation.SapronakTypeOutgoing {
|
if params.Type == validation.SapronakTypeOutgoing {
|
||||||
projectFlockKandangIDs, err = s.getProjectFlockKandangIDs(c.Context(), projectFlockID, nil)
|
projectFlockKandangIDs, err = s.getProjectFlockKandangIDs(c.Context(), projectFlockID, params.KandangID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log.Errorf("Failed to fetch project flock kandang IDs for project flock %d: %+v", projectFlockID, err)
|
s.Log.Errorf("Failed to fetch project flock kandang IDs for project flock %d: %+v", projectFlockID, err)
|
||||||
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandang")
|
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandang")
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ClosingSapronakQuery struct {
|
type ClosingSapronakQuery struct {
|
||||||
Type string `query:"type" validate:"required,oneof=incoming outgoing"`
|
Type string `query:"type" validate:"required,oneof=incoming outgoing"`
|
||||||
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
||||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
||||||
|
KandangID *uint `query:"kandang_id" validate:"omitempty,gt=0"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ func (r *productionResultRepositoryImpl) GetRecordingsByProjectFlockKandang(
|
|||||||
dataQuery := r.db.WithContext(ctx).
|
dataQuery := r.db.WithContext(ctx).
|
||||||
Model(&entity.Recording{}).
|
Model(&entity.Recording{}).
|
||||||
Where("project_flock_kandangs_id = ?", projectFlockKandangID).
|
Where("project_flock_kandangs_id = ?", projectFlockKandangID).
|
||||||
Preload("BodyWeights").
|
|
||||||
Preload("Eggs", func(db *gorm.DB) *gorm.DB {
|
Preload("Eggs", func(db *gorm.DB) *gorm.DB {
|
||||||
return db.Select("recording_eggs.*, f.name AS product_flag_name").
|
return db.Select("recording_eggs.*, f.name AS product_flag_name").
|
||||||
Joins("LEFT JOIN product_warehouses pw ON pw.id = recording_eggs.product_warehouse_id").
|
Joins("LEFT JOIN product_warehouses pw ON pw.id = recording_eggs.product_warehouse_id").
|
||||||
|
|||||||
Reference in New Issue
Block a user