GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
1.6 KiB

package models
// Character is a common data model representing an RP character or NPC.
type Character struct {
ID string `json:"id" bson:"_id" db:"id"`
Nicks []string `json:"nicks" bson:"nicks" db:"nicks"`
Name string `json:"name" bson:"name" db:"name"`
ShortName string `json:"shortName" bson:"shortName" db:"short_name"`
Author string `json:"author" bson:"author" db:"author"`
Description string `json:"description" bson:"description" db:"description"`
}
func (character *Character) ApplyUpdate(update CharacterUpdate) {
if update.Name != nil {
character.Name = *update.Name
}
if update.ShortName != nil {
character.ShortName = *update.ShortName
}
if update.Description != nil {
character.Description = *update.Description
}
}
// Nick gets the character's nick.
func (character *Character) Nick() *string {
if len(character.Nicks[0]) == 0 {
return nil
}
return &character.Nicks[0]
}
// HasNick gets whether the character has the nick.
func (character *Character) HasNick(nick string) bool {
for i := range character.Nicks {
if nick == character.Nicks[i] {
return true
}
}
return false
}
// IsChangeObject is an interface implementation to identify it as a valid
// ChangeObject in GQL.
func (*Character) IsChangeObject() {
panic("this method is a dummy, and so is its caller")
}
// CharacterFilter is a filter for character listing.
type CharacterFilter struct {
IDs []string
Nicks []string
Names []string
Author *string
Search *string
Limit int
}
// CharacterUpdate is an update for characters.
type CharacterUpdate struct {
Name *string
ShortName *string
Description *string
}