diff options
| author | Bobby <[email protected]> | 2026-03-29 22:52:46 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-29 22:52:46 +0530 |
| commit | 9eb9b7f4bd552a641235764f66483e1f940fcfd9 (patch) | |
| tree | da520b923b5e6758d5457b6233dd6671fc640914 /nexus/models/character.go | |
| parent | 65a143a0871c35989b7c7ea6723d39a0585c089e (diff) | |
| download | echoes-of-vaelun-main.tar.xz echoes-of-vaelun-main.zip | |
Diffstat (limited to 'nexus/models/character.go')
| -rw-r--r-- | nexus/models/character.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nexus/models/character.go b/nexus/models/character.go new file mode 100644 index 0000000..b44cf87 --- /dev/null +++ b/nexus/models/character.go @@ -0,0 +1,51 @@ +package models
+
+import (
+ "nexus/types/character"
+ "strings"
+
+ "github.com/google/uuid"
+ "gorm.io/gorm"
+)
+
+type Character struct {
+ gorm.Model
+ ID uuid.UUID `gorm:"type:uuid;primaryKey"`
+ AccountID uuid.UUID `gorm:"type:uuid;not null;index"`
+ RealmID uuid.UUID `gorm:"type:uuid;not null;index"`
+ Name string `gorm:"not null"`
+ Race string `gorm:"not null"`
+ StartingKingdom string `gorm:"not null"`
+ Account Account `gorm:"foreignKey:AccountID"`
+ Realm Realm `gorm:"foreignKey:RealmID"`
+}
+
+func (self *Character) BeforeCreate(tx *gorm.DB) error {
+ if self.ID == uuid.Nil {
+ self.ID = uuid.New()
+ }
+ self.Name = strings.TrimSpace(self.Name)
+ if self.Name == "" {
+ return ErrCharacterNameRequired
+ }
+ return nil
+}
+
+func (self *Character) BeforeUpdate(tx *gorm.DB) error {
+ self.Name = strings.TrimSpace(self.Name)
+ if self.Name == "" {
+ return ErrCharacterNameRequired
+ }
+ return nil
+}
+
+func (self *Character) ToResponse() character.Response {
+ return character.Response{
+ ID: self.ID,
+ Name: self.Name,
+ Race: self.Race,
+ StartingKingdom: self.StartingKingdom,
+ RealmID: self.RealmID,
+ CreatedAt: self.CreatedAt,
+ }
+}
|
