|
@ -5,6 +5,9 @@ import ( |
|
|
"errors" |
|
|
"errors" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"git.aiterp.net/rpdata/api/models/changekeys" |
|
|
|
|
|
"git.aiterp.net/rpdata/api/models/changes" |
|
|
|
|
|
|
|
|
"git.aiterp.net/rpdata/api/graph2/input" |
|
|
"git.aiterp.net/rpdata/api/graph2/input" |
|
|
"git.aiterp.net/rpdata/api/internal/auth" |
|
|
"git.aiterp.net/rpdata/api/internal/auth" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
@ -58,7 +61,14 @@ func (r *mutationResolver) AddStory(ctx context.Context, input input.StoryAddInp |
|
|
listed := input.Listed != nil && *input.Listed |
|
|
listed := input.Listed != nil && *input.Listed |
|
|
open := input.Open != nil && *input.Open |
|
|
open := input.Open != nil && *input.Open |
|
|
|
|
|
|
|
|
return stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate) |
|
|
|
|
|
|
|
|
story, err := stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return models.Story{}, errors.New("Failed to add story: " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go changes.Submit("Story", "add", token.UserID, story.Listed, changekeys.Listed(story), story) |
|
|
|
|
|
|
|
|
|
|
|
return story, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTagAddInput) (models.Story, error) { |
|
|
func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTagAddInput) (models.Story, error) { |
|
@ -73,7 +83,14 @@ func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTag |
|
|
return models.Story{}, errors.New("You are not permitted to edit this story") |
|
|
return models.Story{}, errors.New("You are not permitted to edit this story") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return stories.AddTag(story, input.Tag) |
|
|
|
|
|
|
|
|
story, err = stories.AddTag(story, input.Tag) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return models.Story{}, errors.New("Failed to add story: " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go changes.Submit("Story", "tag", token.UserID, story.Listed, changekeys.Listed(story), story, input.Tag) |
|
|
|
|
|
|
|
|
|
|
|
return story, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.StoryTagRemoveInput) (models.Story, error) { |
|
|
func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.StoryTagRemoveInput) (models.Story, error) { |
|
@ -88,7 +105,14 @@ func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.Story |
|
|
return models.Story{}, errors.New("You are not permitted to edit this story") |
|
|
return models.Story{}, errors.New("You are not permitted to edit this story") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return stories.RemoveTag(story, input.Tag) |
|
|
|
|
|
|
|
|
story, err = stories.RemoveTag(story, input.Tag) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return models.Story{}, errors.New("Failed to add story: " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go changes.Submit("Story", "untag", token.UserID, story.Listed, changekeys.Listed(story), story, input.Tag) |
|
|
|
|
|
|
|
|
|
|
|
return story, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditInput) (models.Story, error) { |
|
|
func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditInput) (models.Story, error) { |
|
@ -107,7 +131,14 @@ func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditI |
|
|
input.FictionalDate = &time.Time{} |
|
|
input.FictionalDate = &time.Time{} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return stories.Edit(story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate) |
|
|
|
|
|
|
|
|
story, err = stories.Edit(story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return models.Story{}, errors.New("Failed to add story: " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go changes.Submit("Story", "edit", token.UserID, story.Listed, changekeys.Listed(story), story) |
|
|
|
|
|
|
|
|
|
|
|
return story, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRemoveInput) (models.Story, error) { |
|
|
func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRemoveInput) (models.Story, error) { |
|
@ -132,5 +163,7 @@ func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRem |
|
|
return models.Story{}, errors.New("Failed to remove chapters, but story is removed: " + err.Error()) |
|
|
return models.Story{}, errors.New("Failed to remove chapters, but story is removed: " + err.Error()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go changes.Submit("Story", "remove", token.UserID, story.Listed, changekeys.Listed(story), story) |
|
|
|
|
|
|
|
|
return story, nil |
|
|
return story, nil |
|
|
} |
|
|
} |