Skip to content

Commit

Permalink
Now using ForumThreadResource on search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
musa11971 committed Sep 10, 2019
1 parent 494e452 commit 78058a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
20 changes: 3 additions & 17 deletions app/Http/Controllers/ForumThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
]);
}

Expand Down
10 changes: 8 additions & 2 deletions public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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<div class=\"kuro-tip\">You can prefix your search with \"id:\" to search for Anime with a specific ID.</div>",
"parameters": [
{
Expand Down
3 changes: 2 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down

0 comments on commit 78058a4

Please sign in to comment.