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.
24 lines
553 B
24 lines
553 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
|
|
}
|