feat: Refactor MainController and related tasks to follow Porto architecture
- Moved logic from MainController to dedicated action and task classes. - Introduced GetMainPageDataAction, GetEducationsDataTask, GetRecentPostsTask, GetUpcomingEventsTask, and GetPageDataTask for better separation of concerns. - Updated routes to use the new MainController from the Main container. - Deprecated the old MainController with a clear message for future removal. - Updated caching mechanisms to use the new task classes. - Adjusted environment variable access to use config() instead of env() for better practice. - Added new MainPageResource for structured data response. - Updated .gitignore to exclude QWEN.md. - Added Jenkins service to docker-compose for CI/CD integration.
This commit is contained in:
@@ -9,7 +9,7 @@ abstract class AbstractCacheService
|
||||
public function clearCacheByPrefix(string $prefix): void
|
||||
{
|
||||
// Получаем префикс из .env
|
||||
$redisPrefix = env('REDIS_PREFIX', 'ntspi');
|
||||
$redisPrefix = config('database.redis.options.prefix', 'ntspi');
|
||||
|
||||
// Получаем ключи, соответствующие префиксу
|
||||
$keys = Redis::keys($prefix);
|
||||
|
||||
@@ -21,8 +21,8 @@ class VkAlbumService
|
||||
public function __construct(VKApiClient $vk) {
|
||||
$this->vk = $vk;
|
||||
$this->vkAuthService = new VkAuthService();
|
||||
$this->serviceToken = env('SERVICE_ACCESS_VK_KEY');
|
||||
$this->publicId = env('PUBLIC_ID');
|
||||
$this->serviceToken = config('services.vk.service_key');
|
||||
$this->publicId = config('services.vk.public_id');
|
||||
}
|
||||
|
||||
public function getServerForUploadImages($album_id, $group_id)
|
||||
@@ -109,7 +109,7 @@ class VkAlbumService
|
||||
$postFields = [
|
||||
'album_id' => $albumId,
|
||||
'server' => $server,
|
||||
'group_id' => env('PUBLIC_ID'),
|
||||
'group_id' => config('services.vk.public_id'),
|
||||
'photos_list' => $photosList, // Преобразуем массив в JSON-строку
|
||||
'hash' => $hash,
|
||||
'access_token' => $this->vkAuthService->getToken()->access_token,
|
||||
|
||||
@@ -33,30 +33,6 @@ class VkAuthService
|
||||
}
|
||||
}
|
||||
|
||||
// public function redirectToProvider()
|
||||
// {
|
||||
// $state = bin2hex(random_bytes(16)); // Генерация случайной строки состояния
|
||||
// session(['vk_state' => $state]); //
|
||||
//
|
||||
// $code_verifier = $this->generateCodeVerifier();
|
||||
// $code_challenge = $this->generateCodeChallenge($code_verifier);
|
||||
//
|
||||
// session(['vk_code_verifier' => $code_verifier]);
|
||||
//
|
||||
//
|
||||
// $url = 'https://id.vk.ru/authorize?' . http_build_query([
|
||||
// 'response_type' => 'code',
|
||||
// 'client_id' => env('VK_APP_ID'),
|
||||
// 'redirect_uri' => env('VK_REDIRECT_URI'),
|
||||
// 'state' => $state,
|
||||
// 'scope' => 'photos wall video docs',
|
||||
// 'code_challenge' => $code_challenge,
|
||||
// 'code_challenge_method' => 's256',
|
||||
// ]);
|
||||
//
|
||||
// return redirect($url);
|
||||
// }
|
||||
|
||||
public function redirectToProvider()
|
||||
{
|
||||
$state = bin2hex(random_bytes(16)); // Генерирует случайную строку состояния (state) для защиты от CSRF-атак.
|
||||
@@ -69,8 +45,8 @@ class VkAuthService
|
||||
|
||||
$url = 'https://id.vk.ru/authorize?' . http_build_query([ // Формирует URL для перенаправления на страницу авторизации VK ID с параметрами:
|
||||
'response_type' => 'code', // Указывает, что нужен код авторизации.
|
||||
'client_id' => env('VK_APP_ID'), // ID приложения VK из переменных окружения.
|
||||
'redirect_uri' => env('VK_REDIRECT_URI'), // URI для перенаправления после авторизации.
|
||||
'client_id' => config('services.vk.app_id'), // ID приложения VK из переменных окружения.
|
||||
'redirect_uri' => config('services.vk.redirect_uri'), // URI для перенаправления после авторизации.
|
||||
'state' => $state, // Передает строку состояния для проверки.
|
||||
'scope' => 'photos wall video docs', // Запрашивает доступ к фото, стене, видео и документам.
|
||||
'code_challenge' => $code_challenge, // Передает code_challenge для PKCE.
|
||||
@@ -115,9 +91,9 @@ class VkAuthService
|
||||
return Http::asForm()->post('https://id.vk.ru/oauth2/auth', [
|
||||
'grant_type' => 'authorization_code',
|
||||
'code_verifier' => $codeVerifier,
|
||||
'redirect_uri' => env('VK_REDIRECT_URI_AFTER_AUTH'),
|
||||
'redirect_uri' => config('services.vk.'),
|
||||
'code' => $request->code,
|
||||
'client_id' => env('VK_APP_ID'),
|
||||
'client_id' => config('services.vk.app_id'),
|
||||
'device_id' => $request->device_id,
|
||||
'state' => $request->state,
|
||||
'scope' => 'photos wall video docs',
|
||||
@@ -129,7 +105,7 @@ class VkAuthService
|
||||
$response = Http::asForm()->post('https://id.vk.ru/oauth2/auth', [
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refresh_token,
|
||||
'client_id' => env('VK_APP_ID'),
|
||||
'client_id' => config('services.vk.app_id'),
|
||||
'device_id' => $device_id,
|
||||
'state' => $state,
|
||||
'scope' => 'photos wall video docs',
|
||||
|
||||
@@ -19,7 +19,7 @@ class VkService
|
||||
$vk = new VKApiClient();
|
||||
$this->wallService = new VkWallService($vk);
|
||||
$this->albumService = new VkAlbumService($vk);
|
||||
$this->public_id = env('PUBLIC_ID');
|
||||
$this->public_id = config('services.vk.public_id');
|
||||
$this->vkAuthService = new VkAuthService();
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class VkService
|
||||
public function createAlbum(string $title, $images)
|
||||
{
|
||||
$album = $this->albumService->createAlbum($title);
|
||||
$uploadServer = $this->albumService->getServerForUploadImages($album['id'], env('PUBLIC_ID'));
|
||||
$uploadServer = $this->albumService->getServerForUploadImages($album['id'], config('services.vk.public_id'));
|
||||
foreach (array_chunk($images, 4) as $images_slice) {
|
||||
$images_data = $this->albumService->uploadImagesToUploadServer($uploadServer['upload_url'], $images_slice);
|
||||
$this->albumService->saveImagesToUploadServer(
|
||||
@@ -142,7 +142,7 @@ class VkService
|
||||
return $baseUrl . $img;
|
||||
}, $images);
|
||||
|
||||
$photos = $this->uploadWallPhotos($imagePaths, env('PUBLIC_ID'));
|
||||
$photos = $this->uploadWallPhotos($imagePaths, config('services.vk.public_id'));
|
||||
|
||||
return implode(',', array_map(function($photo) {
|
||||
return "photo{$photo['owner_id']}_{$photo['id']}";
|
||||
@@ -158,7 +158,7 @@ class VkService
|
||||
$videoPaths = array_map(function($vid) use ($baseUrl) {
|
||||
return $baseUrl . $vid;
|
||||
}, $videos);
|
||||
return $this->uploadVideos($videoPaths, env('PUBLIC_ID')); // Возвращает массив, например: ['video123_456', 'video789_012']
|
||||
return $this->uploadVideos($videoPaths, config('services.vk.public_id')); // Возвращает массив, например: ['video123_456', 'video789_012']
|
||||
}
|
||||
|
||||
private function uploadVideos(array $videoPaths, ?int $groupId = null): array
|
||||
|
||||
@@ -20,10 +20,10 @@ class VkWallService
|
||||
|
||||
public function __construct(VKApiClient $vk) {
|
||||
$this->vk = $vk;
|
||||
$this->wallToken = env('WALL_ACCESS_VK_TOKEN');
|
||||
$this->serviceToken = env('SERVICE_ACCESS_VK_KEY');
|
||||
$this->publicId = env('PUBLIC_ID');
|
||||
$this->publicDomain = env('PUBLIC_DOMAIN');
|
||||
$this->wallToken = config('services.vk.wall_token');
|
||||
$this->serviceToken = config('services.vk.service_key');
|
||||
$this->publicId = config('services.vk.public_id');
|
||||
$this->publicDomain = config('services.vk.public_id');
|
||||
$this->vkAuthService = new VkAuthService();
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class VkWallService
|
||||
|
||||
public function generateAttachmentsParams(string $attachmentType, int $attachmentId)
|
||||
{
|
||||
$pubic_id = env('PUBLIC_ID');
|
||||
$pubic_id = config('services.vk.public_id');
|
||||
switch ($attachmentType) {
|
||||
case 'album': {
|
||||
return "album-{$pubic_id}_{$attachmentId}";
|
||||
|
||||
@@ -28,7 +28,7 @@ class AdmissionPlanService
|
||||
try {
|
||||
$response = $this->callAPI(
|
||||
"https://db-nica.ru/api/v1/campaigns",
|
||||
env('VICON_TOKEN')
|
||||
config('services.vicon.token')
|
||||
);
|
||||
if (!is_array($response)) {
|
||||
Log::warning('Unexpected response type in getCampaigns', [
|
||||
@@ -52,7 +52,7 @@ class AdmissionPlanService
|
||||
try {
|
||||
$response = $this->callAPI(
|
||||
"https://db-nica.ru/api/v1/planPriema/$campaign_levels_code",
|
||||
env('VICON_TOKEN')
|
||||
config('services.vicon.token')
|
||||
);
|
||||
|
||||
if (!is_object($response)) {
|
||||
|
||||
@@ -40,31 +40,31 @@ class DirectionStudyService
|
||||
|
||||
public function getNaprs(int $edu_level): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/naprs?perPage=200&filter_edu_level=$edu_level", env('VICON_TOKEN'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/naprs?perPage=200&filter_edu_level=$edu_level", config('services.vicon.token'));
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNapr(string $uuid): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/napr/$uuid", env('VICON_TOKEN'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/napr/$uuid", config('services.vicon.token'));
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPrograms(int $edu_level): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", env('VICON_TOKEN'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", config('services.vicon.token'));
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getProgram(string $uuid): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", env('VICON_TOKEN'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", config('services.vicon.token'));
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getProgramDocs(string $uuid): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid/edu-docs?perPage=200", env('VICON_TOKEN'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid/edu-docs?perPage=200", config('services.vicon.token'));
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ class EducationalProgramService
|
||||
|
||||
public function getPrograms(int $edu_level) : object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", env('VICON_TOKEN'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", config('services.vicon.token'));
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getProgram(string $uuid) : object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", env('VICON_TOKEN'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", config('services.vicon.token'));
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user