diff --git a/app/Http/Controllers/CareerController.php b/app/Http/Controllers/CareerController.php index fd23d9b..c28ee65 100644 --- a/app/Http/Controllers/CareerController.php +++ b/app/Http/Controllers/CareerController.php @@ -194,6 +194,107 @@ class CareerController extends Controller return redirect()->back()->with('error', 'Dosya yüklenirken bir hata oluştu.'); } + public function saveGithubRepo(Request $request) + { + if (!session()->has('intern_id')) { + return redirect()->route('intern.login')->with('error', 'Lütfen önce giriş yapın.'); + } + + $request->validate([ + 'github_repo' => 'required|string|url|max:255', + ], [ + 'github_repo.required' => 'Lütfen Github depo URL\'sini girin.', + 'github_repo.url' => 'Geçerli bir URL girilmelidir.', + 'github_repo.max' => 'Github depo URL\'si en fazla 255 karakter olabilir.', + ]); + + $intern = CareerApplication::findOrFail(session('intern_id')); + + // Sanitize & format github URL + $repoUrl = trim($request->github_repo); + + $intern->update([ + 'github_repo' => $repoUrl + ]); + + return redirect()->back()->with('success', 'Github deposu başarıyla güncellendi.'); + } + + public function downloadMarkdown() + { + if (!session()->has('intern_id')) { + return redirect()->route('intern.login')->with('error', 'Lütfen önce giriş yapın.'); + } + $intern = CareerApplication::findOrFail(session('intern_id')); + $repo = $intern->github_repo; + if (!$repo) { + return redirect()->back()->with('error', 'Lütfen önce Github deposunu tanımlayın.'); + } + + // Parse owner and repo + // E.g., https://github.com/owner/repo or owner/repo + $repoClean = str_replace(['https://github.com/', 'http://github.com/', 'https://www.github.com/', 'http://www.github.com/'], '', $repo); + $repoClean = trim($repoClean, '/'); + $parts = explode('/', $repoClean); + if (count($parts) < 2) { + return redirect()->back()->with('error', 'Geçersiz Github depo formatı.'); + } + $owner = $parts[0]; + $repoName = explode('.', $parts[1])[0]; // Remove .git if exists + + // Fetch commits + $url = "https://api.github.com/repos/{$owner}/{$repoName}/commits?per_page=100"; + + $opts = [ + 'http' => [ + 'method' => 'GET', + 'header' => [ + 'User-Agent: PHP-Github-Client', + ] + ] + ]; + $context = stream_context_create($opts); + $response = @file_get_contents($url, false, $context); + + if ($response === false) { + return redirect()->back()->with('error', 'Github API\'den commit bilgileri alınamadı. Deponuzun public olduğundan emin olun.'); + } + + $commits = json_decode($response, true); + if (!is_array($commits)) { + return redirect()->back()->with('error', 'Github API yanıtı çözümlenemedi.'); + } + + // Sort commits chronological (ascending) + $commits = array_reverse($commits); + + // Generate Markdown content + $md = "# Staj Günlüğü - " . $intern->name . "\n"; + $md .= "Depo: https://github.com/{$owner}/{$repoName}\n\n"; + + $day = 1; + foreach ($commits as $c) { + $message = $c['commit']['message'] ?? ''; + $dateStr = $c['commit']['author']['date'] ?? ''; + $date = $dateStr ? \Carbon\Carbon::parse($dateStr)->format('d.m.Y H:i') : ''; + $hash = substr($c['sha'] ?? '', 0, 7); + + $md .= "## {$day}. Gün\n"; + $md .= "- **Tarih:** {$date}\n"; + $md .= "- **Commit:** `{$hash}`\n"; + $md .= "- **Mesaj:** {$message}\n\n"; + + $day++; + } + + $fileName = str()->slug($intern->name) . "-staj-gunlugu.md"; + + return response($md, 200, [ + 'Content-Type' => 'text/markdown; charset=UTF-8', + 'Content-Disposition' => 'attachment; filename="' . $fileName . '"', + ]); + } + public function internLogout() { session()->forget('intern_id'); diff --git a/app/Models/CareerApplication.php b/app/Models/CareerApplication.php index cbe7080..6c66df6 100644 --- a/app/Models/CareerApplication.php +++ b/app/Models/CareerApplication.php @@ -29,6 +29,7 @@ class CareerApplication extends Model 'internship_start_date', 'internship_end_date', 'internship_total_days', + 'github_repo', ]; /** diff --git a/database/migrations/2026_06_05_220134_add_github_repo_to_career_applications_table.php b/database/migrations/2026_06_05_220134_add_github_repo_to_career_applications_table.php new file mode 100644 index 0000000..5a693bd --- /dev/null +++ b/database/migrations/2026_06_05_220134_add_github_repo_to_career_applications_table.php @@ -0,0 +1,28 @@ +string('github_repo')->nullable()->after('internship_total_days'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('career_applications', function (Blueprint $table) { + $table->dropColumn('github_repo'); + }); + } +}; diff --git a/resources/views/front/career/intern_dashboard.blade.php b/resources/views/front/career/intern_dashboard.blade.php index 93c9cac..e7eae3d 100644 --- a/resources/views/front/career/intern_dashboard.blade.php +++ b/resources/views/front/career/intern_dashboard.blade.php @@ -53,252 +53,354 @@
Başvuru sırasında yüklemiş olduğunuz özgeçmiş belgeniz.
+