Exemple #1
0
func GetDevice(c *gin.Context) {
	device_name := c.Params.ByName("device_name")
	var device tf.Device
	device.Device_name = device_name
	if device, err := device.GetDevice(); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("Failed to get device %s", device_name))
	} else {
		c.JSON(http.StatusOK, device)
	}
}
Exemple #2
0
func DeleteDevice(c *gin.Context) {
	device_name := c.Params.ByName("device_name")
	var device tf.Device
	device.Device_name = device_name
	fmt.Println(device_name)
	if err := device.DeleteDevice(); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("Failed to delete device %s.  Error: %s", device_name, err))
	} else {
		c.String(http.StatusOK, fmt.Sprintf("Device %s has been deleted successfully", device_name))
	}
}
Exemple #3
0
func UpdateDevice(c *gin.Context) {
	device_name := c.Params.ByName("device_name")
	var payload tf.Device
	c.Bind(&payload)
	var device tf.Device
	device.Device_name = device_name
	if err := device.UpdateDevice(payload); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("Failed to update device %s.  Error: ", device_name, err))
	} else {
		c.String(http.StatusOK, fmt.Sprintf("Device %s has been updated successfully", device_name))
	}
}
Exemple #4
0
func CreateDevice(c *gin.Context) {
	var payload tf.Device
	c.Bind(&payload)
	var device tf.Device

	if err := device.CreateDevice(payload); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("Failed to create a new  device.  Error: %s", err))
	} else {
		c.String(http.StatusOK, "A new device has been created successfully")
	}

}
Exemple #5
0
func GetAllDevices(c *gin.Context) {
	var device tf.Device
	devices := device.GetAllDevices()
	c.JSON(http.StatusOK, devices)
}