diff --git a/app/Http/Controllers/ThreadController.php b/app/Http/Controllers/ThreadController.php new file mode 100644 index 0000000..f67d9df --- /dev/null +++ b/app/Http/Controllers/ThreadController.php @@ -0,0 +1,15 @@ +route('subforum', null); + $page = $request->route('page', 1); + + $subforum = Subforum::get($subforumId, $page); + + return view('page/subforum', [ + 'subforum' => $subforum + ]); + } + + public function popular(Request $request) + { + return 'popular'; + } + + public function latest(Request $request) + { + return 'latest'; + } + +} diff --git a/app/Knockout/Subforum.php b/app/Knockout/Subforum.php index 9377dad..08b36ae 100644 --- a/app/Knockout/Subforum.php +++ b/app/Knockout/Subforum.php @@ -6,13 +6,23 @@ use Illuminate\Support\Facades\Cache; class Subforum { - private static function unwrap($subforum) + public $id; + public $name; + public $description; + + public $threads; + + public static function unwrap($subforum) { $s = new self(); $s->id = $subforum->id; $s->name = $subforum->name; - $s->description = $subforum->description; + $s->description = $subforum->description ?? null; + + $s->threads = array_map(function($thread) { + return Thread::unwrap($thread); + }, $subforum->threads ?? []); return $s; } @@ -26,6 +36,13 @@ class Subforum { }, $json->list); } + public static function get(int $subforumId, int $page = 1) + { + $data = (new AbstractData)->httpGet(sprintf('/subforum/%s/%s', $subforumId, $page)); + $json = json_decode($data); + return self::unwrap($json); + } + public static function updateCache() { Cache::forever('subforums', self::getAll()); @@ -33,7 +50,7 @@ class Subforum { public static function getCache() { - return Cache::get('subforums', []); + return Cache::get('subforums', self::getAll()); } } diff --git a/app/Knockout/Thread.php b/app/Knockout/Thread.php new file mode 100644 index 0000000..5f2b8fe --- /dev/null +++ b/app/Knockout/Thread.php @@ -0,0 +1,39 @@ +id = $thread->id; + $s->title = $thread->title; + + return $s; + } + + public static function get(int $threadId, int $page = 1) + { + $data = (new AbstractData)->httpGet(sprintf('/thread/%s/%s', $threadId, $page)); + $json = json_decode($data); + return self::unwrap($thread); + } + + public static function updateCache(int $subforumId, int $page = 0) + { + Cache::forever('threads-' . $subforumId, self::getAll()); + } + + public static function getCache(int $subforumId, int $page = 0) + { + return Cache::get('threads-' . $subforumId, self::getAll()); + } + +} diff --git a/resources/views/page/index.blade.php b/resources/views/page/index.blade.php index 334f562..776247e 100644 --- a/resources/views/page/index.blade.php +++ b/resources/views/page/index.blade.php @@ -1,5 +1,9 @@ @extends('default') +@section('breadcrumb') +Home +@endsection + @section('content')