@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user