package models_train import ( "os" "path" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils" ) func handleRest(handle *Handle) { handle.Delete("/models/train/reset", func(c *Context) *Error { if !c.CheckAuthLevel(1) { return nil } var dat struct { Id string `json:"id"` } if err := c.ToJSON(&dat); err != nil { return err } model, err := GetBaseModel(c.Db, dat.Id) if err == ModelNotFoundError { return c.JsonBadRequest("Model not found") } else if err != nil { // TODO improve response return c.Error500(err) } if model.Status != FAILED_PREPARING_TRAINING && model.Status != FAILED_TRAINING { return c.JsonBadRequest("Model is not in status that be reset") } os.RemoveAll(path.Join("savedData", model.Id, "defs")) _, err = c.Db.Exec("delete from model_definition where model_id=$1", model.Id) if err != nil { // TODO improve response return c.Error500(err) } ModelUpdateStatus(c, model.Id, CONFIRM_PRE_TRAINING) return c.SendJSON(model.Id) }) }