diff --git a/backend/handlers.go b/backend/handlers.go index 36f63ed..30c7e5b 100644 --- a/backend/handlers.go +++ b/backend/handlers.go @@ -367,11 +367,10 @@ func (cs *server) getSensorsByUser(w http.ResponseWriter, r *http.Request, p htt } -func (cs *server) addSensor(w http.ResponseWriter, r *http.Request, p httprouter.Params){ - +func (cs *server) addSensor(w http.ResponseWriter, r *http.Request, p httprouter.Params) { userId := userIDFromCtx(r.Context()) - + decoder := json.NewDecoder(r.Body) defer r.Body.Close() var sensor entities.Sensor @@ -394,4 +393,3 @@ func (cs *server) addSensor(w http.ResponseWriter, r *http.Request, p httprouter w.WriteHeader(http.StatusOK) } - diff --git a/backend/repos/query_test.go b/backend/repos/query_test.go index 8a718f5..054bdfc 100644 --- a/backend/repos/query_test.go +++ b/backend/repos/query_test.go @@ -140,8 +140,7 @@ func TestUpdateQuery_Existing(t *testing.T) { func initRepo(t *testing.T) *QueryRepo { tmp := t.TempDir() dbPath := fmt.Sprintf("%s/test.db", tmp) - - fmt.Println("path ", dbPath) + db, err := sqlx.Connect("sqlite3", dbPath) require.NoError(t, err) diff --git a/backend/repos/sensors.go b/backend/repos/sensors.go index caab060..bb416c2 100644 --- a/backend/repos/sensors.go +++ b/backend/repos/sensors.go @@ -59,16 +59,16 @@ func (r *SensorRepo) GetSensorsByOwnerId(ownerId string) ([]entities.Sensor, err } -func (r *SensorRepo) AddSensors(sensor entities.Sensor , userId string) error { +func (r *SensorRepo) AddSensors(sensor entities.Sensor, userId string) error { - s:=entities.Sensor{Id: sensor.Id , OwnerId: userId, Name:sensor.Name} + s := entities.Sensor{Id: sensor.Id, OwnerId: userId, Name: sensor.Name} + + _, err := r.addSensor.Exec(s) - _, err:=r.addSensor.Exec(s) - if err != nil { - return err + return err } - return nil + return nil } diff --git a/backend/repos/sensors_test.go b/backend/repos/sensors_test.go index ae66ba1..c165686 100644 --- a/backend/repos/sensors_test.go +++ b/backend/repos/sensors_test.go @@ -9,15 +9,14 @@ import ( ) func TestGetSesors(t *testing.T) { - -} +} func initRepoForSensors(t *testing.T) *SensorRepo { tmp := t.TempDir() dbPath := fmt.Sprintf("%s/test.db", tmp) + - fmt.Println("path ", dbPath) db, err := sqlx.Connect("sqlite3", dbPath) require.NoError(t, err) @@ -27,4 +26,3 @@ func initRepoForSensors(t *testing.T) *SensorRepo { require.NotNil(t, r) return r } -