diff --git a/graphql/resolver/queries/stories.go b/graphql/resolver/queries/stories.go index 240c2de..df74268 100644 --- a/graphql/resolver/queries/stories.go +++ b/graphql/resolver/queries/stories.go @@ -19,6 +19,7 @@ type StoriesArg struct { } EarliestFictionalDate *string LatestFictionalDate *string + Category *string Limit *int32 Open *bool Unlisted *bool @@ -34,6 +35,8 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types author = *filter.Author } + category := filter.Category + tags := make([]story.Tag, 0, 8) if filter != nil && filter.Tags != nil { for _, tagInput := range *filter.Tags { @@ -82,7 +85,7 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types limit = int(*filter.Limit) } - stories, err := story.List(author, tags, earliest, latest, unlisted, open, limit) + stories, err := story.List(author, category, tags, earliest, latest, unlisted, open, limit) if err != nil { return nil, err } diff --git a/graphql/schema/types/story.graphql b/graphql/schema/types/story.graphql index a9928f0..e8ddfc7 100644 --- a/graphql/schema/types/story.graphql +++ b/graphql/schema/types/story.graphql @@ -40,6 +40,9 @@ input StoriesFilter { # What author to query for author: String + # What category to query for + category: StoryCategory + # What tags to query for tags: [TagInput!] @@ -131,18 +134,18 @@ input StoryTagRemoveInput { # Possible values for Story.category enum StoryCategory { - # Description and content of a document or item - Document + # General information + Info # News stories News + # Description and content of a document or item + Document + # 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/model/story/story.go b/model/story/story.go index 345cdb1..0c99d1f 100644 --- a/model/story/story.go +++ b/model/story/story.go @@ -193,13 +193,17 @@ func FindID(id string) (Story, error) { } // List lists stories by any non-zero criteria passed with it. -func List(author string, tags []Tag, earliest, latest time.Time, unlisted bool, open *bool, limit int) ([]Story, error) { +func List(author string, category *string, tags []Tag, earliest, latest time.Time, unlisted bool, open *bool, limit int) ([]Story, error) { query := bson.M{} if author != "" { query["author"] = author } + if category != nil { + query["category"] = category + } + if len(tags) > 0 { query["tags"] = bson.M{"$in": tags} }