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.

39 lines
1.0 KiB

  1. package resolvers
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graph2/graphcore"
  5. "git.aiterp.net/rpdata/api/models"
  6. )
  7. // Queries
  8. func (r *queryResolver) File(ctx context.Context, id string) (*models.File, error) {
  9. return r.s.Files.Find(ctx, id)
  10. }
  11. func (r *queryResolver) Files(ctx context.Context, filter *models.FileFilter) ([]*models.File, error) {
  12. if filter == nil {
  13. public := true
  14. filter = &models.FileFilter{
  15. Public: &public,
  16. }
  17. }
  18. return r.s.Files.List(ctx, *filter)
  19. }
  20. // Mutations
  21. func (r *mutationResolver) UploadFile(ctx context.Context, input *graphcore.FileUploadInput) (*models.File, error) {
  22. return r.s.Files.Upload(ctx, input.File.File, input.Name, input.Public, input.File.Size)
  23. }
  24. func (r *mutationResolver) EditFile(ctx context.Context, input *graphcore.FileEditInput) (*models.File, error) {
  25. return r.s.Files.Edit(ctx, input.ID, input.Name, input.Public)
  26. }
  27. func (r *mutationResolver) RemoveFile(ctx context.Context, input *graphcore.FileRemoveInput) (*models.File, error) {
  28. return r.s.Files.Remove(ctx, input.ID)
  29. }