2023-09-21 16:43:11 +01:00
|
|
|
package models
|
|
|
|
|
2023-09-22 19:22:36 +01:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2023-09-21 16:43:11 +01:00
|
|
|
type BaseModel struct {
|
|
|
|
Name string
|
|
|
|
Status int
|
|
|
|
Id string
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2023-09-22 19:22:36 +01:00
|
|
|
FAILED_PREPARING_ZIP_FILE = -2
|
2023-09-21 16:43:11 +01:00
|
|
|
FAILED_PREPARING = -1
|
|
|
|
|
2023-09-22 19:22:36 +01:00
|
|
|
PREPARING = 1
|
|
|
|
CONFIRM_PRE_TRAINING = 2
|
|
|
|
PREPARING_ZIP_FILE = 3
|
2023-09-21 16:43:11 +01:00
|
|
|
)
|
2023-09-22 19:22:36 +01:00
|
|
|
|
|
|
|
var ModelNotFoundError = errors.New("Model not found error")
|
|
|
|
|
|
|
|
func getBaseModel(db *sql.DB, id string) (base *BaseModel, err error) {
|
|
|
|
rows, err := db.Query("select name, status, id from models where id=$1;", id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
if !rows.Next() {
|
|
|
|
return nil, ModelNotFoundError
|
|
|
|
}
|
|
|
|
|
|
|
|
base = &BaseModel{}
|
|
|
|
err = rows.Scan(&base.Name, &base.Status, &base.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|