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

  1. package models
  2. // Character is a common data model representing an RP character or NPC.
  3. type Character struct {
  4. ID string `json:"id" bson:"_id" db:"id"`
  5. Nicks []string `json:"nicks" bson:"nicks" db:"nicks"`
  6. Name string `json:"name" bson:"name" db:"name"`
  7. ShortName string `json:"shortName" bson:"shortName" db:"short_name"`
  8. Author string `json:"author" bson:"author" db:"author"`
  9. Description string `json:"description" bson:"description" db:"description"`
  10. }
  11. func (character *Character) ApplyUpdate(update CharacterUpdate) {
  12. if update.Name != nil {
  13. character.Name = *update.Name
  14. }
  15. if update.ShortName != nil {
  16. character.ShortName = *update.ShortName
  17. }
  18. if update.Description != nil {
  19. character.Description = *update.Description
  20. }
  21. }
  22. // Nick gets the character's nick.
  23. func (character *Character) Nick() *string {
  24. if len(character.Nicks[0]) == 0 {
  25. return nil
  26. }
  27. return &character.Nicks[0]
  28. }
  29. // HasNick gets whether the character has the nick.
  30. func (character *Character) HasNick(nick string) bool {
  31. for i := range character.Nicks {
  32. if nick == character.Nicks[i] {
  33. return true
  34. }
  35. }
  36. return false
  37. }
  38. // IsChangeObject is an interface implementation to identify it as a valid
  39. // ChangeObject in GQL.
  40. func (*Character) IsChangeObject() {
  41. panic("this method is a dummy, and so is its caller")
  42. }
  43. // CharacterFilter is a filter for character listing.
  44. type CharacterFilter struct {
  45. IDs []string
  46. Nicks []string
  47. Names []string
  48. Author *string
  49. Search *string
  50. Limit int
  51. }
  52. // CharacterUpdate is an update for characters.
  53. type CharacterUpdate struct {
  54. Name *string
  55. ShortName *string
  56. Description *string
  57. }