Now we can share a char to other users

only in DB no UI yet
This commit is contained in:
2026-02-01 21:32:48 +01:00
parent 5152600ea3
commit 321339861f
5 changed files with 61 additions and 0 deletions
+8
View File
@@ -59,6 +59,14 @@ func ListCharacters(c *gin.Context) {
respondWithError(c, http.StatusInternalServerError, "Failed to retrieve public characters")
return
}
listShared, err := models.FindSharedCharList(c.GetUint("userID"))
if err != nil {
logger.Error("Fehler beim Laden der geteilten Charaktere: %s", err.Error())
respondWithError(c, http.StatusInternalServerError, "Failed to retrieve shared characters")
return
}
listPublic = append(listPublic, listShared...)
allCharacters.Others = listPublic
logger.Info("Charakterliste erfolgreich geladen: %d Charaktere", len(listOfChars))
+3
View File
@@ -295,6 +295,9 @@ func copyMariaDBToSQLite(mariaDB, sqliteDB *gorm.DB) error {
// Audit Logging (abhängig von Char)
&models.AuditLogEntry{},
// Char Shares (abhängig von Char und User)
&models.CharShare{},
// View-Strukturen ohne eigene Tabellen werden nicht kopiert:
// SkillLearningInfo, SpellLearningInfo, CharList, FeChar, etc.
}
+3
View File
@@ -49,6 +49,7 @@ func MigrateStructure(db ...*gorm.DB) error {
return nil
}
func gameSystemMigrateStructure(db ...*gorm.DB) error {
// Use provided DB or default to database.DB
var targetDB *gorm.DB
@@ -66,6 +67,7 @@ func gameSystemMigrateStructure(db ...*gorm.DB) error {
}
return nil
}
func gsMasterMigrateStructure(db ...*gorm.DB) error {
// Use provided DB or default to database.DB
var targetDB *gorm.DB
@@ -112,6 +114,7 @@ func characterMigrateStructure(db ...*gorm.DB) error {
&Bennies{},
&Vermoegen{},
&CharacterCreationSession{},
&CharShare{},
)
if err != nil {
return err
+15
View File
@@ -255,6 +255,21 @@ func (object *Char) FindByUserID(userID uint) ([]Char, error) {
return chars, nil
}
func FindSharedCharList(userID uint) ([]CharList, error) {
var chars []CharList
gs := GetGameSystem(0, "midgard")
err := database.DB.Table("char_chars").
Select("char_chars.id, char_chars.name, char_chars.user_id, char_chars.rasse, char_chars.typ, char_chars.grad, char_chars.public, char_chars.game_system, char_chars.game_system_id, users.username as owner").
Joins("LEFT JOIN users ON char_chars.user_id = users.user_id").
Joins("INNER JOIN char_shares ON char_shares.character_id = char_chars.id").
Where("char_shares.user_id = ? AND (char_chars.game_system = ? OR char_chars.game_system_id = ?)", userID, gs.Name, gs.ID).
Find(&chars).Error
if err != nil {
return nil, err
}
return chars, nil
}
func FindPublicCharList() ([]CharList, error) {
var chars []CharList
gs := GetGameSystem(0, "midgard")
+32
View File
@@ -0,0 +1,32 @@
package models
import (
"bamort/database"
"fmt"
)
type CharShare struct {
ID uint `gorm:"primaryKey" json:"id"`
CharacterID uint `gorm:"index" json:"character_id"` // ID of the character being shared
UserID uint `gorm:"index" json:"user_id"` // ID of the user with whom the character is shared
Permission string `json:"permission"` // Permission level (e.g., "read", "write")
}
func (object *CharShare) TableName() string {
dbPrefix := "char"
return dbPrefix + "_" + "shares"
}
func (object *CharShare) FirstByChar(id uint) error {
if id == 0 {
return fmt.Errorf("invalid character ID")
}
return database.DB.First(object, "character_id = ?", id).Error
}
func (object *CharShare) FirstByUser(id uint) error {
if id == 0 {
return fmt.Errorf("invalid user ID")
}
return database.DB.First(object, "user_id = ?", id).Error
}