| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Controllers\GoogleSheets; |
| 4 |
|
| 5 |
use IvyForms\Common\Exceptions\ForbiddenException; |
| 6 |
use IvyForms\Common\Sanitizer\Sanitizer; |
| 7 |
use IvyForms\Controllers\Controller; |
| 8 |
use IvyForms\Services\GoogleSheets\GoogleSheetsService; |
| 9 |
use WP_REST_Request; |
| 10 |
use WP_REST_Response; |
| 11 |
|
| 12 |
class GoogleSheetsListColumnsController extends Controller |
| 13 |
{ |
| 14 |
private GoogleSheetsService $googleSheetsService; |
| 15 |
|
| 16 |
public function __construct(GoogleSheetsService $googleSheetsService) |
| 17 |
{ |
| 18 |
$this->googleSheetsService = $googleSheetsService; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* @throws ForbiddenException |
| 23 |
*/ |
| 24 |
protected function handle(WP_REST_Request $data): WP_REST_Response |
| 25 |
{ |
| 26 |
Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); |
| 27 |
|
| 28 |
$spreadsheetId = Sanitizer::sanitizeText((string) $data->get_param('spreadsheet_id')); |
| 29 |
$worksheetName = Sanitizer::sanitizeText((string) $data->get_param('worksheet_name')); |
| 30 |
|
| 31 |
return new WP_REST_Response([ |
| 32 |
'columns' => $this->googleSheetsService->listColumns($spreadsheetId, $worksheetName), |
| 33 |
], 200); |
| 34 |
} |
| 35 |
} |
| 36 |
|