Skip to content

Commit

Permalink
Change add alarm to return 201 status code
Browse files Browse the repository at this point in the history
  • Loading branch information
bb4L committed Aug 1, 2021
1 parent 20e6144 commit 2e842d5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestApi(t *testing.T) {
{name: "get alarm 1", r: newreq("GET", ts.URL+"/alarm/1", nil), expectedStatus: 200, expectedData: alarm2Json},
{name: "get alarm 2", r: newreq("GET", ts.URL+"/alarm/2", nil), expectedStatus: 400, expectedData: []byte(`{"message": "index not valid 2"}`)},
{name: "get radio", r: newreq("GET", ts.URL+"/radio", nil), expectedStatus: 200, expectedData: result2},
{name: "add alarm", r: newreq("POST", ts.URL+"/alarm", bytes.NewReader(alarm3Json)), expectedStatus: 200, expectedData: resultAddAlarm},
{name: "add alarm", r: newreq("POST", ts.URL+"/alarm", bytes.NewReader(alarm3Json)), expectedStatus: 201, expectedData: resultAddAlarm},

{name: "change alarm", r: newreq("PUT", ts.URL+"/alarm/0", bytes.NewReader(alarm3ChangedJSON)), expectedStatus: 200, expectedData: alarm3ChangedJSON},
{name: "rechange alarm", r: newreq("PUT", ts.URL+"/alarm/0", bytes.NewReader(alarm1Json)), expectedStatus: 200, expectedData: alarm1Json},
Expand Down
1 change: 1 addition & 0 deletions apiserver/alarm/alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func addAlarm(w http.ResponseWriter, r *http.Request) {
return
}

w.WriteHeader(http.StatusCreated)
w.Header().Set("Content-Type", "application/json")
w.Write(jsonData)
}
Expand Down
18 changes: 0 additions & 18 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,3 @@ func checkIfShoulBeRunning(diff time.Duration, weekday int, alarm types.Alarm) (
}
return
}

// func changeRunning(storageHelper *storage.StorageHelper, shouldRun bool) {

// storedData, err := storageHelper.GetStoredData(true)
// if err != nil {
// logger.Fatalf("Error while loading data: %s", err)
// }
// if shouldRun {
// storedData.Radio.StartRadio()
// } else {
// err := storedData.Radio.StopRadio()
// if err != nil {
// logger.Printf("Error while stopping radio %s", err)
// }
// }

// storageHelper.SaveStoredData(storedData)
// }

0 comments on commit 2e842d5

Please sign in to comment.