From 2e842d5af835cf9c0a3bc7b63313c740228279a4 Mon Sep 17 00:00:00 2001 From: bb4L <39266013+bb4L@users.noreply.github.com> Date: Sun, 1 Aug 2021 08:09:51 +0200 Subject: [PATCH] Change add alarm to return 201 status code --- api_test.go | 2 +- apiserver/alarm/alarm.go | 1 + runner/runner.go | 18 ------------------ 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/api_test.go b/api_test.go index c55e305..3759b41 100644 --- a/api_test.go +++ b/api_test.go @@ -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}, diff --git a/apiserver/alarm/alarm.go b/apiserver/alarm/alarm.go index 74ca3ea..d394fea 100644 --- a/apiserver/alarm/alarm.go +++ b/apiserver/alarm/alarm.go @@ -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) } diff --git a/runner/runner.go b/runner/runner.go index 00f10ee..d479048 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -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) -// }