1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 10:52:47 +00:00

adjusted end points again

This commit is contained in:
2016-09-14 20:12:41 +00:00
parent 4354dfe458
commit 2f45864fcc
3 changed files with 40 additions and 20 deletions

View File

@@ -59,9 +59,10 @@ func (s *Data) StoreData() error {
//handle queries for all sensors page
type DataStore_AllSensors struct {
ID string `json:"location" bson:"_id"`
Temperature float64 `json:"temperature" bson:"temperature"`
Updated time.Time `json:"updated" bson:"updated"`
ID bson.ObjectId `bson:"_id,omitempty"`
Location string `json:"location", bson:"location"`
Temperature float64 `json:"temperature" bson:"temperature"`
Updated time.Time `json:"updated" bson:"updated"`
}
//get latest update from each unique sensor
@@ -78,7 +79,9 @@ func GetAllSensors() ([]DataStore_AllSensors, error) {
err := c.Pipe([]bson.M{{"$group": bson.M{"_id": "$location", "temperature": bson.M{"$last": "$temperature"},
"updated": bson.M{"$last": "$updated"}}},
bson.M{"$sort": bson.M{"_id": 1}}}).All(&s)
bson.M{"$sort": bson.M{"_id": 1}},
bson.M{"$project": bson.M{"location": "$_id", "temperature": "$temperature", "updated": "$updated"}},
}).All(&s)
if err != nil {
return s, nil