Lockuplist moved to models

This commit is contained in:
2025-07-27 22:25:17 +02:00
parent 3874b71608
commit 12afdf8095
6 changed files with 87 additions and 32 deletions
+2 -2
View File
@@ -43,7 +43,7 @@ func createTestSkillData() error {
// GSM Test-Skill erstellen
gsmSkill := gsmaster.Skill{
LookupList: gsmaster.LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Menschenkenntnis",
Beschreibung: "Test Skill",
@@ -60,7 +60,7 @@ func createTestSkillData() error {
// GSM Test-Spell erstellen
gsmSpell := gsmaster.Spell{
LookupList: gsmaster.LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Macht über das Selbst",
Beschreibung: "Test Spell",
+12 -11
View File
@@ -2,6 +2,7 @@ package gsmaster
import (
"bamort/database"
"bamort/models"
"testing"
"github.com/stretchr/testify/assert"
@@ -17,7 +18,7 @@ func TestSkill_Create(t *testing.T) {
{
name: "valid skill",
skill: &Skill{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Test Skill",
Beschreibung: "Test Description",
Quelle: "Test Source",
@@ -63,7 +64,7 @@ func TestWeaponSkill_Create(t *testing.T) {
name: "valid weapon skill",
weaponSkill: &WeaponSkill{
Skill: Skill{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Test Weapon Skill",
Beschreibung: "Test Description",
Quelle: "Test Source",
@@ -118,7 +119,7 @@ func TestSkill_First(t *testing.T) {
{
name: "existing skill",
skill: &Skill{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Test Skill",
GameSystem: "midgard",
},
@@ -175,7 +176,7 @@ func TestSkill_FirstId(t *testing.T) {
{
name: "existing skill",
skill: &Skill{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Test Skill",
GameSystem: "midgard",
},
@@ -233,7 +234,7 @@ func TestSkill_Save(t *testing.T) {
{
name: "update existing skill",
skill: &Skill{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Test Skill",
Beschreibung: "Original Description",
GameSystem: "midgard",
@@ -289,7 +290,7 @@ func TestSkill_Delete(t *testing.T) {
{
name: "delete existing skill",
skill: &Skill{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Test Skill",
GameSystem: "midgard",
},
@@ -299,7 +300,7 @@ func TestSkill_Delete(t *testing.T) {
{
name: "delete non-existing skill",
skill: &Skill{
LookupList: LookupList{
LookupList: models.LookupList{
ID: 9999,
},
},
@@ -346,28 +347,28 @@ func TestSkill_GetSkillCategories(t *testing.T) {
// Create test skills with different categories
testSkills := []*Skill{
{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Skill1",
GameSystem: "midgard",
},
Category: "Category1",
},
{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Skill2",
GameSystem: "midgard",
},
Category: "Category2",
},
{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Skill3",
GameSystem: "midgard",
},
Category: "Category1", // Duplicate category
},
{
LookupList: LookupList{
LookupList: models.LookupList{
Name: "Skill4",
GameSystem: "midgard",
},
+7 -6
View File
@@ -2,6 +2,7 @@ package gsmaster
import (
"bamort/database"
"bamort/models"
"testing"
)
@@ -748,7 +749,7 @@ func TestGetSpellInfo(t *testing.T) {
// Create minimal test spell data for our test
testSpells := []Spell{
{
LookupList: LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Schlummer",
Beschreibung: "Test spell for GetSpellInfo",
@@ -758,7 +759,7 @@ func TestGetSpellInfo(t *testing.T) {
Category: "Beherrschen",
},
{
LookupList: LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Erkennen von Krankheit",
Beschreibung: "Test spell for GetSpellInfo",
@@ -768,7 +769,7 @@ func TestGetSpellInfo(t *testing.T) {
Category: "Dweomerzauber",
},
{
LookupList: LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Das Loblied",
Beschreibung: "Test spell for GetSpellInfo",
@@ -854,7 +855,7 @@ func TestCalcSpellLernCostWithRewards(t *testing.T) {
// Create minimal test spell data for our test
testSpells := []Spell{
{
LookupList: LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Schlummer",
Beschreibung: "Test spell for GetSpellInfo",
@@ -864,7 +865,7 @@ func TestCalcSpellLernCostWithRewards(t *testing.T) {
Category: "Beherrschen",
},
{
LookupList: LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Erkennen von Krankheit",
Beschreibung: "Test spell for GetSpellInfo",
@@ -874,7 +875,7 @@ func TestCalcSpellLernCostWithRewards(t *testing.T) {
Category: "Dweomer",
},
{
LookupList: LookupList{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Das Loblied",
Beschreibung: "Test spell for GetSpellInfo",
+7 -12
View File
@@ -2,6 +2,7 @@ package gsmaster
import (
"bamort/database"
"bamort/models"
"fmt"
"gorm.io/gorm"
@@ -9,14 +10,6 @@ import (
var dbPrefix = "gsm"
type LookupList struct {
ID uint `gorm:"primaryKey" json:"id"` //`gorm:"default:uuid_generate_v3()"` // db func
GameSystem string `gorm:"column:game_system;index;default:midgard" json:"game_system"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
Quelle string `json:"quelle"`
}
type LearnCost struct {
Stufe int `json:"stufe"`
LE int `json:"le"`
@@ -27,7 +20,7 @@ type LearnCost struct {
}
type Skill struct {
LookupList
models.LookupList
Initialwert int `gorm:"default:5" json:"initialwert"`
Bonuseigenschaft string `json:"bonuseigenschaft,omitempty"`
Improvable bool `gorm:"default:true" json:"improvable"`
@@ -41,7 +34,7 @@ type WeaponSkill struct {
}
type Spell struct {
LookupList
models.LookupList
Bonus int `json:"bonus"`
Stufe int `json:"level"`
AP string `gorm:"default:1" json:"ap"`
@@ -56,7 +49,7 @@ type Spell struct {
}
type Equipment struct {
LookupList
models.LookupList
Gewicht float64 `json:"gewicht"` // in kg
Wert float64 `json:"wert"` // in Gold
PersonalItem bool `gorm:"default:false" json:"personal_item"`
@@ -79,9 +72,10 @@ type Transportation struct {
}
type Believe struct {
LookupList
models.LookupList
}
/*
func (object *LookupList) Create() error {
gameSystem := "midgard"
object.GameSystem = gameSystem
@@ -124,6 +118,7 @@ func (object *LookupList) Save() error {
}
return nil
}
*/
func (object *Skill) TableName() string {
return dbPrefix + "_" + "skills"
+1 -1
View File
@@ -56,7 +56,7 @@ func createTestDataInLiveDB(t *testing.T, liveDB *gorm.DB) {
// Create test skill
testSkill := &gsmaster.Skill{
LookupList: gsmaster.LookupList{
LookupList: models.LookupList{
Name: "Test Skill",
Beschreibung: "A test skill",
},
+58
View File
@@ -1,5 +1,12 @@
package models
import (
"bamort/database"
"fmt"
"gorm.io/gorm"
)
type BamortBase struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
@@ -15,3 +22,54 @@ type Magisch struct {
Abw int `json:"abw"`
Ausgebrannt bool `json:"ausgebrannt"`
}
type LookupList struct {
ID uint `gorm:"primaryKey" json:"id"` //`gorm:"default:uuid_generate_v3()"` // db func
GameSystem string `gorm:"column:game_system;index;default:midgard" json:"game_system"`
Name string `json:"name"`
Beschreibung string `json:"beschreibung"`
Quelle string `json:"quelle"`
}
func (object *LookupList) Create() error {
gameSystem := "midgard"
object.GameSystem = gameSystem
err := database.DB.Transaction(func(tx *gorm.DB) error {
// Save the main character record
if err := tx.Create(&object).Error; err != nil {
return fmt.Errorf("failed to save Lookup: %w", err)
}
return nil
})
return err
}
func (object *LookupList) First(value string) error {
gameSystem := "midgard"
err := database.DB.First(&object, "game_system=? AND name!='Placeholder' AND name = ?", gameSystem, value).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *LookupList) FirstId(value uint) error {
gameSystem := "midgard"
err := database.DB.First(&object, "game_system=? AND name!='Placeholder' AND id = ?", gameSystem, value).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *LookupList) Save() error {
err := database.DB.Save(&object).Error
if err != nil {
// zauber found
return err
}
return nil
}