-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ route
/forums/{fid}/threads/tid
forwarding to `App\Http\Controlle…
…rs\ThreadsIDQuery->query()` @ routes/api.php + `App\Http\Controllers\ThreadsIDQuery` to print tid by every 1k threads with cursor pagination * replace the invoking to `Symfony\Component\HttpFoundation\Response->send()` with `Illuminate\Http\ResponseTrait::throwResponse()` to pass through registered middlewares * rename error code `40006` to `40406` @ `App\Helper->abortAPI()` * replace usages of facade `\Response::` with global function `response()` @ `App\Exceptions\Handler->convertValidationExceptionToResponse()` & `App\Helper->abortAPI()` @ be
- Loading branch information
Showing
5 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Eloquent\Model\Forum; | ||
use App\Eloquent\Model\Post\PostFactory; | ||
use App\Helper; | ||
use Illuminate\Pagination\Cursor; | ||
|
||
class ThreadsIDQuery extends Controller | ||
{ | ||
public function query(\Illuminate\Http\Request $request, int $fid): array | ||
{ | ||
['cursor' => $cursor] = $request->validate([ | ||
'cursor' => 'integer' | ||
]) + ['cursor' => 0]; | ||
Helper::abortAPIIfNot(40406, (new Forum())->fid($fid)->exists()); | ||
$thread = PostFactory::newThread($fid); | ||
$primaryKey = $thread->getTable() . '.tid'; | ||
$paginators = $thread->cursorPaginate(1000, columns: 'tid', cursor: new Cursor([$primaryKey => $cursor])); | ||
|
||
return [ | ||
'pages' => [ | ||
'currentCursor' => $paginators->cursor()->parameter($primaryKey), | ||
'nextCursor' => $paginators->nextCursor()->parameter($primaryKey) | ||
], | ||
'tid' => array_column($paginators->items(), 'tid') | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
<?php | ||
|
||
use App\Http\Controllers\PostsQuery; | ||
use App\Http\Controllers\UsersQuery; | ||
use App\Http\Controllers; | ||
use App\Http\Middleware\ReCAPTCHACheck; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
Route::get('/forums', static fn () => \App\Eloquent\Model\Forum::all()->toArray()); | ||
|
||
Route::get('/forums/{fid}/threads/tid', [Controllers\ThreadsIDQuery::class, 'query']); | ||
Route::middleware(ReCAPTCHACheck::class)->group(static function () { | ||
Route::get('/posts', [PostsQuery::class, 'query']); | ||
Route::get('/users', [UsersQuery::class, 'query']); | ||
Route::get('/posts', [Controllers\PostsQuery::class, 'query']); | ||
Route::get('/users', [Controllers\UsersQuery::class, 'query']); | ||
}); |