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.
27 lines
613 B
27 lines
613 B
package characters
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"git.aiterp.net/rpdata/api/models"
|
|
"github.com/globalsign/mgo/bson"
|
|
)
|
|
|
|
// AddNick adds a nick to a characters
|
|
func AddNick(character models.Character, nick string) (models.Character, error) {
|
|
for i := range character.Nicks {
|
|
if strings.EqualFold(character.Nicks[i], nick) {
|
|
return models.Character{}, errors.New("Nick already exists")
|
|
}
|
|
}
|
|
|
|
err := collection.UpdateId(character.ID, bson.M{"$push": bson.M{"nicks": nick}})
|
|
if err != nil {
|
|
return models.Character{}, err
|
|
}
|
|
|
|
character.Nicks = append(character.Nicks, nick)
|
|
|
|
return character, nil
|
|
}
|