Browse Source

add device search endpoint. >_>

pull/1/head
Gisle Aune 3 years ago
parent
commit
7a6ee3f87b
  1. 32
      app/api/bridges.go

32
app/api/bridges.go

@ -6,6 +6,7 @@ import (
"git.aiterp.net/lucifer/new-server/models"
"github.com/gin-gonic/gin"
"log"
"time"
)
func Bridges(r gin.IRoutes) {
@ -96,6 +97,37 @@ func Bridges(r gin.IRoutes) {
return bridge, nil
}))
r.PUT("/:id/search", handler(func(c *gin.Context) (interface{}, error) {
var body struct {
TimeoutMS int64 `json:"timeoutMs"`
}
err := parseBody(c, &body)
if err != nil {
return nil, err
}
if body.TimeoutMS <= 0 {
body.TimeoutMS = 30000
}
bridge, err := config.BridgeRepository().Find(ctxOf(c), intParam(c, "id"))
if err != nil {
return nil, err
}
driver, err := config.DriverProvider().Provide(bridge.Driver)
if err != nil {
return nil, err
}
devices, err := driver.SearchDevices(ctxOf(c), bridge, time.Millisecond * time.Duration(body.TimeoutMS))
if err != nil {
return nil, err
}
return devices, nil
}))
r.DELETE("/:id", handler(func(c *gin.Context) (interface{}, error) {
bridge, err := config.BridgeRepository().Find(ctxOf(c), intParam(c, "id"))
if err != nil {

Loading…
Cancel
Save