Initial alterations for RunHistory

pull/31/head
Frutescens 6 months ago
parent 81b316f4c9
commit 1f05a7bda5

@ -58,6 +58,10 @@ func Init(mux *http.ServeMux) error {
mux.HandleFunc("POST /savedata/clear", legacyHandleSaveData) // TODO use clearSessionData mux.HandleFunc("POST /savedata/clear", legacyHandleSaveData) // TODO use clearSessionData
mux.HandleFunc("GET /savedata/newclear", legacyHandleNewClear) mux.HandleFunc("GET /savedata/newclear", legacyHandleNewClear)
//run history
mux.HandleFunc("GET /savedata/runHistory", handleGetRunHistory)
mux.HandleFunc("POST /savedata/runHistory", handleRunHistory)
// new session // new session
mux.HandleFunc("POST /savedata/updateall", handleUpdateAll) mux.HandleFunc("POST /savedata/updateall", handleUpdateAll)
mux.HandleFunc("POST /savedata/system/verify", handleSystemVerify) mux.HandleFunc("POST /savedata/system/verify", handleSystemVerify)

@ -565,6 +565,51 @@ func legacyHandleSaveData(w http.ResponseWriter, r *http.Request) {
writeJSON(w, r, save) writeJSON(w, r, save)
} }
//functions for run history
func handleGetRunHistory(w http.ResponseWriter, r *http.Request) {
uuid, err := uuidFromRequest(r)
if err != nil {
httpError(w, r, err, http.StatusBadRequest)
return
}
var runHistory any
runHistory, err = savadata.Get(uuid,1);
if errors.Is(err, sql.ErrNoRows) {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
if err != nil {
httpError(w, r, err, http.StatusInternalServerError)
return
}
writeJSON(w, r, runHistory)
}
func handleRunHistory(w http.ResponseWriter, r *http.Request) {
uuid, err := uuidFromRequest(r)
if err != nil {
httpError(w, r, err, http.StatusBadRequest)
return
}
var data string
err = json.NewDecoder(r.Body).Decode(&data)
if err != nil {
httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest)
return
}
err = db.UpdateRunHistory(uuid, data)
if err != nil {
httpError(w, r, err, http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
type CombinedSaveData struct { type CombinedSaveData struct {
System defs.SystemSaveData `json:"system"` System defs.SystemSaveData `json:"system"`
Session defs.SessionSaveData `json:"session"` Session defs.SessionSaveData `json:"session"`

@ -92,6 +92,11 @@ func setupDb(tx *sql.Tx) error {
`ALTER TABLE sessions DROP COLUMN IF EXISTS active`, `ALTER TABLE sessions DROP COLUMN IF EXISTS active`,
`CREATE TABLE IF NOT EXISTS activeClientSessions (uuid BINARY(16) NOT NULL PRIMARY KEY, clientSessionId VARCHAR(32) NOT NULL, FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)`, `CREATE TABLE IF NOT EXISTS activeClientSessions (uuid BINARY(16) NOT NULL PRIMARY KEY, clientSessionId VARCHAR(32) NOT NULL, FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)`,
// ----------------------------------
//Migration 002
`CREATE TABLE IF NOT EXISTS runHistoryData (uuid BINARY(16) PRIMARY KEY, data LONGBLOB, timestamp TIMESTAMP, FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)`,
} }
for _, q := range queries { for _, q := range queries {

Loading…
Cancel
Save