mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 07:45:44 +00:00
adjust periode at create project flock
This commit is contained in:
@@ -374,19 +374,32 @@ func (s *projectflockService) CreateOne(c *fiber.Ctx, req *validation.Create) (*
|
||||
err = s.Repository.DB().WithContext(c.Context()).Transaction(func(dbTransaction *gorm.DB) error {
|
||||
projectRepo := repository.NewProjectflockRepository(dbTransaction)
|
||||
|
||||
periods, err := projectRepo.GetNextPeriodsForKandangs(c.Context(), kandangIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
maxPeriod := 1
|
||||
for _, p := range periods {
|
||||
if p > maxPeriod {
|
||||
maxPeriod = p
|
||||
var periods map[uint]int
|
||||
if req.Periode != nil {
|
||||
// Pakai periode yang diminta untuk semua kandang
|
||||
periods = make(map[uint]int, len(kandangIDs))
|
||||
for _, kandangID := range kandangIDs {
|
||||
periods[kandangID] = *req.Periode
|
||||
}
|
||||
} else {
|
||||
periods, err = projectRepo.GetNextPeriodsForKandangs(c.Context(), kandangIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
generatedName, _, err := s.generateSequentialFlockName(c.Context(), projectRepo, canonicalBase, maxPeriod, nil)
|
||||
startPeriod := 1
|
||||
if req.Periode != nil {
|
||||
startPeriod = *req.Periode
|
||||
} else {
|
||||
for _, p := range periods {
|
||||
if p > startPeriod {
|
||||
startPeriod = p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generatedName, _, err := s.generateSequentialFlockName(c.Context(), projectRepo, canonicalBase, startPeriod, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user