feat: closes #18 added the code to generate models and other
This commit is contained in:
58
logic/models/train/reset.go
Normal file
58
logic/models/train/reset.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package models_train
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
. "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(w http.ResponseWriter, r *http.Request, c *Context) *Error {
|
||||
if !CheckAuthLevel(1, w, r, c) {
|
||||
return nil
|
||||
}
|
||||
if c.Mode == JSON {
|
||||
panic("handle JSON /models/train/reset")
|
||||
}
|
||||
|
||||
f, err := MyParseForm(r)
|
||||
if err != nil {
|
||||
// TODO improve response
|
||||
return ErrorCode(nil, 400, c.AddMap(nil))
|
||||
}
|
||||
|
||||
if !CheckId(f, "id") {
|
||||
// TODO improve response
|
||||
return ErrorCode(nil, 400, c.AddMap(nil))
|
||||
}
|
||||
|
||||
id := f.Get("id")
|
||||
|
||||
model, err := GetBaseModel(handle.Db, id)
|
||||
if err == ModelNotFoundError {
|
||||
return ErrorCode(nil, http.StatusNotFound, AnyMap{
|
||||
"NotFoundMessage": "Model not found",
|
||||
"GoBackLink": "/models",
|
||||
})
|
||||
} else if err != nil {
|
||||
// TODO improve response
|
||||
return Error500(err)
|
||||
}
|
||||
|
||||
if model.Status != FAILED_PREPARING_TRAINING {
|
||||
// TODO improve response
|
||||
return ErrorCode(nil, 400, c.AddMap(nil))
|
||||
}
|
||||
|
||||
_, err = handle.Db.Exec("delete from model_definition where model_id=$1", model.Id)
|
||||
if err != nil {
|
||||
// TODO improve response
|
||||
return Error500(err)
|
||||
}
|
||||
|
||||
ModelUpdateStatus(handle, model.Id, CONFIRM_PRE_TRAINING)
|
||||
Redirect("/models/edit?id=" + model.Id, c.Mode, w, r)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user