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.
|
|
package mutations
import ( "context"
"git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/session" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/character" )
// CharacterEditInput is args for mutation addCharacterNick/removeCharacterNick
type CharacterEditInput struct { ID string Name *string ShortName *string Description *string }
// EditCharacter resolves the editCharacter mutation
func (r *MutationResolver) EditCharacter(ctx context.Context, args struct{ Input *CharacterEditInput }) (*types.CharacterResolver, error) { input := args.Input
user := session.FromContext(ctx).User() if user == nil || !user.Permitted("member") { return nil, ErrUnauthorized }
character, err := character.FindID(input.ID) if err != nil { return nil, err } if character.Author != user.ID && !user.Permitted("character.edit") { return nil, ErrPermissionDenied }
name := "" if input.Name != nil { name = *input.Name }
shortName := "" if input.ShortName != nil { shortName = *input.ShortName }
description := "" if input.Description != nil { description = *input.Description }
err = character.Edit(name, shortName, description) if err != nil { return nil, err }
go change.Submit("Character", "edit", user.ID, character.ID, map[string]interface{}{ "name": character.Name, "shortName": character.ShortName, "description": character.Description, })
return &types.CharacterResolver{C: character}, nil }
|