Files
orderPRO/routes/web.php
Jacek Pyziak eb5c9bf345 feat(06-sonarqube-quality): split god classes — ShopproOrdersSyncService + AllegroIntegrationController (06-05)
ShopproOrdersSyncService: 39→9 methods via ShopproOrderMapper + ShopproProductImageResolver.
AllegroIntegrationController: 35→25 methods via AllegroStatusMappingController + AllegroDeliveryMappingController.
S1448 violations: 6x→2x. CronHandlerFactory and routes/web.php updated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 17:25:59 +01:00

274 lines
14 KiB
PHP

<?php
declare(strict_types=1);
use App\Core\Application;
use App\Core\Http\Request;
use App\Core\Http\Response;
use App\Modules\Auth\AuthController;
use App\Modules\Auth\AuthMiddleware;
use App\Modules\Cron\CronRepository;
use App\Modules\Orders\OrdersController;
use App\Modules\Orders\OrderImportRepository;
use App\Modules\Orders\OrdersRepository;
use App\Modules\Settings\AllegroApiClient;
use App\Modules\Settings\AllegroDeliveryMappingController;
use App\Modules\Settings\AllegroIntegrationController;
use App\Modules\Settings\AllegroIntegrationRepository;
use App\Modules\Settings\AllegroOAuthClient;
use App\Modules\Settings\AllegroOrderImportService;
use App\Modules\Settings\AllegroStatusDiscoveryService;
use App\Modules\Settings\AllegroStatusMappingController;
use App\Modules\Settings\AllegroTokenManager;
use App\Modules\Settings\AllegroStatusMappingRepository;
use App\Modules\Settings\OrderStatusRepository;
use App\Modules\Settings\ApaczkaApiClient;
use App\Modules\Settings\ApaczkaIntegrationController;
use App\Modules\Settings\ApaczkaIntegrationRepository;
use App\Modules\Settings\CarrierDeliveryMethodMappingRepository;
use App\Modules\Settings\InpostIntegrationController;
use App\Modules\Settings\InpostIntegrationRepository;
use App\Modules\Settings\IntegrationsHubController;
use App\Modules\Settings\IntegrationsRepository;
use App\Modules\Settings\ShopproIntegrationsController;
use App\Modules\Settings\ShopproIntegrationsRepository;
use App\Modules\Settings\ShopproStatusMappingRepository;
use App\Modules\Settings\CompanySettingsController;
use App\Modules\Settings\CompanySettingsRepository;
use App\Modules\Settings\CronSettingsController;
use App\Modules\Settings\SettingsController;
use App\Modules\Shipments\ApaczkaShipmentService;
use App\Modules\Shipments\AllegroShipmentService;
use App\Modules\Shipments\ShipmentController;
use App\Modules\Shipments\ShipmentPackageRepository;
use App\Modules\Shipments\ShipmentProviderRegistry;
use App\Modules\Users\UsersController;
return static function (Application $app): void {
$router = $app->router();
$template = $app->template();
$auth = $app->auth();
$translator = $app->translator();
$authController = new AuthController($template, $auth, $translator);
$usersController = new UsersController($template, $translator, $auth, $app->users());
$shipmentPackageRepositoryForOrders = new ShipmentPackageRepository($app->db());
$ordersController = new OrdersController($template, $translator, $auth, $app->orders(), $shipmentPackageRepositoryForOrders);
$settingsController = new SettingsController($template, $translator, $auth, $app->migrator(), $app->orderStatuses());
$allegroIntegrationRepository = new AllegroIntegrationRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
);
$allegroStatusMappingRepository = new AllegroStatusMappingRepository($app->db());
$carrierDeliveryMappings = new CarrierDeliveryMethodMappingRepository($app->db());
$allegroOAuthClient = new AllegroOAuthClient();
$allegroTokenManager = new AllegroTokenManager($allegroIntegrationRepository, $allegroOAuthClient);
$apaczkaApiClient = new ApaczkaApiClient();
$cronRepository = new CronRepository($app->db());
$apaczkaIntegrationRepository = new ApaczkaIntegrationRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
);
$allegroStatusDiscoveryService = new AllegroStatusDiscoveryService(
$allegroTokenManager,
new AllegroApiClient(),
$allegroStatusMappingRepository
);
$allegroStatusMappingController = new AllegroStatusMappingController(
$translator,
$allegroStatusMappingRepository,
$app->orderStatuses(),
$allegroStatusDiscoveryService
);
$allegroDeliveryMappingController = new AllegroDeliveryMappingController(
$translator,
$allegroIntegrationRepository,
$allegroOAuthClient,
new AllegroApiClient(),
$carrierDeliveryMappings,
$apaczkaIntegrationRepository,
$apaczkaApiClient
);
$allegroIntegrationController = new AllegroIntegrationController(
$template,
$translator,
$auth,
$allegroIntegrationRepository,
$allegroStatusMappingRepository,
$app->orderStatuses(),
$cronRepository,
$allegroOAuthClient,
new AllegroOrderImportService(
$allegroIntegrationRepository,
$allegroTokenManager,
new AllegroApiClient(),
new OrderImportRepository($app->db()),
$allegroStatusMappingRepository,
new OrdersRepository($app->db())
),
$allegroStatusDiscoveryService,
(string) $app->config('app.url', ''),
$allegroDeliveryMappingController
);
$apaczkaIntegrationController = new ApaczkaIntegrationController(
$template,
$translator,
$auth,
$apaczkaIntegrationRepository,
$apaczkaApiClient
);
$inpostIntegrationRepository = new InpostIntegrationRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
);
$inpostIntegrationController = new InpostIntegrationController(
$template,
$translator,
$auth,
$inpostIntegrationRepository
);
$shopproIntegrationsRepository = new ShopproIntegrationsRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
);
$shopproIntegrationsController = new ShopproIntegrationsController(
$template,
$translator,
$auth,
$shopproIntegrationsRepository,
new ShopproStatusMappingRepository($app->db()),
$app->orderStatuses(),
$cronRepository,
$carrierDeliveryMappings,
$allegroIntegrationRepository,
$allegroOAuthClient,
new AllegroApiClient(),
$apaczkaIntegrationRepository,
$apaczkaApiClient
);
$integrationsHubController = new IntegrationsHubController(
$template,
$translator,
$auth,
new IntegrationsRepository($app->db()),
$allegroIntegrationRepository,
$apaczkaIntegrationRepository,
$inpostIntegrationRepository,
$shopproIntegrationsRepository
);
$cronSettingsController = new CronSettingsController(
$template,
$translator,
$auth,
$cronRepository,
(bool) $app->config('app.cron.run_on_web_default', false),
(int) $app->config('app.cron.web_limit_default', 5)
);
$companySettingsRepository = new CompanySettingsRepository($app->db());
$companySettingsController = new CompanySettingsController(
$template,
$translator,
$auth,
$companySettingsRepository
);
$allegroApiClient = new AllegroApiClient();
$shipmentPackageRepository = new ShipmentPackageRepository($app->db());
$shipmentService = new AllegroShipmentService(
$allegroTokenManager,
$allegroApiClient,
$shipmentPackageRepository,
$companySettingsRepository,
new OrdersRepository($app->db())
);
$apaczkaShipmentService = new ApaczkaShipmentService(
$apaczkaIntegrationRepository,
$apaczkaApiClient,
$shipmentPackageRepository,
$companySettingsRepository,
new OrdersRepository($app->db())
);
$shipmentProviderRegistry = new ShipmentProviderRegistry([
$shipmentService,
$apaczkaShipmentService,
]);
$shipmentController = new ShipmentController(
$template,
$translator,
$auth,
$app->orders(),
$companySettingsRepository,
$shipmentProviderRegistry,
$shipmentPackageRepository,
$app->basePath('storage'),
$carrierDeliveryMappings
);
$authMiddleware = new AuthMiddleware($auth);
$router->get('/health', static fn (Request $request): Response => Response::json([
'status' => 'ok',
'app' => (string) $app->config('app.name', 'orderPRO'),
'timestamp' => date(DATE_ATOM),
]));
$router->get('/', static function (Request $request) use ($auth): Response {
return $auth->check()
? Response::redirect('/settings/users')
: Response::redirect('/login');
});
$router->get('/login', [$authController, 'showLogin']);
$router->post('/login', [$authController, 'login']);
$router->post('/logout', [$authController, 'logout'], [$authMiddleware]);
$router->get('/users', static fn (Request $request): Response => Response::redirect('/settings/users'), [$authMiddleware]);
$router->get('/orders', static fn (Request $request): Response => Response::redirect('/orders/list'), [$authMiddleware]);
$router->get('/orders/list', [$ordersController, 'index'], [$authMiddleware]);
$router->get('/orders/{id}', [$ordersController, 'show'], [$authMiddleware]);
$router->post('/orders/{id}/status', [$ordersController, 'updateStatus'], [$authMiddleware]);
$router->post('/users', [$usersController, 'store'], [$authMiddleware]);
$router->get('/settings/users', [$usersController, 'index'], [$authMiddleware]);
$router->post('/settings/users', [$usersController, 'store'], [$authMiddleware]);
$router->get('/settings', static fn (Request $request): Response => Response::redirect('/settings/users'), [$authMiddleware]);
$router->get('/settings/database', [$settingsController, 'database'], [$authMiddleware]);
$router->post('/settings/database/migrate', [$settingsController, 'migrate'], [$authMiddleware]);
$router->get('/settings/statuses', [$settingsController, 'statuses'], [$authMiddleware]);
$router->post('/settings/status-groups', [$settingsController, 'createStatusGroup'], [$authMiddleware]);
$router->post('/settings/status-groups/update', [$settingsController, 'updateStatusGroup'], [$authMiddleware]);
$router->post('/settings/status-groups/delete', [$settingsController, 'deleteStatusGroup'], [$authMiddleware]);
$router->post('/settings/status-groups/reorder', [$settingsController, 'reorderStatusGroups'], [$authMiddleware]);
$router->post('/settings/statuses/create', [$settingsController, 'createStatus'], [$authMiddleware]);
$router->post('/settings/statuses/update', [$settingsController, 'updateStatus'], [$authMiddleware]);
$router->post('/settings/statuses/delete', [$settingsController, 'deleteStatus'], [$authMiddleware]);
$router->post('/settings/statuses/reorder', [$settingsController, 'reorderStatuses'], [$authMiddleware]);
$router->get('/settings/cron', [$cronSettingsController, 'index'], [$authMiddleware]);
$router->post('/settings/cron', [$cronSettingsController, 'save'], [$authMiddleware]);
$router->get('/settings/integrations', [$integrationsHubController, 'index'], [$authMiddleware]);
$router->get('/settings/integrations/allegro', [$allegroIntegrationController, 'index'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/save', [$allegroIntegrationController, 'save'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/settings/save', [$allegroIntegrationController, 'saveImportSettings'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/oauth/start', [$allegroIntegrationController, 'startOAuth'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/import-single', [$allegroIntegrationController, 'importSingleOrder'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/statuses/save', [$allegroStatusMappingController, 'saveStatusMapping'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/statuses/save-bulk', [$allegroStatusMappingController, 'saveStatusMappingsBulk'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/statuses/delete', [$allegroStatusMappingController, 'deleteStatusMapping'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/statuses/sync', [$allegroStatusMappingController, 'syncStatusesFromAllegro'], [$authMiddleware]);
$router->post('/settings/integrations/allegro/delivery/save', [$allegroDeliveryMappingController, 'saveDeliveryMappings'], [$authMiddleware]);
$router->get('/settings/integrations/allegro/oauth/callback', [$allegroIntegrationController, 'oauthCallback']);
$router->get('/settings/integrations/apaczka', [$apaczkaIntegrationController, 'index'], [$authMiddleware]);
$router->post('/settings/integrations/apaczka/save', [$apaczkaIntegrationController, 'save'], [$authMiddleware]);
$router->post('/settings/integrations/apaczka/test', [$apaczkaIntegrationController, 'test'], [$authMiddleware]);
$router->get('/settings/integrations/inpost', [$inpostIntegrationController, 'index'], [$authMiddleware]);
$router->post('/settings/integrations/inpost/save', [$inpostIntegrationController, 'save'], [$authMiddleware]);
$router->get('/settings/integrations/shoppro', [$shopproIntegrationsController, 'index'], [$authMiddleware]);
$router->post('/settings/integrations/shoppro/save', [$shopproIntegrationsController, 'save'], [$authMiddleware]);
$router->post('/settings/integrations/shoppro/test', [$shopproIntegrationsController, 'test'], [$authMiddleware]);
$router->post('/settings/integrations/shoppro/statuses/save', [$shopproIntegrationsController, 'saveStatusMappings'], [$authMiddleware]);
$router->post('/settings/integrations/shoppro/statuses/sync', [$shopproIntegrationsController, 'syncStatuses'], [$authMiddleware]);
$router->post('/settings/integrations/shoppro/delivery/save', [$shopproIntegrationsController, 'saveDeliveryMappings'], [$authMiddleware]);
$router->get('/settings/company', [$companySettingsController, 'index'], [$authMiddleware]);
$router->post('/settings/company/save', [$companySettingsController, 'save'], [$authMiddleware]);
$router->get('/orders/{id}/shipment/prepare', [$shipmentController, 'prepare'], [$authMiddleware]);
$router->post('/orders/{id}/shipment/create', [$shipmentController, 'create'], [$authMiddleware]);
$router->get('/orders/{id}/shipment/{packageId}/status', [$shipmentController, 'checkStatus'], [$authMiddleware]);
$router->post('/orders/{id}/shipment/{packageId}/label', [$shipmentController, 'label'], [$authMiddleware]);
};