From 78058a42bf2c0c602336831d4a448584ee5fb095 Mon Sep 17 00:00:00 2001 From: musa11971 Date: Tue, 10 Sep 2019 18:43:03 +0200 Subject: [PATCH] Now using ForumThreadResource on search endpoint --- .../Controllers/ForumThreadController.php | 20 +++---------------- public/openapi.json | 10 ++++++++-- routes/api.php | 3 ++- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/ForumThreadController.php b/app/Http/Controllers/ForumThreadController.php index 81471e8a1..e958d5b23 100644 --- a/app/Http/Controllers/ForumThreadController.php +++ b/app/Http/Controllers/ForumThreadController.php @@ -8,6 +8,7 @@ use App\Helpers\CollectionLikeChecker; use App\Helpers\JSONResult; use App\Http\Resources\ForumReplyResource; +use App\Http\Resources\ForumThreadResource; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -196,29 +197,14 @@ public function search(Request $request) { $searchQuery = $request->input('query'); // Search for the thread - $resultArr = ForumThread::kuroSearch($searchQuery, [ + $threads = ForumThread::kuroSearch($searchQuery, [ 'limit' => ForumThread::MAX_SEARCH_RESULTS ]); - // Format the results - $displayResults = []; - - foreach($resultArr as $thread) { - $displayResults[] = [ - 'id' => $thread->id, - 'title' => $thread->title, - 'content_teaser' => - substr(strip_tags($thread->content), 0, 100) . - ((strlen($thread->content) > 100) ? '...' : '') - , - 'locked' => (bool) $thread->locked - ]; - } - // Show response return JSONResult::success([ 'max_search_results' => ForumThread::MAX_SEARCH_RESULTS, - 'results' => $displayResults + 'results' => ForumThreadResource::collection($threads) ]); } diff --git a/public/openapi.json b/public/openapi.json index d6d4c2da5..34bf6de44 100644 --- a/public/openapi.json +++ b/public/openapi.json @@ -1113,7 +1113,7 @@ "tags": [ "forum-sections" ], - "summary": "Forum section get threads.", + "summary": "(optional authentication) Forum section get threads.", "description": "This endpoint will retrieve the threads in a forum section.", "parameters": [ { @@ -1572,10 +1572,16 @@ }, "/forum-threads/search": { "get": { + "security": [ + {}, + { + "kurozoraBearer": [] + } + ], "tags": [ "forum-threads" ], - "summary": "Searches forum threads.", + "summary": "(optional authentication) Searches forum threads.", "description": "This endpoint will retrieve the search results for forum threads.\n
You can prefix your search with \"id:\" to search for Anime with a specific ID.
", "parameters": [ { diff --git a/routes/api.php b/routes/api.php index 69bcd968f..a131da5d2 100644 --- a/routes/api.php +++ b/routes/api.php @@ -140,7 +140,8 @@ }); Route::prefix('/forum-threads')->group(function() { - Route::get('/search', [ForumThreadController::class, 'search']); + Route::get('/search', [ForumThreadController::class, 'search']) + ->middleware('kurozora.userauth:optional'); Route::get('/{thread}', [ForumThreadController::class, 'threadInfo']);