Add support for seperate meters
This commit is contained in:
parent
85165d5c74
commit
b0909c6f7e
3 changed files with 97 additions and 48 deletions
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -31,9 +32,10 @@ func main() {
|
|||
pq := e.Group(`/pq`)
|
||||
pq.GET(`/count`, count)
|
||||
pq.GET(`/list`, listAttr)
|
||||
pq.GET(`/meters`, listMeters)
|
||||
|
||||
for _, v := range app.GetAttributes() {
|
||||
pq.GET(`/`+strings.ToLower(v.Name)+`/:date`, getAttr(v.Index))
|
||||
pq.GET(`/:meter/`+strings.ToLower(v.Name)+`/:date`, getAttr(v.Index))
|
||||
|
||||
attrs = append(attrs, strings.ToLower(v.Name))
|
||||
}
|
||||
|
@ -51,13 +53,22 @@ func listAttr(c echo.Context) error {
|
|||
return c.JSON(200, attrs)
|
||||
}
|
||||
|
||||
func listMeters(c echo.Context) error {
|
||||
return c.JSON(200, app.GetMeters())
|
||||
}
|
||||
|
||||
func getAttr(index int) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
meter, err := strconv.Atoi(c.Param(`meter`))
|
||||
if err != nil {
|
||||
return c.NoContent(400)
|
||||
}
|
||||
|
||||
date, err := time.Parse(time.RFC3339, c.Param(`date`))
|
||||
if err != nil {
|
||||
return c.NoContent(400)
|
||||
}
|
||||
|
||||
return c.JSON(200, app.GetAttribute(index, date))
|
||||
return c.JSON(200, app.GetAttribute(index, meter, date))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue