Jake Vanderwerf
8 days ago 3b83905603d44b1a08f8b2b36a605808ce686ad6
inc/rest/routes/SEORoutes.php
@@ -1,10 +1,12 @@
<?php
namespace JVBase\rest\routes;
use JVBase\rest\RestRouteManager;
use JVBase\registrar\Registrar;
use JVBase\rest\Rest;
use JVBase\managers\Cache;
use JVBase\managers\SEO\ConfigManager;
use JVBase\managers\SEO\SchemaBuilder;
use JVBase\rest\Route;
use WP_REST_Request;
use WP_REST_Response;
use WP_Error;
@@ -19,15 +21,15 @@
 * Handles REST API endpoints for SEO configuration
 * Works with FormController.js for unified form handling
 */
class SEORoutes extends RestRouteManager
class SEORoutes extends Rest
{
   protected SchemaBuilder $registry;
// protected SchemaBuilder $registry;
   public function __construct()
   {
      $this->cache_name = 'schema';
      $this->cacheName = 'schema';
      parent::__construct();
      $this->registry = SchemaBuilder::getInstance();
//    $this->registry = SchemaBuilder::getInstance();
   }
   /**
@@ -35,42 +37,23 @@
    */
   public function registerRoutes(): void
   {
      // Main SEO endpoint - handles save, reset, preview
      register_rest_route($this->namespace, '/seo', [
         [
            'methods' => 'POST',
            'callback' => [$this, 'handleSEO'],
            'permission_callback' => fn() => current_user_can('manage_options'),
            'args' => [
               'action' => [
                  'required' => false,
                  'type' => 'string',
                  'default' => 'save',
                  'enum' => ['save', 'reset', 'preview']
               ],
               'context' => [
                  'required' => true,
                  'type' => 'string',
                  'description' => 'site, business, or content/taxonomy/user type'
               ]
            ]
         ]
      ]);
      Route::for('seo')
         ->post([$this, 'handleSEO'])
         ->auth('admin')
         ->args([
            'action' => 'string|required|enum:save,reset,preview',
            'context'=> 'string|required'
         ])
         ->rateLimit(30)
         ->register();
      // Get fields for a schema type (for dynamic type switching)
      register_rest_route($this->namespace, '/seo/fields', [
         [
            'methods' => 'GET',
            'callback' => [$this, 'getFields'],
            'permission_callback' => fn() => current_user_can('manage_options'),
            'args' => [
               'type' => [
                  'required' => true,
                  'type' => 'string'
               ]
            ]
         ]
      ]);
      Route::for('seo/fields')
         ->get([$this, 'getFields'])
         ->auth('admin')
         ->args([
            'type'=>'string|required'
         ])
         ->register();
   }
   /**
@@ -140,11 +123,7 @@
      // Invalidate cache
      $this->cache->flush();
      return new WP_REST_Response([
         'success' => true,
         'status' => 'completed',
         'message' => ucfirst($context) . ' settings saved successfully'
      ]);
      return$this->success(['message'=>ucfirst($context).' settings saved successfully']);
   }
   /**
@@ -189,11 +168,7 @@
      // Invalidate cache
      $this->cache->flush();
      return new WP_REST_Response([
         'success' => true,
         'status' => 'completed',
         'message' => 'Configuration saved successfully'
      ]);
      return $this->success(['status'=> 'completed', 'message' => 'Configuration saved successfully']);
   }
   /**
@@ -226,8 +201,7 @@
      // Invalidate cache
      $this->cache->flush();
      return new WP_REST_Response([
         'success' => true,
      return $this->success([
         'status' => 'completed',
         'message' => 'Reset to defaults successfully',
         'meta' => $config->meta(),
@@ -261,8 +235,7 @@
         $schema[$fieldName] = $value;
      }
      return new WP_REST_Response([
         'success' => true,
      return $this->success([
         'schema' => $schema
      ]);
   }
@@ -275,10 +248,10 @@
   {
      $type = $request->get_param('type');
      // Get MetaManager field definitions from registry
      // Get Meta field definitions from registry
      $fields = $this->registry->getMetaConfigForType($type);
      return new WP_REST_Response($fields);
      return $this->success($fields);
   }
   /**
@@ -292,6 +265,6 @@
      }
      // Check if it's a valid content/taxonomy/user type
      return $this->checkContent($context, true);
      return (bool)Registrar::getInstance($context);
   }
}