UserID was not set during Import. Thats whyall imported chars are ssigned to userid 1. Because this is default

This commit is contained in:
2026-01-24 00:05:02 +01:00
parent 9dad47dc33
commit 6bc4442ec0
4 changed files with 19 additions and 12 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ func TestImportVTT2Char(t *testing.T) {
database.SetupTestDB()
defer database.ResetTestDB()
fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json")
char, err := ImportVTTJSON(fileName)
char, err := ImportVTTJSON(fileName, 1)
assert.NoError(t, err, "expected no error when saving imported Char")
var chr2 models.Char
chr2.First(char.Name)
+8 -8
View File
@@ -17,7 +17,7 @@ func TestExportChar2VTT(t *testing.T) {
// Import a test character first
fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json")
char, err := ImportVTTJSON(fileName)
char, err := ImportVTTJSON(fileName, 1)
assert.NoError(t, err, "Expected no error when importing char")
// Export the character back to VTT format
@@ -68,7 +68,7 @@ func TestExportChar2VTTRoundTrip(t *testing.T) {
// Import original
fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json")
char1, err := ImportVTTJSON(fileName)
char1, err := ImportVTTJSON(fileName, 1)
assert.NoError(t, err, "Expected no error when importing char")
// Export to VTT
@@ -87,7 +87,7 @@ func TestExportChar2VTTRoundTrip(t *testing.T) {
tempFile.Close()
// Re-import the exported file
char2, err := ImportVTTJSON(tempFile.Name())
char2, err := ImportVTTJSON(tempFile.Name(), 1)
assert.NoError(t, err, "Expected no error when re-importing char")
// Compare key fields
@@ -148,7 +148,7 @@ func TestExportCharToCSV(t *testing.T) {
// Import a test character first
fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json")
char, err := ImportVTTJSON(fileName)
char, err := ImportVTTJSON(fileName, 1)
assert.NoError(t, err, "Expected no error when importing char")
// Export to CSV
@@ -180,7 +180,7 @@ func TestExportImportWithoutMasterData(t *testing.T) {
// Import a test character first
fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json")
char1, err := ImportVTTJSON(fileName)
char1, err := ImportVTTJSON(fileName, 1)
assert.NoError(t, err, "Expected no error when importing char")
// Export to VTT
@@ -210,7 +210,7 @@ func TestExportImportWithoutMasterData(t *testing.T) {
database.DB.Exec("DELETE FROM sqlite_sequence WHERE name LIKE 'gsm_%'")
// Re-import without master data
char2, err := ImportVTTJSON(tempFile.Name())
char2, err := ImportVTTJSON(tempFile.Name(), 1)
assert.NoError(t, err, "Expected no error when re-importing without master data")
assert.NotNil(t, char2, "Character should be imported")
@@ -248,7 +248,7 @@ func TestExportImportPreservesCharacterData(t *testing.T) {
// Import a test character
fileName := fmt.Sprintf("../testdata/%s", "VTT_Import1.json")
char1, err := ImportVTTJSON(fileName)
char1, err := ImportVTTJSON(fileName, 1)
assert.NoError(t, err, "Expected no error when importing char")
// Store original counts and values
@@ -306,7 +306,7 @@ func TestExportImportPreservesCharacterData(t *testing.T) {
database.DB.Exec("DELETE FROM gsm_transportations")
// Re-import
char2, err := ImportVTTJSON(tempFile.Name())
char2, err := ImportVTTJSON(tempFile.Name(), 1)
assert.NoError(t, err, "Expected no error when re-importing")
// Verify all data was preserved
+8 -2
View File
@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/gin-gonic/gin"
@@ -58,8 +59,13 @@ func UploadFiles(c *gin.Context) {
return
}
}
character, err3 := ImportVTTJSON(vttFileName)
userIDStr := c.GetString("userID")
userID, err := strconv.Atoi(userIDStr)
if err != nil {
respondWithError(c, http.StatusInternalServerError, "Invalid user ID")
return
}
character, err3 := ImportVTTJSON(vttFileName, uint(userID))
if err3 != nil {
respondWithError(c, http.StatusInternalServerError, fmt.Sprintf("Failed to Import Character from file %s", err3.Error()))
return
+2 -1
View File
@@ -17,7 +17,7 @@ func readImportChar(fileName string) (*CharacterImport, error) {
return &character, err
}
func ImportVTTJSON(fileName string) (*models.Char, error) {
func ImportVTTJSON(fileName string, userID uint) (*models.Char, error) {
//fileName = fmt.Sprintf("../testdata/%s", "VTT_Import1.json")
imp, err := readImportChar(fileName)
if err != nil {
@@ -57,6 +57,7 @@ func ImportVTTJSON(fileName string) (*models.Char, error) {
}
char := models.Char{}
char.UserID = userID
char.Name = imp.Name
char.Rasse = imp.Rasse
char.Typ = imp.Typ