Browse Source

Added graphql for story, started on resolvers, added finders for story

1.0
Gisle Aune 7 years ago
parent
commit
5a2b8ef1c5
  1. 41
      model/story/story.go
  2. 1
      resolver/story.go
  3. 23
      schema/types/chapter.graphql
  4. 51
      schema/types/story.graphql
  5. 27
      schema/types/tag.graphql

41
model/story/story.go

@ -179,6 +179,47 @@ func New(name, author, category string, listed, open bool, tags []Tag, createdDa
return story, nil 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 // makeStoryID makes a random story ID that's 16 characters long
func makeStoryID() string { func makeStoryID() string {
result := "S" result := "S"

1
resolver/story.go

@ -0,0 +1 @@
package resolver

23
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!
}

51
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
}

27
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
}
Loading…
Cancel
Save