From c348a90b707ade71a4a0d14b4104c13f15eea85b Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Wed, 1 Aug 2018 14:51:45 +0200 Subject: [PATCH] Fixed nil deref error on no filter, fixed no results --- graphql/resolver/queries/stories.go | 5 ++++- model/story/story.go | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/graphql/resolver/queries/stories.go b/graphql/resolver/queries/stories.go index df74268..d0870b5 100644 --- a/graphql/resolver/queries/stories.go +++ b/graphql/resolver/queries/stories.go @@ -35,7 +35,10 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types author = *filter.Author } - category := filter.Category + category := "" + if filter != nil && filter.Category != nil { + category = *filter.Category + } tags := make([]story.Tag, 0, 8) if filter != nil && filter.Tags != nil { diff --git a/model/story/story.go b/model/story/story.go index 0c99d1f..2c1b930 100644 --- a/model/story/story.go +++ b/model/story/story.go @@ -193,14 +193,14 @@ func FindID(id string) (Story, error) { } // List lists stories by any non-zero criteria passed with it. -func List(author string, category *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 { + if category != "" { query["category"] = category } @@ -223,7 +223,9 @@ func List(author string, category *string, tags []Tag, earliest, latest time.Tim } } - query["unlisted"] = unlisted + if unlisted { + query["listed"] = false + } if open != nil { query["open"] = *open