Added chapter query and Chapter type resolvers, added functions to get chapters
This commit is contained in:
@@ -61,6 +61,25 @@ func (chapter *Chapter) Remove() error {
|
||||
return chapterCollection.RemoveId(chapter.ID)
|
||||
}
|
||||
|
||||
// FindChapterID finds a chapter by its own ID
|
||||
func FindChapterID(id string) (Chapter, error) {
|
||||
chapter := Chapter{}
|
||||
err := chapterCollection.FindId(id).One(&chapter)
|
||||
|
||||
return chapter, err
|
||||
}
|
||||
|
||||
// ListChapterStoryID lists all chapters for the story ID
|
||||
func ListChapterStoryID(storyID string) ([]Chapter, error) {
|
||||
chapters := make([]Chapter, 0, 8)
|
||||
err := chapterCollection.Find(bson.M{"storyId": storyID}).Sort("createdDate").One(&chapters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return chapters, nil
|
||||
}
|
||||
|
||||
// makeChapterID makes a random chapter ID that's 24 characters long
|
||||
func makeChapterID() string {
|
||||
result := "SC"
|
||||
|
||||
@@ -124,6 +124,11 @@ func (story *Story) Remove() error {
|
||||
return storyCollection.RemoveId(story.ID)
|
||||
}
|
||||
|
||||
// Chapters calls ListChapterStoryID with the story's ID:
|
||||
func (story *Story) Chapters() ([]Chapter, error) {
|
||||
return ListChapterStoryID(story.ID)
|
||||
}
|
||||
|
||||
// AddChapter adds a chapter to the story. This does not enforce the `Open` setting, but it will log a warning if it
|
||||
// occurs
|
||||
func (story *Story) AddChapter(title, author, source string, createdDate, finctionalDate time.Time) (Chapter, error) {
|
||||
|
||||
Reference in New Issue
Block a user