stufflog graphql server
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.

78 lines
2.6 KiB

5 years ago
  1. package resolvers
  2. // This file will be automatically regenerated based on the schema, any resolver implementations
  3. // will be copied through when generating and any unknown code will be moved to the end.
  4. import (
  5. "context"
  6. "git.aiterp.net/stufflog/server/graph/graphcore"
  7. "git.aiterp.net/stufflog/server/graph/loaders"
  8. "git.aiterp.net/stufflog/server/internal/slerrors"
  9. "git.aiterp.net/stufflog/server/models"
  10. )
  11. func (r *projectResolver) Issues(ctx context.Context, obj *models.Project, filter *graphcore.ProjectIssueFilter) ([]*models.Issue, error) {
  12. if filter == nil {
  13. filter = &graphcore.ProjectIssueFilter{}
  14. }
  15. issues, err := r.Database.Issues().List(ctx, models.IssueFilter{
  16. ProjectIDs: []string{obj.ID},
  17. AssigneeIDs: filter.AssigneeIds,
  18. Search: filter.Search,
  19. MinStage: filter.MinStage,
  20. MaxStage: filter.MaxStage,
  21. Limit: filter.Limit,
  22. })
  23. if err != nil {
  24. return nil, err
  25. }
  26. loader := loaders.IssueLoaderFromContext(ctx)
  27. for _, issue := range issues {
  28. loader.Prime(issue.ID, issue)
  29. }
  30. return issues, nil
  31. }
  32. func (r *projectResolver) Permissions(ctx context.Context, obj *models.Project) ([]*models.ProjectPermission, error) {
  33. if perm, err := r.Auth.ProjectPermission(ctx, obj.ID); err != nil || !perm.CanManagePermissions() {
  34. return nil, slerrors.PermissionDenied
  35. }
  36. return r.Database.Projects().ListPermissions(ctx, *obj)
  37. }
  38. func (r *projectResolver) UserPermissions(ctx context.Context, obj *models.Project) (*models.ProjectPermission, error) {
  39. return r.Auth.ProjectPermission(ctx, obj.ID)
  40. }
  41. func (r *projectResolver) Statuses(ctx context.Context, obj *models.Project, filter *models.ProjectStatusFilter) ([]*models.ProjectStatus, error) {
  42. if filter == nil {
  43. filter = &models.ProjectStatusFilter{}
  44. }
  45. filter.ProjectID = &obj.ID
  46. return r.Database.ProjectStatuses().List(ctx, *filter)
  47. }
  48. func (r *projectResolver) Activities(ctx context.Context, obj *models.Project) ([]*models.Activity, error) {
  49. return r.Database.Activities().List(ctx, models.ActivityFilter{ProjectIDs: []string{obj.ID}})
  50. }
  51. func (r *projectPermissionResolver) User(ctx context.Context, obj *models.ProjectPermission) (*models.User, error) {
  52. return loaders.UserLoaderFromContext(ctx).Load(obj.UserID)
  53. }
  54. // Project returns graphcore.ProjectResolver implementation.
  55. func (r *Resolver) Project() graphcore.ProjectResolver { return &projectResolver{r} }
  56. // ProjectPermission returns graphcore.ProjectPermissionResolver implementation.
  57. func (r *Resolver) ProjectPermission() graphcore.ProjectPermissionResolver {
  58. return &projectPermissionResolver{r}
  59. }
  60. type projectResolver struct{ *Resolver }
  61. type projectPermissionResolver struct{ *Resolver }