|
|
@ -28,20 +28,29 @@ type StoriesArg struct { |
|
|
|
|
|
|
|
// Stories resolves the stories query
|
|
|
|
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types.StoryResolver, error) { |
|
|
|
var err error |
|
|
|
|
|
|
|
filter := args.Filter |
|
|
|
|
|
|
|
author := "" |
|
|
|
if filter != nil && filter.Author != nil { |
|
|
|
category := "" |
|
|
|
tags := make([]story.Tag, 0, 8) |
|
|
|
earliest := time.Time{} |
|
|
|
latest := time.Time{} |
|
|
|
unlisted := false |
|
|
|
open := (*bool)(nil) |
|
|
|
limit := 0 |
|
|
|
|
|
|
|
if filter != nil { |
|
|
|
if filter.Author != nil { |
|
|
|
author = *filter.Author |
|
|
|
} |
|
|
|
|
|
|
|
category := "" |
|
|
|
if filter != nil && filter.Category != nil { |
|
|
|
if filter.Category != nil { |
|
|
|
category = *filter.Category |
|
|
|
} |
|
|
|
|
|
|
|
tags := make([]story.Tag, 0, 8) |
|
|
|
if filter != nil && filter.Tags != nil { |
|
|
|
if filter.Tags != nil { |
|
|
|
for _, tagInput := range *filter.Tags { |
|
|
|
tags = append(tags, story.Tag{ |
|
|
|
Kind: tagInput.Kind, |
|
|
@ -50,24 +59,25 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
earliest := time.Time{} |
|
|
|
err := error(nil) |
|
|
|
if filter != nil && filter.EarliestFictionalDate != nil { |
|
|
|
if filter.EarliestFictionalDate != nil { |
|
|
|
earliest, err = time.Parse(time.RFC3339Nano, *filter.EarliestFictionalDate) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
latest := time.Time{} |
|
|
|
if filter != nil && filter.LatestFictionalDate != nil { |
|
|
|
if filter.LatestFictionalDate != nil { |
|
|
|
latest, err = time.Parse(time.RFC3339Nano, *filter.LatestFictionalDate) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
unlisted := filter.Unlisted != nil && *filter.Unlisted == true |
|
|
|
if filter.Limit != nil { |
|
|
|
limit = int(*filter.Limit) |
|
|
|
} |
|
|
|
|
|
|
|
unlisted = filter.Unlisted != nil && *filter.Unlisted == true |
|
|
|
if unlisted { |
|
|
|
user := session.FromContext(ctx).User() |
|
|
|
if user == nil { |
|
|
@ -81,11 +91,7 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types |
|
|
|
author = user.ID |
|
|
|
} |
|
|
|
|
|
|
|
open := filter.Open |
|
|
|
|
|
|
|
limit := 0 |
|
|
|
if filter != nil && filter.Limit != nil { |
|
|
|
limit = int(*filter.Limit) |
|
|
|
open = filter.Open |
|
|
|
} |
|
|
|
|
|
|
|
stories, err := story.List(author, category, tags, earliest, latest, unlisted, open, limit) |
|
|
|