add new parameter hasChild and set with connection id
This commit is contained in:
@@ -28,6 +28,7 @@ func (d *DBMHandler) Get(req *json_dataModels.Request, id string) {
|
||||
Path: dp.Path,
|
||||
Type: dp.Type,
|
||||
Value: dp.Value,
|
||||
HasChild: dp.Datapoints != nil,
|
||||
Rights: dp.ReadWrite,
|
||||
})
|
||||
}
|
||||
|
@@ -20,29 +20,29 @@ func (d *DBMHandler) Json_Data(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
respond := json_dataModels.NewResponse()
|
||||
resp := json_dataModels.NewResponse()
|
||||
|
||||
if payload.Get != nil {
|
||||
if len(payload.Get) > 0 {
|
||||
var depth uint = 1
|
||||
|
||||
for _, get := range payload.Get {
|
||||
if get.Query != nil {
|
||||
depth = get.Query.Depth
|
||||
}
|
||||
for _, res := range d.DBM.QueryDatapoints(depth, get.Uuid, get.Path) {
|
||||
respond.AddGet(json_dataModels.Get{
|
||||
resp.AddGet(json_dataModels.Get{
|
||||
Uuid: res.Uuid,
|
||||
Path: res.Path,
|
||||
Type: res.Type,
|
||||
Value: res.Value,
|
||||
HasChild: res.Datapoints != nil,
|
||||
Rights: res.ReadWrite,
|
||||
Drivers: &res.Drivers,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if payload.Set != nil {
|
||||
respond.Set, err = d.DBM.CreateDatapoints(payload.Set...)
|
||||
if len(payload.Set) > 0 {
|
||||
resp.Set, err = d.DBM.CreateDatapoints(payload.Set...)
|
||||
if err != nil {
|
||||
r := json_data.NewResponse()
|
||||
r.SetError()
|
||||
@@ -52,7 +52,7 @@ func (d *DBMHandler) Json_Data(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(200, respond)
|
||||
c.JSON(200, resp)
|
||||
}
|
||||
|
||||
func (d *DBMHandler) Delete(c *gin.Context) {
|
||||
|
27
dbm/set.go
27
dbm/set.go
@@ -1,10 +1,12 @@
|
||||
package dbm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
|
||||
func (d *DBMHandler) Set(req *json_dataModels.Request) {
|
||||
func (d *DBMHandler) Set(req *json_dataModels.Request, id string) {
|
||||
if req == nil {
|
||||
return
|
||||
} else if len(req.Set) == 0 {
|
||||
@@ -13,9 +15,28 @@ func (d *DBMHandler) Set(req *json_dataModels.Request) {
|
||||
d.RLock()
|
||||
defer d.RUnlock()
|
||||
|
||||
resp := json_dataModels.NewResponse()
|
||||
resp.Id = req.Id
|
||||
|
||||
for _, set := range req.Set {
|
||||
for _, dp := range d.DBM.QueryDatapoints(1, set.Uuid, set.Path) {
|
||||
dp.UpdateValue(d.Conns, set.Value)
|
||||
dps := d.DBM.QueryDatapoints(1, set.Uuid, set.Path)
|
||||
if len(dps) == 0 {
|
||||
resp.SetError()
|
||||
if resp.Message == "" {
|
||||
resp.SetMessage(fmt.Sprintf("datapoint %s not found", set.Path))
|
||||
}
|
||||
continue
|
||||
}
|
||||
for _, dp := range dps {
|
||||
dp.UpdateValue(d.Conns, set.Value)
|
||||
resp.AddSet(json_dataModels.Set{
|
||||
Uuid: dp.Uuid,
|
||||
Path: dp.Path,
|
||||
Value: dp.Value,
|
||||
})
|
||||
}
|
||||
}
|
||||
if err := d.Conns.SendResponse(id, resp); err != nil {
|
||||
d.Log.Error("get.Set", err.Error())
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package dbm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
|
||||
@@ -18,7 +20,17 @@ func (d *DBMHandler) Subscribe(req *json_dataModels.Request, id string) {
|
||||
resp.Id = req.Id
|
||||
|
||||
for _, sub := range req.Subscribe {
|
||||
for _, dp := range d.DBM.QueryDatapoints(sub.Depth, sub.Uuid, sub.Path) {
|
||||
dps := d.DBM.QueryDatapoints(sub.Depth, sub.Uuid, sub.Path)
|
||||
|
||||
if len(dps) == 0 {
|
||||
resp.SetError()
|
||||
if resp.Message == "" {
|
||||
resp.SetMessage(fmt.Sprintf("datapoint %s not found", sub.Path))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
for _, dp := range dps {
|
||||
if sub.Driver != "" {
|
||||
if dp.Drivers == nil || dp.Drivers[sub.Driver] == nil {
|
||||
continue
|
||||
@@ -29,6 +41,7 @@ func (d *DBMHandler) Subscribe(req *json_dataModels.Request, id string) {
|
||||
Uuid: dp.Uuid,
|
||||
Path: dp.Path,
|
||||
Value: dp.Value,
|
||||
HasChild: dp.Datapoints != nil,
|
||||
Driver: sub.Driver,
|
||||
Drivers: &dp.Drivers,
|
||||
})
|
||||
|
@@ -47,7 +47,7 @@ func (d *DBMHandler) WebSocket(c *gin.Context) {
|
||||
|
||||
d.Get(request, id)
|
||||
// Sets
|
||||
d.Set(request)
|
||||
d.Set(request, id)
|
||||
|
||||
// Subscribe
|
||||
d.Subscribe(request, id)
|
||||
|
Reference in New Issue
Block a user