implement new json_data model

This commit is contained in:
Adrian Zürcher
2025-04-29 08:34:51 +02:00
parent f5e66af3d8
commit 2839b615c3
9 changed files with 176 additions and 59 deletions

View File

@@ -8,6 +8,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
)
// sends a list of all buses in the driver
@@ -79,17 +80,16 @@ func (d *ArtNetDriver) RemoveBus(c *gin.Context) {
}
if _, ok := d.Buses[payload.Name]; !ok {
c.JSON(http.StatusOK, gin.H{"message": "bus " + payload.Name + " not found"})
c.JSON(http.StatusOK, models.JsonResponse{
Message: "bus " + payload.Name + " not found"})
r := json_dataModels.NewResponse()
r.SendMessage("bus " + payload.Name + " not found")
c.JSON(http.StatusOK, r)
return
} else {
delete(d.Buses, payload.Name)
}
c.JSON(http.StatusOK, models.JsonResponse{
Message: fmt.Sprintf("bus '%s' successfully removed", payload.Name),
})
r := json_dataModels.NewResponse()
r.SendMessage(fmt.Sprintf("bus '%s' successfully removed", payload.Name))
c.JSON(http.StatusOK, r)
d.cfgHandler.SaveCfg(*d)
}
@@ -114,9 +114,9 @@ func (d *ArtNetDriver) Start(c *gin.Context) {
d.Buses[payload.Name].Start(d.Log)
c.JSON(http.StatusOK, models.JsonResponse{
Message: fmt.Sprintf("bus '%s' running", payload.Name),
})
r := json_dataModels.NewResponse()
r.SendMessage(fmt.Sprintf("bus '%s' running", payload.Name))
c.JSON(http.StatusOK, r)
d.cfgHandler.SaveCfg(*d)
}
@@ -141,8 +141,8 @@ func (d *ArtNetDriver) Stop(c *gin.Context) {
d.Buses[payload.Name].Stop()
c.JSON(http.StatusOK, models.JsonResponse{
Message: fmt.Sprintf("bus '%s' stopped", payload.Name),
})
r := json_dataModels.NewResponse()
r.SendMessage(fmt.Sprintf("bus '%s' stopped", payload.Name))
c.JSON(http.StatusOK, r)
d.cfgHandler.SaveCfg(*d)
}