Skip to content

Commit

Permalink
feat: add flush-cache endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vermorag committed Jun 21, 2024
1 parent a768e00 commit a9f6ea7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Controllers/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Cdek\Actions\GenerateWaybillAction;
use Cdek\CdekApi;
use Cdek\Config;
use Cdek\Helpers\DBTokenStorage;
use Cdek\Model\OrderMetaData;
use WP_REST_Request;
use WP_REST_Response;
Expand All @@ -23,6 +24,13 @@ public static function checkAuth(): WP_REST_Response
return new WP_REST_Response(['state' => (new CdekApi)->checkAuth()], 200);
}

public static function resetCache(): WP_REST_Response
{
DBTokenStorage::flushCache();

return new WP_REST_Response(['state' => 'OK'], 200);
}

/**
* @throws \JsonException
*/
Expand All @@ -45,7 +53,13 @@ public function __invoke(): void
register_rest_route(Config::DELIVERY_NAME, '/check-auth', [
'methods' => WP_REST_Server::READABLE,
'callback' => [__CLASS__, 'checkAuth'],
'permission_callback' => '__return_true',
'permission_callback' => static fn() => current_user_can('manage_woocommerce'),
]);

register_rest_route(Config::DELIVERY_NAME, '/flush-cache', [
'methods' => WP_REST_Server::READABLE,
'callback' => [__CLASS__, 'resetCache'],
'permission_callback' => static fn() => current_user_can('manage_woocommerce'),
]);

register_rest_route(Config::DELIVERY_NAME, '/order/(?P<id>\d+)/waybill', [
Expand Down

0 comments on commit a9f6ea7

Please sign in to comment.