1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace App\Src\UseCases\Domain\Context\UseCases; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use App\Src\UseCases\Domain\Ports\ContextRepository; |
8
|
|
|
use App\Src\UseCases\Domain\Ports\UserRepository; |
9
|
|
|
use App\Src\UseCases\Domain\Shared\Gateway\AuthGateway; |
10
|
|
|
use App\Src\UseCases\Domain\System\GetDepartmentFromPostalCode; |
11
|
|
|
|
12
|
|
|
class UpdateMainData |
13
|
|
|
{ |
14
|
|
|
private $contextRepository; |
15
|
|
|
private $authGateway; |
16
|
|
|
private $userRepository; |
17
|
|
|
|
18
|
|
|
public function __construct( |
19
|
|
|
ContextRepository $contextRepository, |
20
|
|
|
AuthGateway $authGateway, |
21
|
|
|
UserRepository $userRepository |
22
|
|
|
) |
23
|
|
|
{ |
24
|
|
|
$this->contextRepository = $contextRepository; |
25
|
|
|
$this->authGateway = $authGateway; |
26
|
|
|
$this->userRepository = $userRepository; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function execute(string $postalCode, string $sector, string $structure, string $email, string $firstname, string $lastname, string $role) |
30
|
|
|
{ |
31
|
|
|
$currentUser = $this->authGateway->current(); |
32
|
|
|
$context = $this->contextRepository->getByUser($currentUser->id()); |
33
|
|
|
|
34
|
|
|
$user = $this->userRepository->getById($currentUser->id()); |
35
|
|
|
$user->update($email, $firstname, $lastname); |
36
|
|
|
$user->updateRole($role); |
37
|
|
|
|
38
|
|
|
$geoData = app(GetDepartmentFromPostalCode::class)->execute($postalCode); |
39
|
|
|
|
40
|
|
|
$context->update([ |
41
|
|
|
'postal_code' => $postalCode, |
42
|
|
|
'sector' => $sector, |
43
|
|
|
'structure' => $structure, |
44
|
|
|
'coordinates' => $geoData['coordinates'], |
45
|
|
|
'department_number' => $geoData['department_number'], |
46
|
|
|
], $currentUser->id()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|