mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +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
|
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)
|
latestApproval := defaultProjectFlockLatestApproval(e)
|
||||||
if e.LatestApproval != nil {
|
if e.LatestApproval != nil {
|
||||||
snapshot := approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
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 {
|
err = s.Repository.DB().WithContext(c.Context()).Transaction(func(dbTransaction *gorm.DB) error {
|
||||||
projectRepo := repository.NewProjectflockRepository(dbTransaction)
|
projectRepo := repository.NewProjectflockRepository(dbTransaction)
|
||||||
|
|
||||||
periods, err := projectRepo.GetNextPeriodsForKandangs(c.Context(), kandangIDs)
|
var periods map[uint]int
|
||||||
if err != nil {
|
if req.Periode != nil {
|
||||||
return err
|
// Pakai periode yang diminta untuk semua kandang
|
||||||
}
|
periods = make(map[uint]int, len(kandangIDs))
|
||||||
|
for _, kandangID := range kandangIDs {
|
||||||
maxPeriod := 1
|
periods[kandangID] = *req.Periode
|
||||||
for _, p := range periods {
|
}
|
||||||
if p > maxPeriod {
|
} else {
|
||||||
maxPeriod = p
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ type Create struct {
|
|||||||
Category string `json:"category" validate:"required_strict"`
|
Category string `json:"category" validate:"required_strict"`
|
||||||
ProductionStandardId uint `json:"production_standard_id" validate:"required_strict,number,gt=0"`
|
ProductionStandardId uint `json:"production_standard_id" validate:"required_strict,number,gt=0"`
|
||||||
LocationId uint `json:"location_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"`
|
KandangIds []uint `json:"kandang_ids" validate:"required,min=1,dive,gt=0"`
|
||||||
ProjectBudgets []ProjectBudget `json:"project_budgets" validate:"required,min=1,dive"`
|
ProjectBudgets []ProjectBudget `json:"project_budgets" validate:"required,min=1,dive"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user