package resolvers import ( "context" "time" "git.aiterp.net/rpdata/api/graph2/graphcore" "git.aiterp.net/rpdata/api/models" ) func (r *queryResolver) Story(ctx context.Context, id string) (*models.Story, error) { return r.s.Stories.FindStory(ctx, id) } func (r *queryResolver) Stories(ctx context.Context, filter *models.StoryFilter) ([]*models.Story, error) { if filter == nil { filter = &models.StoryFilter{} } return r.s.Stories.ListStories(ctx, *filter) } // Mutations func (r *mutationResolver) AddStory(ctx context.Context, input graphcore.StoryAddInput) (*models.Story, error) { listed := input.Listed != nil && *input.Listed open := input.Open != nil && *input.Open tags := make([]models.Tag, len(input.Tags)) for i, tag := range input.Tags { tags[i] = *tag } fictionalDate := time.Time{} if input.FictionalDate != nil { fictionalDate = *input.FictionalDate } return r.s.Stories.CreateStory(ctx, input.Name, input.Author, input.Category, listed, open, tags, time.Now(), fictionalDate) } func (r *mutationResolver) AddStoryTag(ctx context.Context, input graphcore.StoryTagAddInput) (*models.Story, error) { story, err := r.s.Stories.FindStory(ctx, input.ID) if err != nil { return nil, err } return r.s.Stories.AddStoryTag(ctx, *story, *input.Tag) } func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input graphcore.StoryTagRemoveInput) (*models.Story, error) { story, err := r.s.Stories.FindStory(ctx, input.ID) if err != nil { return nil, err } return r.s.Stories.RemoveStoryTag(ctx, *story, *input.Tag) } func (r *mutationResolver) EditStory(ctx context.Context, input graphcore.StoryEditInput) (*models.Story, error) { story, err := r.s.Stories.FindStory(ctx, input.ID) if err != nil { return nil, err } return r.s.Stories.EditStory(ctx, story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate) } func (r *mutationResolver) RemoveStory(ctx context.Context, input graphcore.StoryRemoveInput) (*models.Story, error) { story, err := r.s.Stories.FindStory(ctx, input.ID) if err != nil { return nil, err } err = r.s.Stories.RemoveStory(ctx, story) if err != nil { return nil, err } return story, err }