GraphQL API and utilities for the rpdata project
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.
|
|
package queries
import ( "context"
"git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/models" "git.aiterp.net/rpdata/api/models/files" )
func (r *resolver) File(ctx context.Context, id string) (*models.File, error) { file, err := files.FindID(id) if err != nil { return nil, err }
return &file, nil }
func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]*models.File, error) { token := auth.TokenFromContext(ctx)
if filter == nil { filter = &files.Filter{} }
// Only allow users to view public files that are not their own.
if token != nil { if filter.Public == nil || *filter.Public == false { filter.Author = &token.UserID } } else { filter.Public = &trueValue }
files, err := files.List(filter) if err != nil { return nil, err }
files2 := make([]*models.File, len(files)) for i := range files { files2[i] = &files[i] }
return files2, nil }
var trueValue = true
|