重构 #4
| @@ -137,10 +137,10 @@ func (r *gormPlanRepository) CreatePlan(plan *models.Plan) error { | ||||
| 		if plan.ContentType == models.PlanContentTypeSubPlans { | ||||
| 			childIDsToValidate := make(map[uint]bool) | ||||
| 			for _, subPlanLink := range plan.SubPlans { | ||||
| 				if subPlanLink.ChildPlan == nil || subPlanLink.ChildPlan.ID == 0 { | ||||
| 				if subPlanLink.ChildPlanID == 0 { | ||||
| 					return ErrSubPlanIDIsZeroOnCreate | ||||
| 				} | ||||
| 				childIDsToValidate[subPlanLink.ChildPlan.ID] = true | ||||
| 				childIDsToValidate[subPlanLink.ChildPlanID] = true | ||||
| 			} | ||||
|  | ||||
| 			var ids []uint | ||||
|   | ||||
| @@ -1134,7 +1134,7 @@ func TestPlanRepository_Create(t *testing.T) { | ||||
| 				Name:        "父计划", | ||||
| 				ContentType: models.PlanContentTypeSubPlans, | ||||
| 				SubPlans: []models.SubPlan{ | ||||
| 					{ChildPlanID: 1, ExecutionOrder: 1, ChildPlan: &models.Plan{Model: gorm.Model{ID: 1}}}, // 关联已存在的子计划1 | ||||
| 					{ChildPlanID: 1, ExecutionOrder: 1},                                                    // 关联已存在的子计划1 | ||||
| 					{ChildPlanID: 2, ExecutionOrder: 2, ChildPlan: &models.Plan{Model: gorm.Model{ID: 2}}}, // 关联已存在的子计划2 | ||||
| 				}, | ||||
| 			}, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user