| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Controllers\GoogleSheets; |
| 4 |
|
| 5 |
use IvyForms\Common\Exceptions\ForbiddenException; |
| 6 |
use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 7 |
use IvyForms\Common\Sanitizer\Sanitizer; |
| 8 |
use IvyForms\Controllers\Controller; |
| 9 |
use IvyForms\Services\GoogleSheets\GoogleSheetsManagerService; |
| 10 |
use WP_REST_Request; |
| 11 |
use WP_REST_Response; |
| 12 |
|
| 13 |
class GoogleSheetsUpdateStatusController extends Controller |
| 14 |
{ |
| 15 |
private GoogleSheetsManagerService $managerService; |
| 16 |
|
| 17 |
public function __construct(GoogleSheetsManagerService $managerService) |
| 18 |
{ |
| 19 |
$this->managerService = $managerService; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* @throws ForbiddenException |
| 24 |
* @throws InvalidArgumentException |
| 25 |
*/ |
| 26 |
protected function handle(WP_REST_Request $data): WP_REST_Response |
| 27 |
{ |
| 28 |
Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); |
| 29 |
|
| 30 |
$id = Sanitizer::sanitizeId((int) $data->get_param('id')); |
| 31 |
|
| 32 |
if ($id <= 0) { |
| 33 |
throw new InvalidArgumentException('Integration ID is required'); |
| 34 |
} |
| 35 |
|
| 36 |
$integration = $this->managerService->updateStatus($id); |
| 37 |
|
| 38 |
return new WP_REST_Response($integration->toArray(), 200); |
| 39 |
} |
| 40 |
} |
| 41 |
|