diff --git a/documentation/Get_all_readings-1701839548674.txt b/documentation/Get_all_readings-1701839548674.txt deleted file mode 100644 index 29cabb7..0000000 --- a/documentation/Get_all_readings-1701839548674.txt +++ /dev/null @@ -1,13 +0,0 @@ -HTTP/2 500 -date: Wed, 06 Dec 2023 05:11:59 GMT -content-type: text/plain; charset=utf-8 -cf-ray: 831207fd8bbff8f9-NVT -cf-cache-status: DYNAMIC -vary: Accept-Encoding -rndr-id: 26e2e19f-af75-49a5 -x-content-type-options: nosniff -x-render-origin-server: Render -server: cloudflare -alt-svc: h3=":443"; ma=86400 - -Database query error diff --git a/readings_handler.go b/readings_handler.go index f7fde0b..a8ba193 100644 --- a/readings_handler.go +++ b/readings_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "strconv" + "github.com/lib/pq" _ "github.com/lib/pq" ) @@ -23,7 +24,7 @@ func getAllReadings(w http.ResponseWriter, r *http.Request) { db := OpenConnection() defer db.Close() - rows, err := db.Query("SELECT id, user_id, timestamp, value FROM readings") + rows, err := db.Query("SELECT id, userid, timestamp, value, torquevalues, motionwastes, setvalue FROM readings") if err != nil { http.Error(w, "Database query error", http.StatusInternalServerError) return @@ -33,7 +34,7 @@ func getAllReadings(w http.ResponseWriter, r *http.Request) { var readings []Reading for rows.Next() { var reading Reading - err := rows.Scan(&reading.ID, &reading.UserID, &reading.Timestamp, &reading.Value) + err := rows.Scan(&reading.ID, &reading.UserID, &reading.Timestamp, &reading.Value, pq.Array(&reading.TorqueValues), pq.Array(&reading.AsmTimes), pq.Array(&reading.MotionWastes), &reading.SetValue) if err != nil { http.Error(w, "Error scanning readings", http.StatusInternalServerError) @@ -64,8 +65,8 @@ func createReading(w http.ResponseWriter, r *http.Request) { } // Assuming timestamp is auto-generated by the database - sqlStatement := `INSERT INTO readings (user_id, value) VALUES ($1, $2)` - _, err = db.Exec(sqlStatement, reading.UserID, reading.Value) + sqlStatement := `INSERT INTO readings (userid, value, torquevalues, asmtimes, motionwastes, setvalue) VALUES ($1, $2, $3, $4, $5, $6)` + _, err = db.Exec(sqlStatement, reading.UserID, reading.Value, pq.Array(reading.TorqueValues), pq.Array(reading.AsmTimes), pq.Array(reading.MotionWastes), reading.SetValue) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -89,7 +90,7 @@ func getUserReadings(w http.ResponseWriter, r *http.Request) { } // Query database for readings belonging to the user - rows, err := db.Query("SELECT id, user_id, timestamp, value FROM readings WHERE user_id = $1", userID) + rows, err := db.Query("SELECT id, userid, timestamp, value, torquevalues, asmtimes, motionwastes, setvalue FROM readings WHERE userid = $1", userID) if err != nil { http.Error(w, "Database query error", http.StatusInternalServerError) return @@ -99,7 +100,7 @@ func getUserReadings(w http.ResponseWriter, r *http.Request) { var readings []Reading for rows.Next() { var reading Reading - err := rows.Scan(&reading.ID, &reading.UserID, &reading.Timestamp, &reading.Value) + err := rows.Scan(&reading.ID, &reading.UserID, &reading.Timestamp, &reading.Value, pq.Array(&reading.TorqueValues), pq.Array(&reading.AsmTimes), pq.Array(&reading.MotionWastes), &reading.SetValue) if err != nil { http.Error(w, "Error scanning readings", http.StatusInternalServerError)