You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
903 B
37 lines
903 B
package mutations
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
|
"git.aiterp.net/rpdata/api/internal/session"
|
|
"git.aiterp.net/rpdata/api/model/change"
|
|
"git.aiterp.net/rpdata/api/model/story"
|
|
)
|
|
|
|
// RemoveChapterArgs is args for the addChapter mutation
|
|
type RemoveChapterArgs struct {
|
|
ID string
|
|
}
|
|
|
|
// RemoveChapter resolves the removeChapter mutation
|
|
func (r *MutationResolver) RemoveChapter(ctx context.Context, args *RemoveChapterArgs) (*types.ChapterResolver, error) {
|
|
user := session.FromContext(ctx).User()
|
|
if user == nil || !user.Permitted("member", "chapter.edit") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
chapter, err := story.FindChapterID(args.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = chapter.Remove()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go change.Submit("Chapter", "remove", user.ID, chapter.ID, nil)
|
|
|
|
return &types.ChapterResolver{C: chapter}, nil
|
|
}
|