diff --git a/model/story/story.go b/model/story/story.go index 4cffa71..844572b 100644 --- a/model/story/story.go +++ b/model/story/story.go @@ -179,6 +179,47 @@ func New(name, author, category string, listed, open bool, tags []Tag, createdDa return story, nil } +// FindID finds a story by ID +func FindID(id string) (Story, error) { + story := Story{} + err := storyCollection.FindId(id).One(&story) + + return story, err +} + +// List lists stories by any non-zero criteria passed with it. +func List(author string, tags []Tag, earliest, latest time.Time, limit int) ([]Story, error) { + query := bson.M{} + + if author != "" { + query["author"] = author + } + + if len(tags) > 0 { + query["tags"] = bson.M{"$in": tags} + } + + if !earliest.IsZero() && !latest.IsZero() { + query["fictionalDate"] = bson.M{ + "$gte": earliest, + "$lt": latest, + } + } else if !latest.IsZero() { + query["fictionalDate"] = bson.M{ + "$lt": latest, + } + } else if !earliest.IsZero() { + query["fictionalDate"] = bson.M{ + "$gte": earliest, + } + } + + stories := make([]Story, 0, 128) + err := storyCollection.Find(query).Limit(limit).One(&stories) + + return stories, err +} + // makeStoryID makes a random story ID that's 16 characters long func makeStoryID() string { result := "S" diff --git a/resolver/story.go b/resolver/story.go new file mode 100644 index 0000000..d356a7b --- /dev/null +++ b/resolver/story.go @@ -0,0 +1 @@ +package resolver diff --git a/schema/types/chapter.graphql b/schema/types/chapter.graphql new file mode 100644 index 0000000..f7a796b --- /dev/null +++ b/schema/types/chapter.graphql @@ -0,0 +1,23 @@ +# A Chapter is the main content body of a story. +type Chapter { + # The chapter's ID + id: String! + + # The chapter's title + title: String! + + # The chapter's author + author: String! + + # The chapter's source + source: String! + + # When the chapter was posted initialy + createdDate: String! + + # The in-universe date and time of the chapter + fictionalDate: String! + + # The date of edit. + editedDate: String! +} \ No newline at end of file diff --git a/schema/types/story.graphql b/schema/types/story.graphql new file mode 100644 index 0000000..76e7aaf --- /dev/null +++ b/schema/types/story.graphql @@ -0,0 +1,51 @@ +# A Story is a piece of content that, unlike wiki articles, are not something that should be ordered by time instead of title. It can +# contain multiple chapters by one or more autohrs +type Story { + # The story's ID + id: String! + + # The story's name, which will show up in the lists. + name: String! + + # The story's author + author: String! + + # Whether other users may add/edit chapters to the story. + open: Boolean! + + # Whether users without a direct link can find this story. + listed: Boolean! + + # The category of the story + category: StoryCategory! + + # The tags for this tory + tags: [Tags!]! + + # The date the story was created (RFC3339 format). + createdDate: String! + + # The date the story is set in (RFC3339 format). + fictionalDate: String! + + # The date of the last major update to the story (RFC3339 format). This being bumped means a new chapter has been added. + fictionalDate: String! +} + +# Possible values for Story.category +enum StoryCategory { + # Description and content of a document or item + Document + + # News stories + News + + # Information about something going on in the background that may or may not inform RP + Background + + # General information + Info + + # A short story + Story +} \ No newline at end of file diff --git a/schema/types/tag.graphql b/schema/types/tag.graphql new file mode 100644 index 0000000..860dd47 --- /dev/null +++ b/schema/types/tag.graphql @@ -0,0 +1,27 @@ +# A Tag is a means of associating stories that have details in common with one another. +type Tag { + # The tag's kind + kind: TagKind! + + # The tag's name + name: String! +} + +# Allowed values for Tag.kind +enum TagKind { + # An organization is a catch all term for in-universe corporations, teams, groups, cults, forces, etc... + Organization + + # A character tag should have the exact full name of the character. + Character + + # A location is anything from a planet to an establishment. This may overlap with an organization, and if so, both + # kinds of tags should be used. + Location + + # An event is a plot or a part of a plot. + Event + + # None of the above, but it does still tie multiple stories together. The new story/chapter format may obsolete this tag kind. + Series +} \ No newline at end of file