| @@ 24-71 (lines=48) @@ | ||
| 21 | use Kreta\TaskManager\Domain\Model\Organization\OwnerDoesNotExistException; |
|
| 22 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
| 23 | ||
| 24 | class MemberResolver implements Resolver |
|
| 25 | { |
|
| 26 | private $queryBus; |
|
| 27 | private $currentUser; |
|
| 28 | private $organizationResolver; |
|
| 29 | ||
| 30 | public function __construct( |
|
| 31 | TokenStorageInterface $tokenStorage, |
|
| 32 | QueryBus $queryBus, |
|
| 33 | OrganizationResolver $organizationResolver |
|
| 34 | ) { |
|
| 35 | $this->queryBus = $queryBus; |
|
| 36 | $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
| 37 | $this->organizationResolver = $organizationResolver; |
|
| 38 | } |
|
| 39 | ||
| 40 | public function resolve($args) |
|
| 41 | { |
|
| 42 | try { |
|
| 43 | $this->queryBus->handle( |
|
| 44 | new OwnerOfIdQuery( |
|
| 45 | $args['organizationId'], |
|
| 46 | $args['ownerId'], |
|
| 47 | $this->currentUser |
|
| 48 | ), |
|
| 49 | $result |
|
| 50 | ); |
|
| 51 | } catch (OwnerDoesNotExistException $exception) { |
|
| 52 | } |
|
| 53 | ||
| 54 | if (empty($result)) { |
|
| 55 | $this->queryBus->handle( |
|
| 56 | new OrganizationMemberOfIdQuery( |
|
| 57 | $args['organizationId'], |
|
| 58 | $args['organizationMemberId'], |
|
| 59 | $this->currentUser |
|
| 60 | ), |
|
| 61 | $result |
|
| 62 | ); |
|
| 63 | } |
|
| 64 | ||
| 65 | $result['organization'] = $this->organizationResolver->resolve([ |
|
| 66 | 'id' => $args['organizationId'], |
|
| 67 | ]); |
|
| 68 | ||
| 69 | return $result; |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 24-67 (lines=44) @@ | ||
| 21 | use Kreta\TaskManager\Infrastructure\Symfony\GraphQl\Query\Organization\OrganizationResolver; |
|
| 22 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
| 23 | ||
| 24 | class ProjectResolver implements Resolver |
|
| 25 | { |
|
| 26 | private $queryBus; |
|
| 27 | private $currentUser; |
|
| 28 | private $organizationResolver; |
|
| 29 | ||
| 30 | public function __construct( |
|
| 31 | TokenStorageInterface $tokenStorage, |
|
| 32 | QueryBus $queryBus, |
|
| 33 | OrganizationResolver $organizationResolver |
|
| 34 | ) { |
|
| 35 | $this->queryBus = $queryBus; |
|
| 36 | $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
| 37 | $this->organizationResolver = $organizationResolver; |
|
| 38 | } |
|
| 39 | ||
| 40 | public function resolve($args) |
|
| 41 | { |
|
| 42 | if (isset($args['slug'])) { |
|
| 43 | $this->queryBus->handle( |
|
| 44 | new ProjectOfSlugQuery( |
|
| 45 | $args['slug'], |
|
| 46 | $args['organizationSlug'], |
|
| 47 | $this->currentUser |
|
| 48 | ), |
|
| 49 | $result |
|
| 50 | ); |
|
| 51 | } else { |
|
| 52 | $this->queryBus->handle( |
|
| 53 | new ProjectOfIdQuery( |
|
| 54 | $args['id'], |
|
| 55 | $this->currentUser |
|
| 56 | ), |
|
| 57 | $result |
|
| 58 | ); |
|
| 59 | } |
|
| 60 | $result['organization'] = $this->organizationResolver->resolve([ |
|
| 61 | 'id' => $result['organization_id'], |
|
| 62 | ]); |
|
| 63 | unset($result['organization_id']); |
|
| 64 | ||
| 65 | return $result; |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||