|
@ -28,64 +28,70 @@ type StoriesArg struct { |
|
|
|
|
|
|
|
|
// Stories resolves the stories query
|
|
|
// Stories resolves the stories query
|
|
|
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types.StoryResolver, error) { |
|
|
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types.StoryResolver, error) { |
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
filter := args.Filter |
|
|
filter := args.Filter |
|
|
|
|
|
|
|
|
author := "" |
|
|
author := "" |
|
|
if filter != nil && filter.Author != nil { |
|
|
|
|
|
author = *filter.Author |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
|
|
for _, tagInput := range *filter.Tags { |
|
|
|
|
|
tags = append(tags, story.Tag{ |
|
|
|
|
|
Kind: tagInput.Kind, |
|
|
|
|
|
Name: tagInput.Name, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
earliest := time.Time{} |
|
|
|
|
|
latest := time.Time{} |
|
|
|
|
|
unlisted := false |
|
|
|
|
|
open := (*bool)(nil) |
|
|
|
|
|
limit := 0 |
|
|
|
|
|
|
|
|
|
|
|
if filter != nil { |
|
|
|
|
|
if filter.Author != nil { |
|
|
|
|
|
author = *filter.Author |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
earliest := time.Time{} |
|
|
|
|
|
err := error(nil) |
|
|
|
|
|
if filter != nil && filter.EarliestFictionalDate != nil { |
|
|
|
|
|
earliest, err = time.Parse(time.RFC3339Nano, *filter.EarliestFictionalDate) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
|
if filter.Category != nil { |
|
|
|
|
|
category = *filter.Category |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
latest := time.Time{} |
|
|
|
|
|
if filter != nil && filter.LatestFictionalDate != nil { |
|
|
|
|
|
latest, err = time.Parse(time.RFC3339Nano, *filter.LatestFictionalDate) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
|
if filter.Tags != nil { |
|
|
|
|
|
for _, tagInput := range *filter.Tags { |
|
|
|
|
|
tags = append(tags, story.Tag{ |
|
|
|
|
|
Kind: tagInput.Kind, |
|
|
|
|
|
Name: tagInput.Name, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unlisted := filter.Unlisted != nil && *filter.Unlisted == true |
|
|
|
|
|
if unlisted { |
|
|
|
|
|
user := session.FromContext(ctx).User() |
|
|
|
|
|
if user == nil { |
|
|
|
|
|
return nil, ErrUnauthorized |
|
|
|
|
|
|
|
|
if filter.EarliestFictionalDate != nil { |
|
|
|
|
|
earliest, err = time.Parse(time.RFC3339Nano, *filter.EarliestFictionalDate) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if author != "" && author != user.ID && !user.Permitted("story.unlisted") { |
|
|
|
|
|
return nil, ErrPermissionDenied |
|
|
|
|
|
|
|
|
if filter.LatestFictionalDate != nil { |
|
|
|
|
|
latest, err = time.Parse(time.RFC3339Nano, *filter.LatestFictionalDate) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
author = user.ID |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if filter.Limit != nil { |
|
|
|
|
|
limit = int(*filter.Limit) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
open := filter.Open |
|
|
|
|
|
|
|
|
unlisted = filter.Unlisted != nil && *filter.Unlisted == true |
|
|
|
|
|
if unlisted { |
|
|
|
|
|
user := session.FromContext(ctx).User() |
|
|
|
|
|
if user == nil { |
|
|
|
|
|
return nil, ErrUnauthorized |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
limit := 0 |
|
|
|
|
|
if filter != nil && filter.Limit != nil { |
|
|
|
|
|
limit = int(*filter.Limit) |
|
|
|
|
|
|
|
|
if author != "" && author != user.ID && !user.Permitted("story.unlisted") { |
|
|
|
|
|
return nil, ErrPermissionDenied |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
author = user.ID |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open = filter.Open |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
stories, err := story.List(author, category, tags, earliest, latest, unlisted, open, limit) |
|
|
stories, err := story.List(author, category, tags, earliest, latest, unlisted, open, limit) |
|
|