| @@ 18-53 (lines=36) @@ | ||
| 15 | use Longman\Platfourm\Service\EntityService; |
|
| 16 | use Longman\Platfourm\User\Repositories\Eloquent\UserRepository; |
|
| 17 | ||
| 18 | class RestoreUserService extends EntityService |
|
| 19 | { |
|
| 20 | ||
| 21 | protected $repository; |
|
| 22 | ||
| 23 | protected $authUserService; |
|
| 24 | ||
| 25 | public function __construct( |
|
| 26 | AuthUserService $authUserService, |
|
| 27 | UserRepository $repository |
|
| 28 | ) { |
|
| 29 | $this->authUserService = $authUserService; |
|
| 30 | $this->repository = $repository; |
|
| 31 | ||
| 32 | $authUserService->should('user.delete'); |
|
| 33 | } |
|
| 34 | ||
| 35 | public function run($id) |
|
| 36 | { |
|
| 37 | $this->checkRepository(); |
|
| 38 | ||
| 39 | $item = $this->repository->withTrashed()->find($id); |
|
| 40 | ||
| 41 | if (!$item->trashed()) { |
|
| 42 | throw new Exception('Entity is not trashed'); |
|
| 43 | } |
|
| 44 | ||
| 45 | /*if (!$this->authUserService->canDeleteUser($item)) { |
|
| 46 | throw new ForbiddenException('Do not have permission to update this user'); |
|
| 47 | }*/ |
|
| 48 | ||
| 49 | $item = $this->repository->restore($id); |
|
| 50 | ||
| 51 | return $item; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 18-46 (lines=29) @@ | ||
| 15 | use Longman\Platfourm\Service\EntityService; |
|
| 16 | use Longman\Platfourm\User\Repositories\Eloquent\UserRepository; |
|
| 17 | ||
| 18 | class UpdateUserStatusService extends EntityService |
|
| 19 | { |
|
| 20 | protected $repository; |
|
| 21 | protected $authUserService; |
|
| 22 | ||
| 23 | public function __construct( |
|
| 24 | AuthUserService $authUserService, |
|
| 25 | UserRepository $repository |
|
| 26 | ) { |
|
| 27 | ||
| 28 | $this->authUserService = $authUserService; |
|
| 29 | $this->repository = $repository; |
|
| 30 | ||
| 31 | $authUserService->should('user.update'); |
|
| 32 | } |
|
| 33 | ||
| 34 | public function run($id, $state) |
|
| 35 | { |
|
| 36 | $item = $this->repository->find($id); |
|
| 37 | ||
| 38 | if (!$this->authUserService->canUpdateUser($item)) { |
|
| 39 | throw new ForbiddenException('Do not have permission to update this user'); |
|
| 40 | } |
|
| 41 | ||
| 42 | $item->update(['status' => $state]); |
|
| 43 | ||
| 44 | return $item; |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||