mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-10 09:52:51 +00:00
working on api for getting unique list of dates
This commit is contained in:
@@ -61,6 +61,7 @@ func HandleSensorRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P
|
||||
storedData.Month = int(t.Month())
|
||||
storedData.MonthName = t.Month().String()
|
||||
storedData.Year = t.Year()
|
||||
storedData.Updated = t
|
||||
|
||||
err := storedData.StoreData()
|
||||
|
||||
@@ -134,21 +135,7 @@ func HandleSensorByLocation(w http.ResponseWriter, r *http.Request, ps httproute
|
||||
|
||||
s, err := daily_sensor.GetAllSensorInfo(location)
|
||||
|
||||
var response string
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
response = "{message : \"Error loading data from database\""
|
||||
} else {
|
||||
js, err := json.MarshalIndent(s, "", " ")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
response = "{message : \"Error loading data from database\""
|
||||
} else {
|
||||
response = string(js)
|
||||
}
|
||||
}
|
||||
response := createResponse(s, err)
|
||||
|
||||
fmt.Fprint(w, response)
|
||||
}
|
||||
@@ -162,21 +149,7 @@ func HandleSensorByLocationYear(w http.ResponseWriter, r *http.Request, ps httpr
|
||||
|
||||
s, err := daily_sensor.GetAllSensorInfoByYear(location, year)
|
||||
|
||||
var response string
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
response = "{message : \"Error loading data from database\""
|
||||
} else {
|
||||
js, err := json.MarshalIndent(s, "", " ")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
response = "{message : \"Error loading data from database\""
|
||||
} else {
|
||||
response = string(js)
|
||||
}
|
||||
}
|
||||
response := createResponse(s, err)
|
||||
|
||||
fmt.Fprint(w, response)
|
||||
}
|
||||
@@ -191,21 +164,41 @@ func HandleSensorByLocationMonth(w http.ResponseWriter, r *http.Request, ps http
|
||||
|
||||
s, err := daily_sensor.GetAllSensorInfoByMonth(location, year, monthname)
|
||||
|
||||
response := createResponse(s, err)
|
||||
|
||||
fmt.Fprint(w, response)
|
||||
}
|
||||
|
||||
/*
|
||||
func HandleUniqueDates(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
|
||||
location := ps.ByName("location")
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
s, err := daily_sensor.GetUniqueSensorDates(location)
|
||||
|
||||
response := createResponse(s, err)
|
||||
|
||||
fmt.Fprint(w, response)
|
||||
}
|
||||
*/
|
||||
func createResponse(s []daily_sensor.Data, err error) string{
|
||||
var response string
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
response = "{message : \"Error loading data from database\""
|
||||
} else {
|
||||
js, err := json.MarshalIndent(s, "", " ")
|
||||
js, err1 := json.MarshalIndent(s, "", " ")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
if err1 != nil {
|
||||
log.Println(err1)
|
||||
response = "{message : \"Error loading data from database\""
|
||||
} else {
|
||||
response = string(js)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprint(w, response)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
Reference in New Issue
Block a user