package posts import ( "git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo/bson" ) // Remove removes a post, moving all subsequent post up one position func Remove(post models.Post) (models.Post, error) { mutex.Lock() defer mutex.Unlock() err := collection.RemoveId(post.ID) if err != nil { return models.Post{}, err } _, err = collection.UpdateAll(bson.M{"logId": post.LogID, "position": bson.M{"$gt": post.Position}}, bson.M{"$inc": bson.M{"position": -1}}) if err != nil { return models.Post{}, err } return post, nil }