Browse Source

Fixed nil deref error on no filter, fixed no results

1.0
Gisle Aune 6 years ago
parent
commit
c348a90b70
  1. 5
      graphql/resolver/queries/stories.go
  2. 8
      model/story/story.go

5
graphql/resolver/queries/stories.go

@ -35,7 +35,10 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types
author = *filter.Author author = *filter.Author
} }
category := filter.Category
category := ""
if filter != nil && filter.Category != nil {
category = *filter.Category
}
tags := make([]story.Tag, 0, 8) tags := make([]story.Tag, 0, 8)
if filter != nil && filter.Tags != nil { if filter != nil && filter.Tags != nil {

8
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. // 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{} query := bson.M{}
if author != "" { if author != "" {
query["author"] = author query["author"] = author
} }
if category != nil {
if category != "" {
query["category"] = 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 { if open != nil {
query["open"] = *open query["open"] = *open

Loading…
Cancel
Save