32 lines
731 B
Go
32 lines
731 B
Go
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})
|
|
}
|