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.
 
 

30 lines
729 B

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
}
// RemoveAllInLog removes all posts for the given log.
func RemoveAllInLog(log models.Log) error {
_, err := collection.RemoveAll(bson.M{"logId": log.ShortID})
return err
}