Skip to content

Commit

Permalink
FIX #92
Browse files Browse the repository at this point in the history
Added /sensor route .
  • Loading branch information
Tushar-kalsi committed Nov 29, 2023
1 parent 9b55308 commit eec66b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
6 changes: 2 additions & 4 deletions backend/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -394,4 +393,3 @@ func (cs *server) addSensor(w http.ResponseWriter, r *http.Request, p httprouter
w.WriteHeader(http.StatusOK)

}

3 changes: 1 addition & 2 deletions backend/repos/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions backend/repos/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
6 changes: 2 additions & 4 deletions backend/repos/sensors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -27,4 +26,3 @@ func initRepoForSensors(t *testing.T) *SensorRepo {
require.NotNil(t, r)
return r
}

0 comments on commit eec66b9

Please sign in to comment.