@@ 16-42 (lines=27) @@ | ||
13 | * |
|
14 | * @author Mahmoud Zalt <[email protected]> |
|
15 | */ |
|
16 | class DeleteUserTask extends Task |
|
17 | { |
|
18 | ||
19 | protected $repository; |
|
20 | ||
21 | public function __construct(UserRepository $repository) |
|
22 | { |
|
23 | $this->repository = $repository; |
|
24 | } |
|
25 | ||
26 | /** |
|
27 | * |
|
28 | * @param User $user |
|
29 | * |
|
30 | * @return bool |
|
31 | * @throws DeleteResourceFailedException |
|
32 | */ |
|
33 | public function run(User $user) |
|
34 | { |
|
35 | try { |
|
36 | return $this->repository->delete($user->id); |
|
37 | } |
|
38 | catch (Exception $exception) { |
|
39 | throw new DeleteResourceFailedException(); |
|
40 | } |
|
41 | } |
|
42 | } |
|
43 |
@@ 16-40 (lines=25) @@ | ||
13 | * |
|
14 | * @author Sebastian Weckend |
|
15 | */ |
|
16 | class FindUserByEmailTask extends Task |
|
17 | { |
|
18 | ||
19 | protected $repository; |
|
20 | ||
21 | public function __construct(UserRepository $repository) |
|
22 | { |
|
23 | $this->repository = $repository; |
|
24 | } |
|
25 | ||
26 | /** |
|
27 | * @param string $email |
|
28 | * |
|
29 | * @return User |
|
30 | * @throws NotFoundException |
|
31 | */ |
|
32 | public function run(string $email): User |
|
33 | { |
|
34 | try { |
|
35 | return $this->repository->findByField('email', $email)->first(); |
|
36 | } catch (Exception $e) { |
|
37 | throw new NotFoundException(); |
|
38 | } |
|
39 | } |
|
40 | } |
|
41 |
@@ 16-44 (lines=29) @@ | ||
13 | * |
|
14 | * @author Mahmoud Zalt <[email protected]> |
|
15 | */ |
|
16 | class FindUserByIdTask extends Task |
|
17 | { |
|
18 | ||
19 | protected $repository; |
|
20 | ||
21 | public function __construct(UserRepository $repository) |
|
22 | { |
|
23 | $this->repository = $repository; |
|
24 | } |
|
25 | ||
26 | /** |
|
27 | * @param $userId |
|
28 | * |
|
29 | * @return User |
|
30 | * @throws NotFoundException |
|
31 | */ |
|
32 | public function run($userId): User |
|
33 | { |
|
34 | // find the user by its id |
|
35 | try { |
|
36 | $user = $this->repository->find($userId); |
|
37 | } catch (Exception $e) { |
|
38 | throw new NotFoundException(); |
|
39 | } |
|
40 | ||
41 | return $user; |
|
42 | } |
|
43 | ||
44 | } |
|
45 |