Strukturen verschoben

Skill		WeaponSkill
Spell	Equipment
Weapon
Container
Transportation
This commit is contained in:
2025-07-28 18:56:45 +02:00
parent 40835e02a7
commit c76f1cfbe2
10 changed files with 146 additions and 99 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ package gsmaster
import (
"bamort/database"
"bamort/models"
"gorm.io/gorm"
)
@@ -16,7 +17,7 @@ func MigrateStructure(db ...*gorm.DB) error {
}
err := targetDB.AutoMigrate(
&Equipment{},
&models.Equipment{},
&Weapon{},
&Container{},
&Transportation{},
+12 -12
View File
@@ -157,8 +157,8 @@ func GetMasterData(c *gin.Context) {
Skills []models.Skill `json:"skills"`
Weaponskills []models.WeaponSkill `json:"weaponskills"`
Spell []models.Spell `json:"spells"`
Equipment []Equipment `json:"equipment"`
Weapons []Weapon `json:"weapons"`
Equipment []models.Equipment `json:"equipment"`
Weapons []models.Weapon `json:"weapons"`
SkillCategories []string `json:"skillcategories"`
SpellCategories []string `json:"spellcategories"`
}
@@ -303,42 +303,42 @@ func DeleteMDSpell(c *gin.Context) {
}
func GetMDEquipments(c *gin.Context) {
getMDItems[Equipment](c)
getMDItems[models.Equipment](c)
}
func GetMDEquipment(c *gin.Context) {
getMDItem[Equipment](c)
getMDItem[models.Equipment](c)
}
func UpdateMDEquipment(c *gin.Context) {
updateMDItem[Equipment](c)
updateMDItem[models.Equipment](c)
}
func AddEquipment(c *gin.Context) {
addMDItem[Equipment](c)
addMDItem[models.Equipment](c)
}
func DeleteMDEquipment(c *gin.Context) {
deleteMDItem[Equipment](c)
deleteMDItem[models.Equipment](c)
}
// Refactored handler functions
func GetMDWeapons(c *gin.Context) {
getMDItems[Weapon](c)
getMDItems[models.Weapon](c)
}
func GetMDWeapon(c *gin.Context) {
getMDItem[Weapon](c)
getMDItem[models.Weapon](c)
}
func UpdateMDWeapon(c *gin.Context) {
updateMDItem[Weapon](c)
updateMDItem[models.Weapon](c)
}
func AddWeapon(c *gin.Context) {
addMDItem[Weapon](c)
addMDItem[models.Weapon](c)
}
func DeleteMDWeapon(c *gin.Context) {
deleteMDItem[Weapon](c)
deleteMDItem[models.Weapon](c)
}
+4 -4
View File
@@ -15,8 +15,8 @@ type exportData struct {
Skills []models.Skill `json:"skills"`
WeaponSkills []models.WeaponSkill `json:"weapon_skills"`
Spells []models.Spell `json:"spells"`
Equipments []Equipment `json:"equipments"`
Weapons []Weapon `json:"weapons"`
Equipments []models.Equipment `json:"equipments"`
Weapons []models.Weapon `json:"weapons"`
Containers []Container `json:"containers"`
Transportations []Container `json:"transportations"`
Believes []Believe `json:"believes"`
@@ -26,8 +26,8 @@ func Export(filePath string) error {
var skills []models.Skill
var weaponSkills []models.WeaponSkill
var spells []models.Spell
var equipments []Equipment
var weapons []Weapon
var equipments []models.Equipment
var weapons []models.Weapon
var containers []Container
var transportations []Container
var believes []Believe
+3 -65
View File
@@ -11,37 +11,22 @@ import (
var dbPrefix = "gsm"
/*
type Spell struct {
models.LookupList
Bonus int `json:"bonus"`
Stufe int `json:"level"`
AP string `gorm:"default:1" json:"ap"`
Art string `gorm:"default:Gestenzauber" json:"art"`
Zauberdauer string `gorm:"default:10 sec" json:"zauberdauer"`
Reichweite string `json:"reichweite"` // in m
Wirkungsziel string `json:"wirkungsziel"`
Wirkungsbereich string `json:"wirkungsbereich"`
Wirkungsdauer string `json:"wirkungsdauer"`
Ursprung string `json:"ursprung"`
Category string `gorm:"default:normal" json:"category"`
}
*/
type Equipment struct {
models.LookupList
Gewicht float64 `json:"gewicht"` // in kg
Wert float64 `json:"wert"` // in Gold
PersonalItem bool `gorm:"default:false" json:"personal_item"`
}
*/
type Weapon struct {
Equipment
models.Equipment
SkillRequired string `json:"skill_required"`
Damage string `json:"damage"`
}
type Container struct {
Equipment
models.Equipment
Tragkraft float64 `json:"tragkraft"` // in kg
Volumen float64 `json:"volumen"` // in Liter
}
@@ -54,53 +39,6 @@ type Believe struct {
models.LookupList
}
func (object *Equipment) TableName() string {
return dbPrefix + "_" + "equipments"
}
func (stamm *Equipment) Create() error {
gameSystem := "midgard"
stamm.GameSystem = gameSystem
err := database.DB.Transaction(func(tx *gorm.DB) error {
// Save the main character record
if err := tx.Create(&stamm).Error; err != nil {
return fmt.Errorf("failed to save LookupEquipment: %w", err)
}
return nil
})
return err
}
func (stamm *Equipment) First(name string) error {
gameSystem := "midgard"
err := database.DB.First(&stamm, "game_system=? AND name = ?", gameSystem, name).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Equipment) FirstId(value uint) error {
gameSystem := "midgard"
err := database.DB.First(&object, "game_system=? AND id = ?", gameSystem, value).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Equipment) Save() error {
err := database.DB.Save(&object).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Weapon) TableName() string {
return dbPrefix + "_" + "weapons"
}
@@ -345,12 +345,12 @@ func TestImportWeapon2GSMaster(t *testing.T) {
assert.Equal(t, "check", skill.SkillRequired)
assert.Equal(t, "check", skill.Damage)
//}
skill2 := gsmaster.Weapon{}
skill2 := models.Weapon{}
erro = skill2.First("Armbrust:schwer")
assert.NoError(t, erro, "Expected no error when finding Record by name")
assert.Equal(t, 1, int(skill.ID))
skill3 := gsmaster.Weapon{}
skill3 := models.Weapon{}
erro = skill3.FirstId(1)
assert.NoError(t, erro, "Expected no error when finding Record by ID")
assert.Equal(t, "Armbrust:schwer", skill3.Name)
@@ -472,12 +472,12 @@ func TestImportEquipment2GSMaster(t *testing.T) {
assert.Equal(t, 13.0, skill.Gewicht)
assert.Equal(t, 30.0, skill.Wert)
//}
skill2 := gsmaster.Equipment{}
skill2 := models.Equipment{}
erro = skill2.First("Lederrüstung")
assert.NoError(t, erro, "Expected no error when finding Record by name")
assert.Equal(t, 1, int(skill.ID))
skill3 := gsmaster.Equipment{}
skill3 := models.Equipment{}
erro = skill3.FirstId(1)
assert.NoError(t, erro, "Expected no error when finding Record by ID")
assert.Equal(t, "Lederrüstung", skill3.Name)
+4 -4
View File
@@ -288,8 +288,8 @@ func TransformImportSpell2GSDMaster(object *Zauber) (*models.Spell, error) {
return &gsmobj, nil
}
func TransformImportWeapon2GSDMaster(object *Waffe) (*gsmaster.Weapon, error) {
gsmobj := gsmaster.Weapon{}
func TransformImportWeapon2GSDMaster(object *Waffe) (*models.Weapon, error) {
gsmobj := models.Weapon{}
err := gsmobj.First(object.Name)
// if found check if we need to adjust masterdata
@@ -359,8 +359,8 @@ func TransformImportTransportation2GSDMaster(object *Transportation) (*gsmaster.
return &gsmobj, nil
}
func TransformImportEquipment2GSDMaster(object *Ausruestung) (*gsmaster.Equipment, error) {
gsmobj := gsmaster.Equipment{}
func TransformImportEquipment2GSDMaster(object *Ausruestung) (*models.Equipment, error) {
gsmobj := models.Equipment{}
err := gsmobj.First(object.Name)
// if found check if we need to adjust masterdata
+2 -2
View File
@@ -74,8 +74,8 @@ func TestGetMasterData(t *testing.T) {
Skills []models.Skill `json:"skills"`
Weaponskills []models.WeaponSkill `json:"weaponskills"`
Spell []models.Spell `json:"spells"`
Equipment []gsmaster.Equipment `json:"equipment"`
Weapons []gsmaster.Weapon `json:"weapons"`
Equipment []models.Equipment `json:"equipment"`
Weapons []models.Weapon `json:"weapons"`
}
var dta dtaStruct
err := json.Unmarshal(respRecorder.Body.Bytes(), &dta)
+3 -3
View File
@@ -151,13 +151,13 @@ func copyAllDataToTestDB(liveDB, testDB *gorm.DB) (map[string]int, error) {
}
stats["gsmaster_spells"] = count
count, err = copyTableDataWithCount(liveDB, testDB, &gsmaster.Equipment{})
count, err = copyTableDataWithCount(liveDB, testDB, &models.Equipment{})
if err != nil {
return stats, err
}
stats["gsmaster_equipment"] = count
count, err = copyTableDataWithCount(liveDB, testDB, &gsmaster.Weapon{})
count, err = copyTableDataWithCount(liveDB, testDB, &models.Weapon{})
if err != nil {
return stats, err
}
@@ -473,7 +473,7 @@ func getTestDataStatistics(db *gorm.DB) (map[string]int64, error) {
"characters": &character.Char{},
"gsmaster_skills": &models.Skill{},
"gsmaster_spells": &models.Spell{},
"gsmaster_equipment": &gsmaster.Equipment{},
"gsmaster_equipment": &models.Equipment{},
"skills_fertigkeiten": &skills.Fertigkeit{},
"skills_waffenfertigkeiten": &skills.Waffenfertigkeit{},
"skills_zauber": &skills.Zauber{},
+1 -1
View File
@@ -19,8 +19,8 @@ func MigrateStructure(db ...*gorm.DB) error {
&Skill{},
&WeaponSkill{},
&Spell{},
&Equipment{},
/*
&Equipment{},
&Weapon{},
&Container{},
&Transportation{},
+111 -3
View File
@@ -69,6 +69,19 @@ type Spell struct {
Category string `gorm:"default:normal" json:"category"`
}
type Equipment struct {
LookupList
Gewicht float64 `json:"gewicht"` // in kg
Wert float64 `json:"wert"` // in Gold
PersonalItem bool `gorm:"default:false" json:"personal_item"`
}
type Weapon struct {
Equipment
SkillRequired string `json:"skill_required"`
Damage string `json:"damage"`
}
func (object *LookupList) Create() error {
gameSystem := "midgard"
object.GameSystem = gameSystem
@@ -113,7 +126,7 @@ func (object *LookupList) Save() error {
}
func (object *Skill) TableName() string {
var dbPrefix = "gsm"
dbPrefix := "gsm"
return dbPrefix + "_" + "skills"
}
@@ -215,7 +228,7 @@ func (object *Skill) GetSkillCategories() ([]string, error) {
}
func (object *WeaponSkill) TableName() string {
var dbPrefix = "gsm"
dbPrefix := "gsm"
return dbPrefix + "_" + "weaponskills"
}
@@ -263,7 +276,7 @@ func (object *WeaponSkill) Save() error {
}
func (object *Spell) TableName() string {
var dbPrefix = "gsm"
dbPrefix := "gsm"
return dbPrefix + "_" + "spells"
}
@@ -325,3 +338,98 @@ func (object *Spell) GetSpellCategories() ([]string, error) {
return categories, nil
}
func (object *Equipment) TableName() string {
dbPrefix := "gsm"
return dbPrefix + "_" + "equipments"
}
func (stamm *Equipment) Create() error {
gameSystem := "midgard"
stamm.GameSystem = gameSystem
err := database.DB.Transaction(func(tx *gorm.DB) error {
// Save the main character record
if err := tx.Create(&stamm).Error; err != nil {
return fmt.Errorf("failed to save LookupEquipment: %w", err)
}
return nil
})
return err
}
func (stamm *Equipment) First(name string) error {
gameSystem := "midgard"
err := database.DB.First(&stamm, "game_system=? AND name = ?", gameSystem, name).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Equipment) FirstId(value uint) error {
gameSystem := "midgard"
err := database.DB.First(&object, "game_system=? AND id = ?", gameSystem, value).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Equipment) Save() error {
err := database.DB.Save(&object).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Weapon) TableName() string {
dbPrefix := "gsm"
return dbPrefix + "_" + "weapons"
}
func (stamm *Weapon) Create() error {
gameSystem := "midgard"
stamm.GameSystem = gameSystem
err := database.DB.Transaction(func(tx *gorm.DB) error {
// Save the main character record
if err := tx.Create(&stamm).Error; err != nil {
return fmt.Errorf("failed to save LookupEquipment: %w", err)
}
return nil
})
return err
}
func (stamm *Weapon) First(name string) error {
gameSystem := "midgard"
err := database.DB.First(&stamm, "game_system=? AND name = ?", gameSystem, name).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Weapon) FirstId(id uint) error {
gameSystem := "midgard"
err := database.DB.First(&object, "game_system=? AND id = ?", gameSystem, id).Error
if err != nil {
return err
}
return nil
}
func (object *Weapon) Save() error {
err := database.DB.Save(&object).Error
if err != nil {
// zauber found
return err
}
return nil
}