mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
Feat[BE]: implement max target quantity retrieval for kandangs and update routes
This commit is contained in:
@@ -34,6 +34,7 @@ type TransferLayingService interface {
|
||||
DeleteOne(ctx *fiber.Ctx, id uint) error
|
||||
Approval(ctx *fiber.Ctx, req *validation.Approve) ([]entity.LayingTransfer, error)
|
||||
GetAvailableQtyPerKandang(ctx *fiber.Ctx, projectFlockID uint) (*entity.ProjectFlock, map[uint]float64, error)
|
||||
GetMaxTargetQtyPerKandang(ctx *fiber.Ctx, projectFlockID uint) (map[uint]float64, error)
|
||||
}
|
||||
|
||||
type transferLayingService struct {
|
||||
@@ -888,3 +889,39 @@ func (s *transferLayingService) validateKandangOwnership(
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s transferLayingService) GetMaxTargetQtyPerKandang(c *fiber.Ctx, projectFlockID uint) (map[uint]float64, error) {
|
||||
|
||||
if err := commonSvc.EnsureRelations(c.Context(),
|
||||
commonSvc.RelationCheck{Name: "Project Flock", ID: &projectFlockID, Exists: s.ProjectFlockRepo.IdExists},
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
projectFlockKandangs, err := s.ProjectFlockKandangRepo.GetByProjectFlockID(c.Context(), projectFlockID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
kandangMaxTargetQty := make(map[uint]float64)
|
||||
for _, projectFlockKandang := range projectFlockKandangs {
|
||||
|
||||
capacity := projectFlockKandang.Kandang.Capacity
|
||||
|
||||
availableQty, err := s.ProjectFlockPopulationRepo.GetAvailableQtyByProjectFlockKandangID(
|
||||
c.Context(),
|
||||
projectFlockKandang.Id,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
kandangMaxTargetQty[projectFlockKandang.Id] = capacity - availableQty
|
||||
|
||||
if kandangMaxTargetQty[projectFlockKandang.Id] < 0 {
|
||||
kandangMaxTargetQty[projectFlockKandang.Id] = 0
|
||||
}
|
||||
}
|
||||
|
||||
return kandangMaxTargetQty, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user