Added route for saving device info
This commit is contained in:
31
controllers/DevicesController.go
Normal file
31
controllers/DevicesController.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab.com/pactual1/backend/models"
|
||||
"gitlab.com/pactual1/backend/shared"
|
||||
)
|
||||
|
||||
func SaveDeviceInfofunc(c *gin.Context) {
|
||||
var deviceInfo models.DeviceInfo
|
||||
rawData, _ := c.GetRawData()
|
||||
|
||||
// Unmarshal to the important info structure
|
||||
err := json.Unmarshal(rawData, &deviceInfo)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON payload"})
|
||||
return
|
||||
}
|
||||
|
||||
// Convert raw JSON bytes to string
|
||||
deviceInfo.RawJSON = string(rawData)
|
||||
|
||||
// Save deviceInfo to your database here
|
||||
db :=shared.GetDb()
|
||||
db.Create(&deviceInfo)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Successfully received device info", "data": deviceInfo})
|
||||
}
|
||||
Reference in New Issue
Block a user