initial
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class RsvFormController {
|
||||
private $namespace;
|
||||
private $resource_name;
|
||||
|
||||
public function __construct() {
|
||||
$this->namespace = 'reservations/v1';
|
||||
$this->resource_name = 'form';
|
||||
}
|
||||
|
||||
public function register_routes(): void {
|
||||
register_rest_route($this->namespace, '/' . $this->resource_name . '/(?P<id>[^/]+)', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'handle'],
|
||||
// Public: site visitors submit reservation forms. The handler validates
|
||||
// the form definition and payload before persisting anything.
|
||||
'permission_callback' => [RsvRestPolicy::class, 'open']
|
||||
]);
|
||||
}
|
||||
|
||||
function handle(WP_REST_Request $request) {
|
||||
$submitter = new RsvFormSubmission();
|
||||
$submit_result = $submitter->submit($request->get_param("id"), $request->get_json_params());
|
||||
|
||||
if(isset($submit_result['success']) && $submit_result['success'] === true) {
|
||||
return new WP_REST_Response($submit_result, 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($submit_result, 400);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user