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 stories
import ( "errors"
"git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo/bson" )
// ErrTagAlreadyExists is an error returned by Story.AddTag
var ErrTagAlreadyExists = errors.New("Tag already exists on story")
// AddTag adds a tag to the story. It returns ErrTagAlreadyExists if the tag is already there
func AddTag(story models.Story, tag models.Tag) (*models.Story, error) { for i := range story.Tags { if story.Tags[i].Equal(tag) { return nil, ErrTagAlreadyExists } }
err := collection.UpdateId(story.ID, bson.M{"$push": bson.M{"tags": tag}}) if err != nil { return nil, err }
story.Tags = append(story.Tags, tag)
return &story, nil }
|