自动判断content_type
This commit is contained in:
@@ -22,7 +22,6 @@ type CreatePlanRequest struct {
|
||||
ExecutionType models.PlanExecutionType `json:"execution_type" binding:"required" example:"automatic"`
|
||||
ExecuteNum uint `json:"execute_num,omitempty" example:"10"`
|
||||
CronExpression string `json:"cron_expression" example:"0 0 6 * * *"`
|
||||
ContentType models.PlanContentType `json:"content_type" binding:"required" example:"tasks"`
|
||||
SubPlanIDs []uint `json:"sub_plan_ids,omitempty"`
|
||||
Tasks []TaskRequest `json:"tasks,omitempty"`
|
||||
}
|
||||
@@ -55,7 +54,6 @@ type UpdatePlanRequest struct {
|
||||
ExecutionType models.PlanExecutionType `json:"execution_type" example:"automatic"`
|
||||
ExecuteNum uint `json:"execute_num,omitempty" example:"10"`
|
||||
CronExpression string `json:"cron_expression" example:"0 0 6 * * *"`
|
||||
ContentType models.PlanContentType `json:"content_type" example:"tasks"`
|
||||
SubPlanIDs []uint `json:"sub_plan_ids,omitempty"`
|
||||
Tasks []TaskRequest `json:"tasks,omitempty"`
|
||||
}
|
||||
@@ -132,6 +130,14 @@ func (c *Controller) CreatePlan(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// --- 自动判断 ContentType ---
|
||||
if len(req.SubPlanIDs) > 0 {
|
||||
planToCreate.ContentType = models.PlanContentTypeSubPlans
|
||||
} else {
|
||||
// 如果 SubPlanIDs 未提供,则默认为 Tasks 类型(即使 Tasks 字段也未提供)
|
||||
planToCreate.ContentType = models.PlanContentTypeTasks
|
||||
}
|
||||
|
||||
// 调用仓库方法创建计划
|
||||
if err := c.planRepo.CreatePlan(planToCreate); err != nil {
|
||||
controller.SendErrorResponse(ctx, controller.CodeBadRequest, "创建计划失败: "+err.Error())
|
||||
@@ -269,6 +275,14 @@ func (c *Controller) UpdatePlan(ctx *gin.Context) {
|
||||
}
|
||||
planToUpdate.ID = uint(id) // 确保ID被设置
|
||||
|
||||
// --- 自动判断 ContentType ---
|
||||
if len(req.SubPlanIDs) > 0 {
|
||||
planToUpdate.ContentType = models.PlanContentTypeSubPlans
|
||||
} else {
|
||||
// 如果 SubPlanIDs 未提供,则默认为 Tasks 类型(即使 Tasks 字段也未提供)
|
||||
planToUpdate.ContentType = models.PlanContentTypeTasks
|
||||
}
|
||||
|
||||
// 4. 检查计划是否存在
|
||||
_, err = c.planRepo.GetBasicPlanByID(uint(id))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user