This commit is contained in:
2025-11-16 18:46:22 +08:00
parent 9d9a2545f9
commit 46a19c12fa
12 changed files with 101 additions and 101 deletions

47
server/model/character.go Normal file
View File

@@ -0,0 +1,47 @@
package model
type Character struct {
ID uint `gorm:"primaryKey;autoIncrement"`
Name string `gorm:"type:varchar(100);not null"`
Alias []string `gorm:"serializer:json"`
CV string `gorm:"type:varchar(100)"`
Role string `gorm:"type:varchar(20);default:primary"`
ImageID uint
ResourceID uint
Image *Image `gorm:"foreignKey:ImageID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}
type CharacterView struct {
Id uint `json:"id"`
Name string `json:"name"`
Alias []string `json:"alias"`
CV string `json:"cv"`
Role string `json:"role"`
Image uint `json:"image"`
}
func (c *Character) ToView() *CharacterView {
return &CharacterView{
Id: c.ID,
Name: c.Name,
Alias: c.Alias,
CV: c.CV,
Role: c.Role,
Image: c.ImageID,
}
}
func (c *Character) Equal(other *Character) bool {
if c.Name != other.Name || c.CV != other.CV || c.Role != other.Role || c.ImageID != other.ImageID {
return false
}
if len(c.Alias) != len(other.Alias) {
return false
}
for i := range c.Alias {
if c.Alias[i] != other.Alias[i] {
return false
}
}
return true
}