| @@ 26-60 (lines=35) @@ | ||
| 23 | use Kreta\TaskManager\Domain\Model\Organization\UnauthorizedOrganizationActionException; |
|
| 24 | use Kreta\TaskManager\Domain\Model\User\UserId; |
|
| 25 | ||
| 26 | class OrganizationMemberOfIdHandler |
|
| 27 | { |
|
| 28 | private $repository; |
|
| 29 | private $dataTransformer; |
|
| 30 | ||
| 31 | public function __construct(OrganizationRepository $repository, MemberDataTransformer $dataTransformer) |
|
| 32 | { |
|
| 33 | $this->repository = $repository; |
|
| 34 | $this->dataTransformer = $dataTransformer; |
|
| 35 | } |
|
| 36 | ||
| 37 | public function __invoke(OrganizationMemberOfIdQuery $query) |
|
| 38 | { |
|
| 39 | $organization = $this->repository->organizationOfId( |
|
| 40 | OrganizationId::generate( |
|
| 41 | $query->organizationId() |
|
| 42 | ) |
|
| 43 | ); |
|
| 44 | if (!$organization instanceof Organization) { |
|
| 45 | throw new OrganizationDoesNotExistException(); |
|
| 46 | } |
|
| 47 | if (!$organization->isOrganizationMember(UserId::generate($query->userId()))) { |
|
| 48 | throw new UnauthorizedOrganizationActionException(); |
|
| 49 | } |
|
| 50 | ||
| 51 | $memberId = UserId::generate($query->memberId()); |
|
| 52 | if (!$organization->isOrganizationMember($memberId)) { |
|
| 53 | throw new OrganizationMemberDoesNotExistException($memberId); |
|
| 54 | } |
|
| 55 | ||
| 56 | $this->dataTransformer->write($organization->organizationMember($memberId)); |
|
| 57 | ||
| 58 | return $this->dataTransformer->read(); |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| @@ 26-60 (lines=35) @@ | ||
| 23 | use Kreta\TaskManager\Domain\Model\Organization\UnauthorizedOrganizationActionException; |
|
| 24 | use Kreta\TaskManager\Domain\Model\User\UserId; |
|
| 25 | ||
| 26 | class OwnerOfIdHandler |
|
| 27 | { |
|
| 28 | private $repository; |
|
| 29 | private $dataTransformer; |
|
| 30 | ||
| 31 | public function __construct(OrganizationRepository $repository, MemberDataTransformer $dataTransformer) |
|
| 32 | { |
|
| 33 | $this->repository = $repository; |
|
| 34 | $this->dataTransformer = $dataTransformer; |
|
| 35 | } |
|
| 36 | ||
| 37 | public function __invoke(OwnerOfIdQuery $query) |
|
| 38 | { |
|
| 39 | $organization = $this->repository->organizationOfId( |
|
| 40 | OrganizationId::generate( |
|
| 41 | $query->organizationId() |
|
| 42 | ) |
|
| 43 | ); |
|
| 44 | if (!$organization instanceof Organization) { |
|
| 45 | throw new OrganizationDoesNotExistException(); |
|
| 46 | } |
|
| 47 | if (!$organization->isOrganizationMember(UserId::generate($query->userId()))) { |
|
| 48 | throw new UnauthorizedOrganizationActionException(); |
|
| 49 | } |
|
| 50 | ||
| 51 | $ownerId = UserId::generate($query->ownerId()); |
|
| 52 | if (!$organization->isOwner($ownerId)) { |
|
| 53 | throw new OwnerDoesNotExistException($ownerId); |
|
| 54 | } |
|
| 55 | ||
| 56 | $this->dataTransformer->write($organization->owner($ownerId)); |
|
| 57 | ||
| 58 | return $this->dataTransformer->read(); |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||