Struct generalisation
This commit is contained in:
+79
-109
@@ -1,18 +1,37 @@
|
||||
package models
|
||||
|
||||
import "bamort/database"
|
||||
import (
|
||||
"bamort/database"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
UserID uint `gorm:"primaryKey"`
|
||||
Username string `gorm:"unique"`
|
||||
PasswordHash string
|
||||
Email string `gorm:"unique"`
|
||||
UserID uint `gorm:"primaryKey" json:"id"`
|
||||
Username string `gorm:"unique" json:"name"`
|
||||
PasswordHash string `json:"password"`
|
||||
Email string `gorm:"unique" json:"email"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type BamortBase struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
type BamortCharTrait struct {
|
||||
BamortBase
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
}
|
||||
|
||||
type BamortCharTraitMaxVal struct {
|
||||
BamortCharTrait
|
||||
Max int `json:"max"`
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
type Char struct {
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
ImportID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
BamortBase
|
||||
|
||||
Rasse string `json:"rasse"`
|
||||
Typ string `json:"typ"`
|
||||
Alter int `json:"alter"`
|
||||
@@ -22,36 +41,35 @@ type Char struct {
|
||||
Gewicht int `json:"gewicht"`
|
||||
Glaube string `json:"glaube"`
|
||||
Hand string `json:"hand"`
|
||||
Fertigkeiten []Fertigkeit `gorm:"foreignKey:CharacterID" json:"fertigkeiten"`
|
||||
Zauber []Zauber `gorm:"foreignKey:CharacterID" json:"zauber"`
|
||||
Lp Lp `gorm:"foreignKey:CharacterID" json:"lp"`
|
||||
Eigenschaften []Eigenschaft `gorm:"foreignKey:CharacterID" json:"eigenschaften"`
|
||||
Merkmale Merkmale `gorm:"foreignKey:CharacterID" json:"merkmale"`
|
||||
Bennies Bennies `gorm:"foreignKey:CharacterID" json:"bennies"`
|
||||
Gestalt Gestalt `gorm:"foreignKey:CharacterID" json:"gestalt"`
|
||||
Ap Ap `gorm:"foreignKey:CharacterID" json:"ap"`
|
||||
B B `gorm:"foreignKey:CharacterID" json:"b"`
|
||||
Erfahrungsschatz Erfahrungsschatz `gorm:"foreignKey:CharacterID" json:"erfahrungsschatz"`
|
||||
Merkmale Merkmale `gorm:"foreignKey:CharacterID" json:"merkmale"`
|
||||
Fertigkeiten []Fertigkeit `gorm:"foreignKey:CharacterID" json:"fertigkeiten"`
|
||||
Zauber []Zauber `gorm:"foreignKey:CharacterID" json:"zauber"`
|
||||
Eigenschaften []Eigenschaft `gorm:"foreignKey:CharacterID" json:"eigenschaften"`
|
||||
Transportmittel []Transportation `gorm:"foreignKey:CharacterID" json:"transportmittel"`
|
||||
Ausruestung []Ausruestung `gorm:"foreignKey:CharacterID" json:"ausruestung"`
|
||||
Behaeltnisse []Behaeltniss `gorm:"foreignKey:CharacterID" json:"behaeltnisse"`
|
||||
Waffen []Waffe `gorm:"foreignKey:CharacterID" json:"waffen"`
|
||||
Waffenfertigkeiten []Waffenfertigkeit `gorm:"foreignKey:CharacterID" json:"waffenfertigkeiten"`
|
||||
Spezialisierung database.StringArray `gorm:"type:TEXT" json:"spezialisierung"`
|
||||
Bennies Bennies `gorm:"foreignKey:CharacterID" json:"bennies"`
|
||||
Erfahrungsschatz Erfahrungsschatz `gorm:"foreignKey:CharacterID" json:"erfahrungsschatz"`
|
||||
Image string `json:"image,omitempty"`
|
||||
}
|
||||
|
||||
// Au, Gs, Gw ,In, Ko, Pa, St, Wk, Zt
|
||||
type Eigenschaft struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Name string `json:"name"`
|
||||
Value int `json:"value"`
|
||||
BamortCharTrait
|
||||
Name string `json:"name"`
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
type Ausruestung struct {
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
ImportID string `json:"id"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
BamortCharTrait
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
|
||||
Name string `json:"name"`
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
Anzahl int `json:"anzahl"`
|
||||
@@ -63,42 +81,32 @@ type Ausruestung struct {
|
||||
}
|
||||
|
||||
type Fertigkeit struct {
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
ImportID string `json:"id"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Name string `json:"name"`
|
||||
BamortCharTrait
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
Fertigkeitswert int `json:"fertigkeitswert"`
|
||||
Bonus int `json:"bonus,omitempty"`
|
||||
Pp int `json:"pp,omitempty"`
|
||||
Quelle string `json:"quelle"`
|
||||
Bemerkung string `json:"bemerkung"`
|
||||
}
|
||||
|
||||
type Waffenfertigkeit struct {
|
||||
Fertigkeit
|
||||
}
|
||||
|
||||
type Zauber struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
BamortCharTrait
|
||||
ID uint `gorm:"primaryKey"`
|
||||
|
||||
Name string `json:"name"`
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
Bonus int `json:"bonus"`
|
||||
Quelle string `json:"quelle"`
|
||||
}
|
||||
|
||||
type Waffenfertigkeit struct {
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
ImportID string `json:"id"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Name string `json:"name"`
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
Bonus int `json:"bonus"`
|
||||
Fertigkeitswert int `json:"fertigkeitswert"`
|
||||
Pp int `json:"pp"`
|
||||
Quelle string `json:"quelle"`
|
||||
}
|
||||
|
||||
type Waffe struct {
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
ImportID string `json:"id"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
BamortCharTrait
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
|
||||
Name string `json:"name"`
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
Abwb int `json:"abwb"`
|
||||
@@ -113,60 +121,44 @@ type Waffe struct {
|
||||
}
|
||||
|
||||
type Merkmale struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Augenfarbe string `json:"augenfarbe"`
|
||||
Haarfarbe string `json:"haarfarbe"`
|
||||
Sonstige string `json:"sonstige"`
|
||||
}
|
||||
|
||||
type Lp struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Max int `json:"max"`
|
||||
Value int `json:"value"`
|
||||
BamortCharTrait
|
||||
Augenfarbe string `json:"augenfarbe"`
|
||||
Haarfarbe string `json:"haarfarbe"`
|
||||
Sonstige string `json:"sonstige"`
|
||||
Breite string `json:"breite"`
|
||||
Groesse string `json:"groesse"`
|
||||
}
|
||||
|
||||
type Gestalt struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Breite string `json:"breite"`
|
||||
Groesse string `json:"groesse"`
|
||||
BamortCharTrait
|
||||
}
|
||||
|
||||
type Erfahrungsschatz struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
type Eigenschaften struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Au int `json:"au"`
|
||||
Gs int `json:"gs"`
|
||||
Gw int `json:"gw"`
|
||||
In int `json:"in"`
|
||||
Ko int `json:"ko"`
|
||||
Pa int `json:"pa"`
|
||||
St int `json:"st"`
|
||||
Wk int `json:"wk"`
|
||||
Zt int `json:"zt"`
|
||||
BamortCharTrait
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
type Bennies struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Gg int `json:"gg"`
|
||||
Gp int `json:"gp"`
|
||||
Sg int `json:"sg"`
|
||||
BamortCharTrait
|
||||
Gg int `json:"gg"`
|
||||
Gp int `json:"gp"`
|
||||
Sg int `json:"sg"`
|
||||
}
|
||||
|
||||
type Lp struct {
|
||||
BamortCharTraitMaxVal
|
||||
}
|
||||
|
||||
type Ap struct {
|
||||
BamortCharTraitMaxVal
|
||||
}
|
||||
|
||||
type B struct {
|
||||
BamortCharTraitMaxVal
|
||||
}
|
||||
|
||||
type Behaeltniss struct {
|
||||
ID uint `gorm:"primaryKey" json:"dbid"`
|
||||
ImportID string `json:"id"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Name string `json:"name"`
|
||||
BamortCharTrait
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
//BeinhaltetIn any `json:"beinhaltet_in"`
|
||||
Gewicht float64 `json:"gewicht"`
|
||||
@@ -176,30 +168,8 @@ type Behaeltniss struct {
|
||||
Volumen float64 `json:"volumen"`
|
||||
}
|
||||
|
||||
type Ap struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Max int `json:"max"`
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
type B struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Max int `json:"max"`
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
type Transportation struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CharacterID uint `gorm:"index" json:"character_id"`
|
||||
Name string `json:"name"`
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
//BeinhaltetIn any `json:"beinhaltet_in"`
|
||||
Gewicht int `json:"gewicht"`
|
||||
Tragkraft float64 `json:"tragkraft"`
|
||||
Wert float64 `json:"wert"`
|
||||
Magisch MagischTransport `gorm:"foreignKey:TransportationID" json:"magisch"`
|
||||
Behaeltniss
|
||||
//Magisch Magisch `gorm:"polymorphic:Item;polymorphicValue:Transportmittel" json:"magisch"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"bamort/character"
|
||||
"bamort/database"
|
||||
"bamort/models"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -34,94 +30,96 @@ func initTestDB4Char() *gorm.DB {
|
||||
return db
|
||||
}
|
||||
|
||||
/*
|
||||
func TestSaveCharacterToDB(t *testing.T) {
|
||||
// Setup test database
|
||||
testDB := initTestDB4Char()
|
||||
database.DB = testDB // Assign test DB to global DB
|
||||
|
||||
// Define a sample character for testing
|
||||
char := &models.Char{
|
||||
Name: "Test Character",
|
||||
Rasse: "Elf",
|
||||
Typ: "Mage",
|
||||
Alter: 100,
|
||||
Anrede: "Lord",
|
||||
Grad: 5,
|
||||
Groesse: 180,
|
||||
Gewicht: 70,
|
||||
Glaube: "None",
|
||||
Hand: "Right",
|
||||
Eigenschaften: []models.Eigenschaft{
|
||||
{Name: "Au", Value: 50},
|
||||
{Name: "St", Value: 80},
|
||||
{Name: "Zt", Value: 100},
|
||||
},
|
||||
Fertigkeiten: []models.Fertigkeit{
|
||||
{Name: "Stehlen", Beschreibung: "jemandem etwas wegnehmen ohne das der es merkt", Fertigkeitswert: 6},
|
||||
{Name: "Geländelauf", Beschreibung: "Lauf um Hindernisse herum", Fertigkeitswert: 12},
|
||||
},
|
||||
Zauber: []models.Zauber{
|
||||
{Name: "Fireball", Beschreibung: "Cast a fireball", Bonus: 0, Quelle: "Ark 20"},
|
||||
},
|
||||
Lp: models.Lp{
|
||||
Max: 100,
|
||||
Value: 80,
|
||||
},
|
||||
Merkmale: models.Merkmale{
|
||||
Augenfarbe: "Blau",
|
||||
Haarfarbe: "Blonde",
|
||||
Sonstige: "Scar on the left cheek",
|
||||
},
|
||||
Bennies: models.Bennies{
|
||||
Gg: 1,
|
||||
Gp: 0,
|
||||
Sg: 2,
|
||||
},
|
||||
Gestalt: models.Gestalt{
|
||||
Breite: "schmal",
|
||||
Groesse: "klein",
|
||||
},
|
||||
Ap: models.Ap{
|
||||
Max: 50,
|
||||
Value: 40,
|
||||
},
|
||||
B: models.B{
|
||||
|
||||
Max: 25,
|
||||
Value: 20,
|
||||
},
|
||||
Erfahrungsschatz: models.Erfahrungsschatz{
|
||||
Value: 2768,
|
||||
},
|
||||
Transportmittel: []models.Transportation{
|
||||
{Name: "Karren",
|
||||
Beschreibung: "ein Karren",
|
||||
Gewicht: 100, Tragkraft: 300, Wert: 55,
|
||||
Magisch: models.MagischTransport{IstMagisch: true, Abw: 30, Ausgebrannt: false},
|
||||
},
|
||||
},
|
||||
Ausruestung: []models.Ausruestung{
|
||||
{Name: "Staff", Beschreibung: "Magic Staff", Anzahl: 1, Gewicht: 2.5, Wert: 500,
|
||||
Magisch: models.MagischAusruestung{IstMagisch: true, Abw: 10, Ausgebrannt: false},
|
||||
},
|
||||
},
|
||||
Behaeltnisse: []models.Behaeltniss{
|
||||
{Name: "Backpack", Beschreibung: "Leather backpack",
|
||||
Gewicht: 1.5, Tragkraft: 10, Volumen: 20, Wert: 50,
|
||||
//Magisch: MagischBehaelter{IstMagisch: false},
|
||||
},
|
||||
},
|
||||
Waffen: []models.Waffe{
|
||||
{Name: "Schwert", Beschreibung: "Ein schwert", Abwb: 0, Anb: 0, Gewicht: 1.5, NameFuerSpezialisierung: "Schwert", Schb: 0, Wert: 3,
|
||||
Magisch: models.MagischWaffe{IstMagisch: false}},
|
||||
},
|
||||
Waffenfertigkeiten: []models.Waffenfertigkeit{
|
||||
{Name: "Einhandschlagwaffe", Beschreibung: "z.B. für Kurzschwerter", Bonus: 0,
|
||||
Fertigkeitswert: 12, Pp: 1, Quelle: "Kod 256"},
|
||||
},
|
||||
Spezialisierung: []string{
|
||||
"Bogen", "Streitaxt",
|
||||
},
|
||||
char := &models.Char{}
|
||||
char.Name= "Test Character"
|
||||
char.Rasse = "Elf"
|
||||
char.Typ = "Mage"
|
||||
char.Alter = 100
|
||||
char.Anrede = "Lord"
|
||||
char.Grad = 5
|
||||
char.Groesse = 180
|
||||
char.Gewicht = 70
|
||||
char.Glaube = "None"
|
||||
char.Hand = "Right"
|
||||
char.Lp.Max=100
|
||||
char.Lp.Value=80
|
||||
char.Eigenschaften = []models.Eigenschaft{
|
||||
{Name = "Au", Value = 50}
|
||||
{Name = "St", Value = 80}
|
||||
{Name = "Zt", Value = 100}
|
||||
}
|
||||
char.Fertigkeiten = []models.Fertigkeit{
|
||||
{Name = "Stehlen", Beschreibung = "jemandem etwas wegnehmen ohne das der es merkt", Fertigkeitswert = 6}
|
||||
{Name = "Geländelauf", Beschreibung = "Lauf um Hindernisse herum", Fertigkeitswert = 12}
|
||||
}
|
||||
char.Zauber = []models.Zauber{
|
||||
{Name = "Fireball", Beschreibung = "Cast a fireball", Bonus = 0, Quelle = "Ark 20"}
|
||||
}
|
||||
char.Lp = models.Lp{
|
||||
Max = 100
|
||||
Value = 80
|
||||
}
|
||||
char.Merkmale = models.Merkmale{
|
||||
Augenfarbe = "Blau"
|
||||
Haarfarbe = "Blonde"
|
||||
Sonstige = "Scar on the left cheek"
|
||||
}
|
||||
char.Bennies = models.Bennies{
|
||||
Gg = 1
|
||||
Gp = 0
|
||||
Sg = 2
|
||||
}
|
||||
char.Gestalt = models.Gestalt{
|
||||
Breite = "schmal"
|
||||
Groesse = "klein"
|
||||
}
|
||||
char.Ap = models.Ap{
|
||||
Max = 50
|
||||
Value = 40
|
||||
}
|
||||
char.B = models.B{
|
||||
Max = 25
|
||||
Value = 20
|
||||
}
|
||||
char.Erfahrungsschatz = models.Erfahrungsschatz{
|
||||
Value = 2768
|
||||
}
|
||||
char.Transportmittel = []models.Transportation{
|
||||
{Name = "Karren"
|
||||
Beschreibung = "ein Karren"
|
||||
Gewicht = 100, Tragkraft = 300, Wert = 55
|
||||
Magisch = models.MagischTransport{IstMagisch = true, Abw = 30, Ausgebrannt = false}
|
||||
}
|
||||
}
|
||||
char.Ausruestung = []models.Ausruestung{
|
||||
{Name = "Staff", Beschreibung = "Magic Staff", Anzahl = 1, Gewicht = 2.5, Wert = 500
|
||||
Magisch = models.MagischAusruestung{IstMagisch = true, Abw = 10, Ausgebrannt = false}
|
||||
}
|
||||
}
|
||||
char.Behaeltnisse = []models.Behaeltniss{
|
||||
{Name = "Backpack", Beschreibung = "Leather backpack"
|
||||
Gewicht = 1.5, Tragkraft = 10, Volumen = 20, Wert = 50
|
||||
//Magisch = MagischBehaelter{IstMagisch = false}
|
||||
}
|
||||
}
|
||||
char.Waffen = []models.Waffe{
|
||||
{Name = "Schwert", Beschreibung = "Ein schwert", Abwb = 0, Anb = 0, Gewicht = 1.5, NameFuerSpezialisierung = "Schwert", Schb = 0, Wert = 3
|
||||
Magisch = models.MagischWaffe{IstMagisch = false}}
|
||||
}
|
||||
char.Waffenfertigkeiten = []models.Waffenfertigkeit{
|
||||
{Name = "Einhandschlagwaffe", Beschreibung = "z.B. für Kurzschwerter", Bonus = 0
|
||||
Fertigkeitswert = 12, Pp = 1, Quelle = "Kod 256"}
|
||||
}
|
||||
char.Spezialisierung = []string{
|
||||
"Bogen", "Streitaxt"
|
||||
}
|
||||
}
|
||||
|
||||
//fmt.Println(char)
|
||||
@@ -174,3 +172,4 @@ func TestSaveCharacterToDB(t *testing.T) {
|
||||
assert.Equal(t, "Bogen", savedChar.Spezialisierung[0])
|
||||
assert.Equal(t, "Streitaxt", savedChar.Spezialisierung[1])
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user