mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
Merge branch 'fix/create-flock' into 'development'
[FEAT][BE]: adjust periode at create project flock See merge request mbugroup/lti-api!490
This commit is contained in:
@@ -120,6 +120,11 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF
|
||||
locationSummary = &mapped
|
||||
}
|
||||
|
||||
// Jika period tidak di-pass secara eksplisit (0), derive dari KandangHistory
|
||||
if period == 0 && len(e.KandangHistory) > 0 {
|
||||
period = e.KandangHistory[0].Period
|
||||
}
|
||||
|
||||
latestApproval := defaultProjectFlockLatestApproval(e)
|
||||
if e.LatestApproval != nil {
|
||||
snapshot := approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ type Create struct {
|
||||
Category string `json:"category" validate:"required_strict"`
|
||||
ProductionStandardId uint `json:"production_standard_id" validate:"required_strict,number,gt=0"`
|
||||
LocationId uint `json:"location_id" validate:"required_strict,number,gt=0"`
|
||||
Periode *int `json:"periode" validate:"omitempty,gt=0"`
|
||||
KandangIds []uint `json:"kandang_ids" validate:"required,min=1,dive,gt=0"`
|
||||
ProjectBudgets []ProjectBudget `json:"project_budgets" validate:"required,min=1,dive"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user