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