new son_data model

This commit is contained in:
Adrian Zürcher
2025-05-05 07:32:26 +02:00
parent a92995d766
commit dc64d08e9d
5 changed files with 28 additions and 19 deletions

View File

@@ -30,7 +30,8 @@ func (d *ArtNetDriver) CreateBus(c *gin.Context) {
_, err := auth.GetIDFromQuery(c)
if err != nil {
r := json_data.NewResponse()
r.SendError(err.Error())
r.SetError()
r.SetMessage(err.Error())
c.JSON(http.StatusBadRequest, r)
return
}
@@ -42,14 +43,16 @@ func (d *ArtNetDriver) CreateBus(c *gin.Context) {
if addr := net.ParseIP(busPayload.Ip); addr == nil {
r := json_data.NewResponse()
r.SendError("wrong ip '" + busPayload.Ip + "'")
r.SetError()
r.SetMessage("wrong ip '" + busPayload.Ip + "'")
c.JSON(http.StatusBadRequest, r)
return
}
if _, ok := d.Buses[busPayload.Name]; ok {
r := json_data.NewResponse()
r.SendError("bus " + busPayload.Name + " exists already")
r.SetError()
r.SetMessage("bus " + busPayload.Name + " exists already")
c.JSON(http.StatusOK, r)
return
}
@@ -57,7 +60,7 @@ func (d *ArtNetDriver) CreateBus(c *gin.Context) {
bus := d.NewBus(busPayload.Name, busPayload.Ip, busPayload.GetPort())
r := json_data.NewResponse()
r.SendMessage(fmt.Sprintf("bus '%s' successfully created with ip: %s and on port: %d", bus.Name, bus.Ip, bus.GetPort()))
r.SetMessage(fmt.Sprintf("bus '%s' successfully created with ip: %s and on port: %d", bus.Name, bus.Ip, bus.GetPort()))
c.JSON(http.StatusOK, r)
d.cfgHandler.SaveCfg(*d)
}
@@ -66,7 +69,8 @@ func (d *ArtNetDriver) RemoveBus(c *gin.Context) {
_, err := auth.GetIDFromQuery(c)
if err != nil {
r := json_data.NewResponse()
r.SendError("id: " + err.Error())
r.SetError()
r.SetMessage("id: " + err.Error())
c.JSON(http.StatusBadRequest, r)
return
}
@@ -78,14 +82,14 @@ func (d *ArtNetDriver) RemoveBus(c *gin.Context) {
if _, ok := d.Buses[busPayload.Name]; !ok {
r := json_dataModels.NewResponse()
r.SendMessage("bus " + busPayload.Name + " not found")
r.SetMessage("bus " + busPayload.Name + " not found")
c.JSON(http.StatusOK, r)
return
} else {
delete(d.Buses, busPayload.Name)
}
r := json_dataModels.NewResponse()
r.SendMessage(fmt.Sprintf("bus '%s' successfully removed", busPayload.Name))
r.SetMessage(fmt.Sprintf("bus '%s' successfully removed", busPayload.Name))
c.JSON(http.StatusOK, r)
d.cfgHandler.SaveCfg(*d)
}
@@ -94,7 +98,8 @@ func (d *ArtNetDriver) Start(c *gin.Context) {
_, err := auth.GetIDFromQuery(c)
if err != nil {
r := json_data.NewResponse()
r.SendError("id: " + err.Error())
r.SetError()
r.SetMessage("id: " + err.Error())
c.JSON(http.StatusBadRequest, r)
return
}
@@ -107,7 +112,7 @@ func (d *ArtNetDriver) Start(c *gin.Context) {
d.Buses[busPayload.Name].Start(d.Log)
r := json_dataModels.NewResponse()
r.SendMessage(fmt.Sprintf("bus '%s' running", busPayload.Name))
r.SetMessage(fmt.Sprintf("bus '%s' running", busPayload.Name))
c.JSON(http.StatusOK, r)
d.cfgHandler.SaveCfg(*d)
}
@@ -116,7 +121,8 @@ func (d *ArtNetDriver) Stop(c *gin.Context) {
_, err := auth.GetIDFromQuery(c)
if err != nil {
r := json_data.NewResponse()
r.SendError("id: " + err.Error())
r.SetError()
r.SetMessage("id: " + err.Error())
c.JSON(http.StatusBadRequest, r)
return
}
@@ -129,7 +135,7 @@ func (d *ArtNetDriver) Stop(c *gin.Context) {
d.Buses[busPayload.Name].Stop()
r := json_dataModels.NewResponse()
r.SendMessage(fmt.Sprintf("bus '%s' stopped", busPayload.Name))
r.SetMessage(fmt.Sprintf("bus '%s' stopped", busPayload.Name))
c.JSON(http.StatusOK, r)
d.cfgHandler.SaveCfg(*d)
}
@@ -138,7 +144,8 @@ func (d *ArtNetDriver) Status(c *gin.Context) {
_, err := auth.GetIDFromQuery(c)
if err != nil {
r := json_data.NewResponse()
r.SendError("id: " + err.Error())
r.SetError()
r.SetMessage("id: " + err.Error())
c.JSON(http.StatusBadRequest, r)
return
}
@@ -153,6 +160,6 @@ func (d *ArtNetDriver) Status(c *gin.Context) {
if d.Buses[busPayload.Name].Status() {
state = "running"
}
r.SendMessage(fmt.Sprintf("bus '%s' %s", busPayload.Name, state))
r.SetMessage(fmt.Sprintf("bus '%s' %s", busPayload.Name, state))
c.JSON(http.StatusOK, r)
}

View File

@@ -6,7 +6,7 @@ import (
json_dataModels "github.com/tecamino/tecamino-json_data/models"
)
func (d *ArtNetDriver) Subscribe(subs ...json_dataModels.Subscribe) {
func (d *ArtNetDriver) Subscribe(subs ...json_dataModels.Subscription) {
if d.Subscriptions == nil {
d.Subscriptions = models.NewSubscriptions()
}