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

  1. package posts
  2. import (
  3. "git.aiterp.net/rpdata/api/models"
  4. "github.com/globalsign/mgo/bson"
  5. )
  6. // Remove removes a post, moving all subsequent post up one position
  7. func Remove(post models.Post) (models.Post, error) {
  8. mutex.Lock()
  9. defer mutex.Unlock()
  10. err := collection.RemoveId(post.ID)
  11. if err != nil {
  12. return models.Post{}, err
  13. }
  14. _, err = collection.UpdateAll(bson.M{"logId": post.LogID, "position": bson.M{"$gt": post.Position}}, bson.M{"$inc": bson.M{"position": -1}})
  15. if err != nil {
  16. return models.Post{}, err
  17. }
  18. return post, nil
  19. }
  20. // RemoveAllInLog removes all posts for the given log.
  21. func RemoveAllInLog(log models.Log) error {
  22. _, err := collection.RemoveAll(bson.M{"logId": log.ShortID})
  23. return err
  24. }