struct
This commit is contained in:
31
controllers/train.go
Normal file
31
controllers/train.go
Normal file
@ -0,0 +1,31 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hr_receiver/config"
|
||||
"hr_receiver/models"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ReceiveTrainingData(c *gin.Context) {
|
||||
var data models.TrainingData
|
||||
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Invalid request body: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if result := config.DB.Create(&data); result.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Failed to save data: " + result.Error.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, gin.H{
|
||||
"message": "Data saved successfully",
|
||||
"id": data.ID,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user