|
|
@ -24,7 +24,7 @@ func (r *resolver) Story(ctx context.Context, id string) (*models.Story, error) |
|
|
|
return &story, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]models.Story, error) { |
|
|
|
func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]*models.Story, error) { |
|
|
|
if filter != nil { |
|
|
|
if filter.Unlisted != nil && *filter.Unlisted == true { |
|
|
|
token := auth.TokenFromContext(ctx) |
|
|
@ -38,7 +38,17 @@ func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]model |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return stories.List(filter) |
|
|
|
stories, err := stories.List(filter) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
stories2 := make([]*models.Story, len(stories)) |
|
|
|
for i, story := range stories { |
|
|
|
stories2[i] = &story |
|
|
|
} |
|
|
|
|
|
|
|
return stories2, nil |
|
|
|
} |
|
|
|
|
|
|
|
// Mutations
|
|
|
@ -66,7 +76,12 @@ func (r *mutationResolver) AddStory(ctx context.Context, input input.StoryAddInp |
|
|
|
listed := input.Listed != nil && *input.Listed |
|
|
|
open := input.Open != nil && *input.Open |
|
|
|
|
|
|
|
story, err := stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate) |
|
|
|
tags := make([]models.Tag, len(input.Tags)) |
|
|
|
for i := range input.Tags { |
|
|
|
tags[i] = *input.Tags[i] |
|
|
|
} |
|
|
|
|
|
|
|
story, err := stories.Add(input.Name, author, input.Category, listed, open, tags, time.Now(), fictionalDate) |
|
|
|
if err != nil { |
|
|
|
return nil, errors.New("Failed to add story: " + err.Error()) |
|
|
|
} |
|
|
@ -94,7 +109,7 @@ func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTag |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
story, err = stories.AddTag(story, input.Tag) |
|
|
|
story, err = stories.AddTag(story, *input.Tag) |
|
|
|
if err != nil { |
|
|
|
return nil, errors.New("Failed to add story: " + err.Error()) |
|
|
|
} |
|
|
@ -122,7 +137,7 @@ func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.Story |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
story, err = stories.RemoveTag(story, input.Tag) |
|
|
|
story, err = stories.RemoveTag(story, *input.Tag) |
|
|
|
if err != nil { |
|
|
|
return nil, errors.New("Failed to add story: " + err.Error()) |
|
|
|
} |
|
|
|