should update values from DataSheetView

This commit is contained in:
2025-12-29 17:07:45 +01:00
parent 3a12b613d9
commit 28b6ed204a
2 changed files with 304 additions and 29 deletions
+9 -2
View File
@@ -14,6 +14,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
// Character Handlers
@@ -100,14 +101,20 @@ func UpdateCharacter(c *gin.Context) {
return
}
// Store the original ID to preserve it
originalID := character.ID
// Bind the updated data
if err := c.ShouldBindJSON(&character); err != nil {
respondWithError(c, http.StatusBadRequest, err.Error())
return
}
// Save the updated character
if err := database.DB.Save(&character).Error; err != nil {
// Restore the ID
character.ID = originalID
// Update all associations
if err := database.DB.Session(&gorm.Session{FullSaveAssociations: true}).Save(&character).Error; err != nil {
respondWithError(c, http.StatusInternalServerError, "Failed to update character")
return
}