fix
This commit is contained in:
@@ -99,6 +99,53 @@ func (c *ControlCaseController) Launch(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusCreated, controlCase)
|
||||
}
|
||||
|
||||
func (c *ControlCaseController) Restart(ctx *gin.Context) {
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 32)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid ID"})
|
||||
return
|
||||
}
|
||||
|
||||
var controlCase ControlCase
|
||||
if err := c.db.Preload("Params").Preload("Params.InitialCondition").First(&controlCase, id).Error; err != nil {
|
||||
ctx.JSON(http.StatusNotFound, gin.H{"error": "record not found"})
|
||||
return
|
||||
}
|
||||
|
||||
if controlCase.Status == "N" {
|
||||
ctx.JSON(http.StatusConflict, gin.H{"error": "calculation is already queued or running"})
|
||||
return
|
||||
}
|
||||
|
||||
if controlCase.ParamsID == 0 {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "params_id is empty"})
|
||||
return
|
||||
}
|
||||
|
||||
folderPath := filepath.Join(BASE_DIR, fmt.Sprintf("%d", controlCase.ParamsID))
|
||||
if err := os.RemoveAll(folderPath); err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Exec("DELETE FROM analizes WHERE case_id = ?", controlCase.ID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Model(&ControlCase{}).Where("id = ?", controlCase.ID).Update("status", "N").Error
|
||||
}); err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.db.Preload("Params").Preload("Params.InitialCondition").First(&controlCase, controlCase.ID).Error; err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, controlCase)
|
||||
}
|
||||
|
||||
type CSVSeriesResponse struct {
|
||||
Columns []string `json:"columns"`
|
||||
Rows [][]interface{} `json:"rows"`
|
||||
|
||||
Reference in New Issue
Block a user