2023-09-22 19:22:36 +01:00
|
|
|
package model_classes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-04-14 15:19:32 +01:00
|
|
|
|
2024-04-17 17:46:43 +01:00
|
|
|
"git.andr3h3nriqu3s.com/andr3/fyp/logic/db"
|
2024-04-14 15:19:32 +01:00
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
|
2023-09-22 19:22:36 +01:00
|
|
|
)
|
|
|
|
|
2023-10-02 21:15:31 +01:00
|
|
|
var FailedToGetIdAfterInsertError = errors.New("Failed to Get Id After Insert Error")
|
|
|
|
|
2024-04-17 17:46:43 +01:00
|
|
|
func AddDataPoint(db db.Db, class_id string, file_path string, mode DATA_POINT_MODE) (id string, err error) {
|
2023-10-10 12:28:49 +01:00
|
|
|
id = ""
|
|
|
|
result, err := db.Query("insert into model_data_point (class_id, file_path, model_mode, status) values ($1, $2, $3, 1) returning id;", class_id, file_path, mode)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer result.Close()
|
|
|
|
if !result.Next() {
|
|
|
|
err = FailedToGetIdAfterInsertError
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = result.Scan(&id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-04-17 17:46:43 +01:00
|
|
|
func UpdateDataPointStatus(db db.Db, data_point_id string, status int, message *string) (err error) {
|
2024-04-14 15:19:32 +01:00
|
|
|
_, err = db.Exec("update model_data_point set status=$1, status_message=$2 where id=$3", status, message, data_point_id)
|
|
|
|
return
|
2023-09-22 19:22:36 +01:00
|
|
|
}
|