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.

28 lines
697 B

  1. package chapters
  2. import (
  3. "time"
  4. "git.aiterp.net/rpdata/api/models"
  5. "github.com/globalsign/mgo/bson"
  6. )
  7. // Move updates the chapter, moving it to the given story.
  8. func Move(chapter models.Chapter, story models.Story) (models.Chapter, error) {
  9. now := time.Now()
  10. err := collection.UpdateId(chapter.ID, bson.M{"$set": bson.M{"editedDate": now, "storyId": story.ID}})
  11. if err != nil {
  12. return models.Chapter{}, err
  13. }
  14. chapter.EditedDate = now
  15. if chapter.CreatedDate.After(story.UpdatedDate) {
  16. if err := storyCollection.UpdateId(story.ID, bson.M{"$set": bson.M{"updatedDate": chapter.CreatedDate}}); err == nil {
  17. story.UpdatedDate = chapter.CreatedDate
  18. }
  19. }
  20. return chapter, nil
  21. }