AddUserToGroup.php 1.12 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
<?php

namespace Source\UseCases\GroupUser\AddUserToGroup;

Jacob Priddy's avatar
Jacob Priddy committed
5
use Source\Authorization\Authorizer;
Jacob Priddy's avatar
Jacob Priddy committed
6
7
8
9
10
11
12
13
14
use Source\Gateways\GroupUser\GroupUserRepository;

class AddUserToGroup implements AddUserToGroupUseCase
{
    /**
     * @var \Source\Gateways\GroupUser\GroupUserRepository
     */
    protected GroupUserRepository $repository;

Jacob Priddy's avatar
Jacob Priddy committed
15
16
17
18
19
20
21
22
23
24
    /**
     * @var \Source\Authorization\Authorizer
     */
    protected Authorizer $authorizer;

    /**
     * @param \Source\Authorization\Authorizer               $authorizer
     * @param \Source\Gateways\GroupUser\GroupUserRepository $repository
     */
    public function __construct(Authorizer $authorizer, GroupUserRepository $repository)
Jacob Priddy's avatar
Jacob Priddy committed
25
26
    {
        $this->repository = $repository;
Jacob Priddy's avatar
Jacob Priddy committed
27
        $this->authorizer = $authorizer;
Jacob Priddy's avatar
Jacob Priddy committed
28
29
30
31
32
33
34
    }

    /**
     * @inheritDoc
     */
    public function addUserToGroup(string $userId, string $groupId, Presenter $presenter): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
35
36
        $this->authorizer->protectAdminRights($userId, $groupId);

Jacob Priddy's avatar
Jacob Priddy committed
37
38
39
40
41
42
43
        $this->repository->addUserToGroup($userId, $groupId);

        $responseModel = new ResponseModel('Success');

        $presenter->present($responseModel);
    }
}