2016-05-17 10:59:34 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/FreifunkBremen/respond-collector/models"
|
2016-05-29 21:41:58 +02:00
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
"net/http"
|
2016-05-17 10:59:34 +02:00
|
|
|
)
|
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// NodesAPI struct for API
|
|
|
|
type NodesAPI struct {
|
2016-05-29 21:41:58 +02:00
|
|
|
config *models.Config
|
|
|
|
nodes *models.Nodes
|
2016-05-17 10:59:34 +02:00
|
|
|
}
|
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// NewNodes Bind to API
|
2016-05-29 21:41:58 +02:00
|
|
|
func NewNodes(config *models.Config, router *httprouter.Router, prefix string, nodes *models.Nodes) {
|
2017-01-20 22:27:44 +01:00
|
|
|
api := &NodesAPI{
|
2016-05-29 21:41:58 +02:00
|
|
|
nodes: nodes,
|
2016-05-17 10:59:34 +02:00
|
|
|
config: config,
|
|
|
|
}
|
2016-05-29 21:41:58 +02:00
|
|
|
router.GET(prefix, api.GetAll)
|
2016-05-17 10:59:34 +02:00
|
|
|
}
|
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// GetAll request for get all nodes
|
|
|
|
func (api *NodesAPI) GetAll(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
2016-05-29 21:41:58 +02:00
|
|
|
jsonOutput(w, r, api.nodes.List)
|
2016-05-17 10:59:34 +02:00
|
|
|
}
|