Browse Source

Moved FileResolver into resolvers/types package, updated references to it.

1.0
Gisle Aune 6 years ago
parent
commit
d05f3a8ca8
  1. 72
      resolver/file.go
  2. 59
      resolver/types/file.go

72
resolver/file.go

@ -2,28 +2,25 @@ package resolver
import (
"context"
"time"
"git.aiterp.net/rpdata/api/internal/session"
"git.aiterp.net/rpdata/api/model/file"
"git.aiterp.net/rpdata/api/resolver/types"
)
// FileResolver for the File graphql type
type FileResolver struct{ F file.File }
// FileArgs is an arg
type FileArgs struct {
ID string
}
// File implements the file query
func (r *QueryResolver) File(ctx context.Context, args *FileArgs) (*FileResolver, error) {
func (r *QueryResolver) File(ctx context.Context, args *FileArgs) (*types.FileResolver, error) {
file, err := file.FindID(args.ID)
if err != nil {
return nil, err
}
return &FileResolver{F: file}, nil
return &types.FileResolver{F: file}, nil
}
// FilesArgs is an arg
@ -33,7 +30,7 @@ type FilesArgs struct {
}
// Files implements the file query
func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*FileResolver, error) {
func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*types.FileResolver, error) {
user := session.FromContext(ctx).User()
author := ""
if user != nil {
@ -52,9 +49,9 @@ func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*FileReso
return nil, err
}
resolvers := make([]*FileResolver, len(files))
resolvers := make([]*types.FileResolver, len(files))
for i := range files {
resolvers[i] = &FileResolver{F: files[i]}
resolvers[i] = &types.FileResolver{F: files[i]}
}
return resolvers, nil
@ -70,7 +67,7 @@ type FileEditArgs struct {
}
// EditFile resolves the editFile mutation
func (r *MutationResolver) EditFile(ctx context.Context, args *FileEditArgs) (*FileResolver, error) {
func (r *MutationResolver) EditFile(ctx context.Context, args *FileEditArgs) (*types.FileResolver, error) {
input := args.Input
user := session.FromContext(ctx).User()
@ -91,11 +88,11 @@ func (r *MutationResolver) EditFile(ctx context.Context, args *FileEditArgs) (*F
return nil, err
}
return &FileResolver{F: file}, nil
return &types.FileResolver{F: file}, nil
}
// RemoveFile resolves the removeFIle mutation
func (r *MutationResolver) RemoveFile(ctx context.Context, args *FileArgs) (*FileResolver, error) {
func (r *MutationResolver) RemoveFile(ctx context.Context, args *FileArgs) (*types.FileResolver, error) {
user := session.FromContext(ctx).User()
if user == nil || !user.Permitted("member") {
return nil, ErrUnauthorized
@ -114,54 +111,5 @@ func (r *MutationResolver) RemoveFile(ctx context.Context, args *FileArgs) (*Fil
return nil, err
}
return &FileResolver{F: file}, nil
}
// ID resolves File.id
func (f *FileResolver) ID() string {
return f.F.ID
}
// Author resolves File.author
func (f *FileResolver) Author() string {
return f.F.Author
}
// Kind resolves File.kind
func (f *FileResolver) Kind() string {
return f.F.Kind
}
// Time resolves File.time
func (f *FileResolver) Time() string {
return f.F.Time.Format(time.RFC3339Nano)
}
// Public resolves File.public
func (f *FileResolver) Public() bool {
return f.F.Public
}
// Name resolves File.name
func (f *FileResolver) Name() string {
return f.F.Name
}
// MimeType resolves File.mimeType
func (f *FileResolver) MimeType() string {
return f.F.MimeType
}
// Size resolves File.size
func (f *FileResolver) Size() int32 {
return int32(f.F.Size)
}
// URL resolves File.url
func (f *FileResolver) URL() *string {
if f.F.URL == "" {
return nil
}
return &f.F.URL
return &types.FileResolver{F: file}, nil
}

59
resolver/types/file.go

@ -0,0 +1,59 @@
package types
import (
"time"
"git.aiterp.net/rpdata/api/model/file"
)
// FileResolver for the File graphql type
type FileResolver struct{ F file.File }
// ID resolves File.id
func (f *FileResolver) ID() string {
return f.F.ID
}
// Author resolves File.author
func (f *FileResolver) Author() string {
return f.F.Author
}
// Kind resolves File.kind
func (f *FileResolver) Kind() string {
return f.F.Kind
}
// Time resolves File.time
func (f *FileResolver) Time() string {
return f.F.Time.Format(time.RFC3339Nano)
}
// Public resolves File.public
func (f *FileResolver) Public() bool {
return f.F.Public
}
// Name resolves File.name
func (f *FileResolver) Name() string {
return f.F.Name
}
// MimeType resolves File.mimeType
func (f *FileResolver) MimeType() string {
return f.F.MimeType
}
// Size resolves File.size
func (f *FileResolver) Size() int32 {
return int32(f.F.Size)
}
// URL resolves File.url
func (f *FileResolver) URL() *string {
if f.F.URL == "" {
return nil
}
return &f.F.URL
}
Loading…
Cancel
Save