feat: [claude-code] Claude Code 뉴스 페이지 추가
- GitHub Releases API 연동 서비스 (1시간 캐싱) - 뉴스 컨트롤러 + Blade 뷰 (릴리즈 카드 목록) - /claude-code/news 라우트 그룹 등록
This commit is contained in:
42
app/Http/Controllers/ClaudeCode/NewsController.php
Normal file
42
app/Http/Controllers/ClaudeCode/NewsController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ClaudeCode;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ClaudeCodeNewsService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ClaudeCodeNewsService $newsService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Claude Code 뉴스 (GitHub Releases) 목록
|
||||
*/
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
if ($request->header('HX-Request')) {
|
||||
return response('', 200)->header('HX-Redirect', route('claude-code.news.index'));
|
||||
}
|
||||
|
||||
$releases = $this->newsService->getReleases();
|
||||
|
||||
return view('claude-code.news.index', compact('releases'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 캐시 새로고침
|
||||
*/
|
||||
public function refreshCache(): RedirectResponse
|
||||
{
|
||||
$this->newsService->clearCache();
|
||||
|
||||
return redirect()->route('claude-code.news.index')
|
||||
->with('success', '캐시가 새로고침되었습니다.');
|
||||
}
|
||||
}
|
||||
74
app/Services/ClaudeCodeNewsService.php
Normal file
74
app/Services/ClaudeCodeNewsService.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ClaudeCodeNewsService
|
||||
{
|
||||
private const CACHE_KEY = 'claude_code_releases';
|
||||
|
||||
private const CACHE_TTL = 3600; // 1시간
|
||||
|
||||
private const API_URL = 'https://api.github.com/repos/anthropics/claude-code/releases';
|
||||
|
||||
/**
|
||||
* GitHub Releases 목록 조회 (캐싱)
|
||||
*/
|
||||
public function getReleases(int $perPage = 20): array
|
||||
{
|
||||
return Cache::remember(self::CACHE_KEY, self::CACHE_TTL, function () use ($perPage) {
|
||||
return $this->fetchFromGitHub($perPage);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 캐시 클리어
|
||||
*/
|
||||
public function clearCache(): void
|
||||
{
|
||||
Cache::forget(self::CACHE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* GitHub API에서 릴리즈 정보 가져오기
|
||||
*/
|
||||
private function fetchFromGitHub(int $perPage): array
|
||||
{
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
'User-Agent' => 'SAM-MNG-App',
|
||||
])->timeout(10)->get(self::API_URL, [
|
||||
'per_page' => $perPage,
|
||||
]);
|
||||
|
||||
if (! $response->successful()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($response->json())
|
||||
->map(function ($release) {
|
||||
return [
|
||||
'id' => $release['id'],
|
||||
'tag_name' => $release['tag_name'],
|
||||
'name' => $release['name'] ?? $release['tag_name'],
|
||||
'body_html' => Str::markdown($release['body'] ?? ''),
|
||||
'published_at' => $release['published_at'],
|
||||
'author' => $release['author']['login'] ?? 'unknown',
|
||||
'author_avatar' => $release['author']['avatar_url'] ?? '',
|
||||
'html_url' => $release['html_url'],
|
||||
'prerelease' => $release['prerelease'] ?? false,
|
||||
'draft' => $release['draft'] ?? false,
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user