@ -29,28 +29,27 @@ func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResol
// StoriesArg is args for stories query
// StoriesArg is args for stories query
type StoriesArg struct {
type StoriesArg struct {
Input * StoriesInput
}
// StoriesInput resolves the TagInput input
type StoriesInput struct {
Input * struct {
Author * string
Author * string
Tags * [ ] TagInput
Tags * [ ] TagInput
EarliestFictionalDate * string
EarliestFictionalDate * string
LatestFictionalDate * string
LatestFictionalDate * string
Limit * int32
Limit * int32
}
}
}
// Stories implements the stories query
// Stories implements the stories query
func ( r * QueryResolver ) Stories ( ctx context . Context , args * StoriesArg ) ( [ ] * StoryResolver , error ) {
func ( r * QueryResolver ) Stories ( ctx context . Context , args * StoriesArg ) ( [ ] * StoryResolver , error ) {
input := args . Input
author := ""
author := ""
if args . Input . Author != nil {
author = * args . I nput. Author
if i nput. Author != nil {
author = * i nput. Author
}
}
tags := make ( [ ] story . Tag , 0 , 8 )
tags := make ( [ ] story . Tag , 0 , 8 )
if args . I nput. Tags != nil {
for _ , tagInput := range * args . I nput. Tags {
if i nput. Tags != nil {
for _ , tagInput := range * i nput. Tags {
tags = append ( tags , story . Tag {
tags = append ( tags , story . Tag {
Kind : tagInput . Kind ,
Kind : tagInput . Kind ,
Name : tagInput . Name ,
Name : tagInput . Name ,
@ -60,24 +59,24 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*Story
earliest := time . Time { }
earliest := time . Time { }
err := error ( nil )
err := error ( nil )
if args . I nput. EarliestFictionalDate != nil {
earliest , err = time . Parse ( time . RFC3339Nano , * args . I nput. EarliestFictionalDate )
if i nput. EarliestFictionalDate != nil {
earliest , err = time . Parse ( time . RFC3339Nano , * i nput. EarliestFictionalDate )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
}
}
latest := time . Time { }
latest := time . Time { }
if args . I nput. LatestFictionalDate != nil {
latest , err = time . Parse ( time . RFC3339Nano , * args . I nput. LatestFictionalDate )
if i nput. LatestFictionalDate != nil {
latest , err = time . Parse ( time . RFC3339Nano , * i nput. LatestFictionalDate )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
}
}
limit := 30
limit := 30
if args . I nput. Limit != nil {
limit = int ( * args . I nput. Limit )
if i nput. Limit != nil {
limit = int ( * i nput. Limit )
}
}
stories , err := story . List ( author , tags , earliest , latest , limit )
stories , err := story . List ( author , tags , earliest , latest , limit )
@ -108,27 +107,29 @@ type StoryAddArgs struct {
// AddStory implements the addStory mutation
// AddStory implements the addStory mutation
func ( r * MutationResolver ) AddStory ( ctx context . Context , args * StoryAddArgs ) ( * StoryResolver , error ) {
func ( r * MutationResolver ) AddStory ( ctx context . Context , args * StoryAddArgs ) ( * StoryResolver , error ) {
input := args . Input
user := session . FromContext ( ctx ) . User ( )
user := session . FromContext ( ctx ) . User ( )
if user == nil || ! user . Permitted ( "member" , "story.add" ) {
if user == nil || ! user . Permitted ( "member" , "story.add" ) {
return nil , ErrUnauthorized
return nil , ErrUnauthorized
}
}
author := user . ID
author := user . ID
if args . I nput. Author != nil {
author = * args . I nput. Author
if i nput. Author != nil {
author = * i nput. Author
if user . ID != author && ! user . Permitted ( "story.add" ) {
if user . ID != author && ! user . Permitted ( "story.add" ) {
return nil , ErrPermissionDenied
return nil , ErrPermissionDenied
}
}
}
}
listed := ( args . I nput. Listed != nil && * args . I nput. Listed == true )
listed := ( i nput. Listed != nil && * i nput. Listed == true )
open := ( args . I nput. Open != nil && * args . I nput. Open == true )
open := ( i nput. Open != nil && * i nput. Open == true )
tags := make ( [ ] story . Tag , 0 , 8 )
tags := make ( [ ] story . Tag , 0 , 8 )
if args . I nput. Tags != nil {
for _ , tagInput := range * args . I nput. Tags {
if i nput. Tags != nil {
for _ , tagInput := range * i nput. Tags {
tags = append ( tags , story . Tag {
tags = append ( tags , story . Tag {
Kind : tagInput . Kind ,
Kind : tagInput . Kind ,
Name : tagInput . Name ,
Name : tagInput . Name ,
@ -137,8 +138,8 @@ func (r *MutationResolver) AddStory(ctx context.Context, args *StoryAddArgs) (*S
}
}
fictionalDate := time . Time { }
fictionalDate := time . Time { }
if args . I nput. FictionalDate != nil {
date , err := time . Parse ( time . RFC3339Nano , * args . I nput. FictionalDate )
if i nput. FictionalDate != nil {
date , err := time . Parse ( time . RFC3339Nano , * i nput. FictionalDate )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -146,22 +147,22 @@ func (r *MutationResolver) AddStory(ctx context.Context, args *StoryAddArgs) (*S
fictionalDate = date
fictionalDate = date
}
}
story , err := story . New ( args . I nput. Name , author , args . I nput. Category , listed , open , tags , time . Now ( ) , fictionalDate )
story , err := story . New ( i nput. Name , author , i nput. Category , listed , open , tags , time . Now ( ) , fictionalDate )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
change . Submit ( "Story" , "add" , user . ID , story . ID , map [ string ] interface { } {
change . Submit ( "Story" , "add" , user . ID , story . ID , map [ string ] interface { } {
"name" : args . I nput. Name ,
"category" : args . I nput. Category ,
"author" : args . I nput. Author ,
"name" : i nput. Name ,
"category" : i nput. Category ,
"author" : i nput. Author ,
} )
} )
return & StoryResolver { S : story } , nil
return & StoryResolver { S : story } , nil
}
}
// StoryTagArgs is args for the addStory mutation
type StoryTagArgs struct {
// StoryTagAddA rgs is args for the addStoryTag mutation
type StoryTagAddA rgs struct {
Input * struct {
Input * struct {
ID string
ID string
Tag TagInput
Tag TagInput
@ -169,15 +170,16 @@ type StoryTagArgs struct {
}
}
// AddStoryTag implements the addStoryTag mutation
// AddStoryTag implements the addStoryTag mutation
func ( r * MutationResolver ) AddStoryTag ( ctx context . Context , args * StoryTagArgs ) ( * StoryResolver , error ) {
func ( r * MutationResolver ) AddStoryTag ( ctx context . Context , args * StoryTagAddArgs ) ( * StoryResolver , error ) {
input := args . Input
tag := story . Tag { Kind : input . Tag . Kind , Name : input . Tag . Name }
user := session . FromContext ( ctx ) . User ( )
user := session . FromContext ( ctx ) . User ( )
if user == nil || ! user . Permitted ( "member" , "story.edit" ) {
if user == nil || ! user . Permitted ( "member" , "story.edit" ) {
return nil , ErrUnauthorized
return nil , ErrUnauthorized
}
}
tag := story . Tag { Kind : args . Input . Tag . Kind , Name : args . Input . Tag . Name }
story , err := story . FindID ( args . Input . ID )
story , err := story . FindID ( input . ID )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -199,16 +201,25 @@ func (r *MutationResolver) AddStoryTag(ctx context.Context, args *StoryTagArgs)
return & StoryResolver { S : story } , nil
return & StoryResolver { S : story } , nil
}
}
// StoryTagRemoveArgs is args for the removeStoryTag mutation
type StoryTagRemoveArgs struct {
Input * struct {
ID string
Tag TagInput
}
}
// RemoveStoryTag implements the removeStoryTag mutation
// RemoveStoryTag implements the removeStoryTag mutation
func ( r * MutationResolver ) RemoveStoryTag ( ctx context . Context , args * StoryTagArgs ) ( * StoryResolver , error ) {
func ( r * MutationResolver ) RemoveStoryTag ( ctx context . Context , args * StoryTagRemoveArgs ) ( * StoryResolver , error ) {
input := args . Input
tag := story . Tag { Kind : input . Tag . Kind , Name : input . Tag . Name }
user := session . FromContext ( ctx ) . User ( )
user := session . FromContext ( ctx ) . User ( )
if user == nil || ! user . Permitted ( "member" , "story.edit" ) {
if user == nil || ! user . Permitted ( "member" , "story.edit" ) {
return nil , ErrUnauthorized
return nil , ErrUnauthorized
}
}
tag := story . Tag { Kind : args . Input . Tag . Kind , Name : args . Input . Tag . Name }
story , err := story . FindID ( args . Input . ID )
story , err := story . FindID ( input . ID )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -245,12 +256,14 @@ type StoryEditArgs struct {
// EditStory implements the editStory mutation
// EditStory implements the editStory mutation
func ( r * MutationResolver ) EditStory ( ctx context . Context , args * StoryEditArgs ) ( * StoryResolver , error ) {
func ( r * MutationResolver ) EditStory ( ctx context . Context , args * StoryEditArgs ) ( * StoryResolver , error ) {
input := args . Input
user := session . FromContext ( ctx ) . User ( )
user := session . FromContext ( ctx ) . User ( )
if user == nil || ! user . Permitted ( "member" , "story.edit" ) {
if user == nil || ! user . Permitted ( "member" , "story.edit" ) {
return nil , ErrUnauthorized
return nil , ErrUnauthorized
}
}
story , err := story . FindID ( args . I nput. ID )
story , err := story . FindID ( i nput. ID )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -260,8 +273,8 @@ func (r *MutationResolver) EditStory(ctx context.Context, args *StoryEditArgs) (
}
}
var fictionalDate * time . Time
var fictionalDate * time . Time
if args . I nput. FictionalDate != nil {
date , err := time . Parse ( time . RFC3339Nano , * args . I nput. FictionalDate )
if i nput. FictionalDate != nil {
date , err := time . Parse ( time . RFC3339Nano , * i nput. FictionalDate )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -269,19 +282,18 @@ func (r *MutationResolver) EditStory(ctx context.Context, args *StoryEditArgs) (
fictionalDate = & date
fictionalDate = & date
}
}
input := args . Input
err = story . Edit ( input . Name , input . Category , input . Listed , input . Open , fictionalDate )
err = story . Edit ( input . Name , input . Category , input . Listed , input . Open , fictionalDate )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
change . Submit ( "Story" , "edit" , user . ID , story . ID , map [ string ] interface { } {
change . Submit ( "Story" , "edit" , user . ID , story . ID , map [ string ] interface { } {
"name" : args . I nput. Name ,
"category" : args . I nput. Category ,
"author" : args . I nput. Author ,
"open" : args . I nput. Open ,
"listed" : args . I nput. Listed ,
"fictionalDate" : args . I nput. FictionalDate ,
"name" : i nput. Name ,
"category" : i nput. Category ,
"author" : i nput. Author ,
"open" : i nput. Open ,
"listed" : i nput. Listed ,
"fictionalDate" : i nput. FictionalDate ,
} )
} )
return & StoryResolver { S : story } , nil
return & StoryResolver { S : story } , nil