Files
ntspi-app/app/Services/Vicon/EducationalProgram/EducationalProgramService.php
T
F4ilji 2d101dcdda 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.
2025-12-16 12:20:01 +05:00

58 lines
1.7 KiB
PHP

<?php
namespace App\Services\Vicon\EducationalProgram;
use App\Jobs\CreateDirectionStudy;
use App\Jobs\CreateEducationalProgram;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class EducationalProgramService
{
const EDU_LEVELS = [1,2,3,4,5,6];
public function getAllProgramsUuid() : array
{
$programs = [];
$programsUuid = [];
foreach (self::EDU_LEVELS as $level) {
$data = $this->getPrograms($level);
$programs = array_merge($programs, $data->rows);
}
foreach ($programs as $program) {
$programsUuid[] = $program->uuid;
}
return $programsUuid;
}
public function getPrograms(int $edu_level) : object
{
$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", config('services.vicon.token'));
return $data;
}
private function callAPI(string $endpoint, string $token = null): object
{
try {
$response = Http::withToken($token)->get($endpoint);
$data = $response->object();
// Проверяем наличие сообщения об ошибке в ответе
if (isset($data->message)) {
throw new \Exception($data->message);
}
return $data;
} catch (\Exception $e) {
Log::error('Ошибка при вызове API: ' . $e->getMessage());
throw $e; // Перебрасываем исключение
}
}
}