graphicek/app/sensor_config.go

47 lines
862 B
Go
Raw Normal View History

2022-08-13 23:33:50 +02:00
package app
import (
"net/http"
"github.com/gin-gonic/gin"
)
type sensorConfigValue struct {
Value string `json:"value"`
}
func (s *Server) HandlePutSensorConfig() gin.HandlerFunc {
return func(c *gin.Context) {
var configValue sensorConfigValue
sensor := c.Param("sensor")
key := c.Param("key")
if err := c.BindJSON(&configValue); err != nil {
c.AbortWithError(400, err)
return
}
if err := s.Services.SensorConfig.SetValue(sensor, key, configValue.Value); err != nil {
c.AbortWithError(500, err)
return
}
c.Writer.WriteHeader(http.StatusOK)
}
}
func (s *Server) GetSensorConfig() gin.HandlerFunc {
return func(c *gin.Context) {
sensor := c.Param("sensor")
config, err := s.Services.SensorConfig.GetValues(sensor)
if err != nil {
c.AbortWithError(500, err)
return
}
c.JSON(http.StatusOK, config)
}
}