notificationService = $notificationService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * * @throws QueryExecutionException * @throws InvalidArgumentException * @throws ForbiddenException */ public function handle(WP_REST_Request $data): WP_REST_Response { // Verify the nonce Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); // Validate request data if (empty($data->get_params())) { throw new InvalidArgumentException('Invalid request data.'); } // Sanitize the input data $params = Sanitizer::sanitizeNotificationData($data->get_params()); $notification = NotificationFactory::create($params); $notificationId = $this->notificationService->createNotification($notification); if (!$notificationId) { throw new QueryExecutionException('Failed to create notification.'); } $notification->setId($notificationId); return new WP_REST_Response([ 'message' => 'OK', 'data' => $notification->toArray() ], 200); } }