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.

31 lines
735 B

  1. package queries
  2. import (
  3. "context"
  4. "errors"
  5. "git.aiterp.net/rpdata/api/internal/auth"
  6. "git.aiterp.net/rpdata/api/models"
  7. "git.aiterp.net/rpdata/api/models/stories"
  8. )
  9. func (r *resolver) Story(ctx context.Context, id string) (models.Story, error) {
  10. return stories.FindID(id)
  11. }
  12. func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]models.Story, error) {
  13. if filter != nil {
  14. if filter.Unlisted != nil && *filter.Unlisted == true {
  15. token := auth.TokenFromContext(ctx)
  16. if !token.Authenticated() {
  17. return nil, errors.New("You are not permitted to view unlisted stories")
  18. }
  19. if !token.Permitted("story.unlisted") {
  20. filter.Author = &token.UserID
  21. }
  22. }
  23. }
  24. return stories.List(filter)
  25. }