graph2: Added character mutations
the build failed

This commit is contained in:
2018-10-01 22:05:12 +02:00
parent fc488b938d
commit 2317f66920
5 changed files with 175 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package characters
import (
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo/bson"
)
// Edit sets the fields of metadata. Only non-empty and different fields will be set in the
// database, preventing out of order edits to two fields from conflicting
func Edit(character models.Character, name, shortName, description *string) (models.Character, error) {
changes := bson.M{}
if name != nil && *name != character.Name {
character.Name = *name
changes["name"] = *name
}
if shortName != nil && *shortName != character.ShortName {
character.ShortName = *shortName
changes["shortName"] = *shortName
}
if description != nil && *description != character.Description {
character.Description = *description
changes["description"] = *description
}
err := collection.UpdateId(character.ID, changes)
if err != nil {
return models.Character{}, err
}
return character, nil
}
+13
View File
@@ -0,0 +1,13 @@
package characters
import "git.aiterp.net/rpdata/api/models"
// Remove removes a character, returning it if it succeeds
func Remove(character models.Character) (models.Character, error) {
err := collection.RemoveId(character.ID)
if err != nil {
return models.Character{}, err
}
return character, nil
}