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.

68 lines
2.4 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. return 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. }
  24. func (r *projectResolver) Permissions(ctx context.Context, obj *models.Project) ([]*models.ProjectPermission, error) {
  25. if perm, err := r.Auth.ProjectPermission(ctx, *obj); err != nil || !perm.CanManagePermissions() {
  26. return nil, slerrors.PermissionDenied
  27. }
  28. return r.Database.Projects().ListPermissions(ctx, *obj)
  29. }
  30. func (r *projectResolver) UserPermissions(ctx context.Context, obj *models.Project) (*models.ProjectPermission, error) {
  31. return r.Auth.ProjectPermission(ctx, *obj)
  32. }
  33. func (r *projectResolver) Statuses(ctx context.Context, obj *models.Project, filter *models.ProjectStatusFilter) ([]*models.ProjectStatus, error) {
  34. if filter == nil {
  35. filter = &models.ProjectStatusFilter{}
  36. }
  37. filter.ProjectID = &obj.ID
  38. return r.Database.ProjectStatuses().List(ctx, *filter)
  39. }
  40. func (r *projectResolver) Activities(ctx context.Context, obj *models.Project) ([]*models.Activity, error) {
  41. return r.Database.Activities().List(ctx, models.ActivityFilter{ProjectIDs: []string{obj.ID}})
  42. }
  43. func (r *projectPermissionResolver) User(ctx context.Context, obj *models.ProjectPermission) (*models.User, error) {
  44. return loaders.UserLoaderFromContext(ctx).Load(obj.UserID)
  45. }
  46. // Project returns graphcore.ProjectResolver implementation.
  47. func (r *Resolver) Project() graphcore.ProjectResolver { return &projectResolver{r} }
  48. // ProjectPermission returns graphcore.ProjectPermissionResolver implementation.
  49. func (r *Resolver) ProjectPermission() graphcore.ProjectPermissionResolver {
  50. return &projectPermissionResolver{r}
  51. }
  52. type projectResolver struct{ *Resolver }
  53. type projectPermissionResolver struct{ *Resolver }