5 changed files with 175 additions and 0 deletions
			
			
		- 
					107graph2/queries/character.go
 - 
					16graph2/schema/root.gql
 - 
					7graph2/schema/types/Character.gql
 - 
					32models/characters/edit.go
 - 
					13models/characters/remove.go
 
@ -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 | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue