Skip to content

Commit

Permalink
Merge pull request #4 from Klausdk1999/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
cissavgonc authored Dec 6, 2023
2 parents 950e755 + 397ec62 commit fbaf72c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
13 changes: 0 additions & 13 deletions documentation/Get_all_readings-1701839548674.txt

This file was deleted.

13 changes: 7 additions & 6 deletions readings_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strconv"

"github.com/lib/pq"
_ "github.com/lib/pq"
)

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit fbaf72c

Please sign in to comment.