Skip to content

Commit

Permalink
move id_asc and id_desc to own sort type
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Sep 11, 2024
1 parent 44dc277 commit 7f62c0b
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Knuckles\Scribe\Attributes\GenericParam;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class SortCustom extends GenericParam
class Sort extends GenericParam
{
public function __construct(
array|string $sorts,
Expand Down
23 changes: 0 additions & 23 deletions app/Docs/Attributes/SortId.php

This file was deleted.

6 changes: 2 additions & 4 deletions app/Docs/Strategies/GetFromQueryParamAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
use App\Docs\Attributes\Limit;
use App\Docs\Attributes\Offset;
use App\Docs\Attributes\Page;
use App\Docs\Attributes\SortCustom;
use App\Docs\Attributes\SortId;
use App\Docs\Attributes\Sort;
use Http\Message\Authentication\QueryParam;
use Knuckles\Scribe\Extracting\Strategies\GetParamsFromAttributeStrategy;

Expand All @@ -22,7 +21,6 @@ class GetFromQueryParamAttribute extends GetParamsFromAttributeStrategy
Offset::class,
Page::class,
QueryParam::class,
SortCustom::class,
SortId::class,
Sort::class,
];
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/BeatmapDiscussionPostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use App\Docs\Attributes\Limit;
use App\Docs\Attributes\Page;
use App\Docs\Attributes\SortId;
use App\Docs\Attributes\Sort;
use App\Exceptions\ModelNotSavedException;
use App\Libraries\BeatmapsetDiscussion\Discussion;
use App\Libraries\BeatmapsetDiscussion\Reply;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function destroy($id)
* @queryParam user integer The `id` of the [User](#user).
* @queryParam with_deleted boolean This param has no effect as api calls do not currently receive group permissions.
*/
#[Limit, Page, SortId]
#[Limit, Page, Sort('IdSort')]
public function index()
{
$bundle = new BeatmapsetDiscussionPostsBundle(request()->all());
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/BeatmapDiscussionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use App\Docs\Attributes\Limit;
use App\Docs\Attributes\Page;
use App\Docs\Attributes\SortId;
use App\Docs\Attributes\Sort;
use App\Exceptions\ModelNotSavedException;
use App\Libraries\BeatmapsetDiscussion\Review;
use App\Libraries\BeatmapsetDiscussionsBundle;
Expand Down Expand Up @@ -102,7 +102,7 @@ public function destroy($id)
* @queryParam user integer The `id` of the [User](#user).
* @queryParam with_deleted boolean This param has no effect as api calls do not currently receive group permissions. No-example
*/
#[Limit, Page, SortId]
#[Limit, Page, Sort('IdSort')]
public function index()
{
$bundle = new BeatmapsetDiscussionsBundle(request()->all());
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/BeatmapsetDiscussionVotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use App\Docs\Attributes\Limit;
use App\Docs\Attributes\Page;
use App\Docs\Attributes\SortId;
use App\Docs\Attributes\Sort;
use App\Libraries\BeatmapsetDiscussionVotesBundle;

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ public function __construct()
* @queryParam user integer The `id` of the [User](#user) giving the votes.
* @queryParam with_deleted boolean This param has no effect as api calls do not currently receive group permissions. No-example
*/
#[Limit, Page, SortId]
#[Limit, Page, Sort('IdSort')]
public function index()
{
$bundle = new BeatmapsetDiscussionVotesBundle(request()->all());
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace App\Http\Controllers;

use App\Docs\Attributes\SortCustom;
use App\Docs\Attributes\Sort;
use App\Exceptions\ModelNotSavedException;
use App\Jobs\Notifications\CommentNew;
use App\Libraries\CommentBundle;
Expand Down Expand Up @@ -77,7 +77,7 @@ public function destroy($id)
* @queryParam cursor Pagination option. See [CommentSort](#commentsort) for detail. The format follows [Cursor](#cursor) except it's not currently included in the response. No-example
* @queryParam parent_id integer Limit to comments which are reply to the specified id. Specify 0 to get top level comments. Example: 1
*/
#[SortCustom('CommentSort', 'Defaults to `new` for guests and user-specified default when authenticated.', 'new')]
#[Sort('CommentSort', 'Defaults to `new` for guests and user-specified default when authenticated.', 'new')]
public function index()
{
$params = request()->all();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace App\Http\Controllers;

use App\Docs\Attributes\SortId;
use App\Docs\Attributes\Sort;
use App\Models\Event;

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ public function __construct()
* cursor_string: "eyJldmVudF9pZCI6OH0"
* }
*/
#[SortId]
#[Sort('IdSort')]
public function index()
{
$params = request()->all();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Forum/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace App\Http\Controllers\Forum;

use App\Docs\Attributes\Limit;
use App\Docs\Attributes\SortId;
use App\Docs\Attributes\Sort;
use App\Exceptions\ModelNotSavedException;
use App\Jobs\Notifications\ForumTopicReply;
use App\Libraries\NewForumTopic;
Expand Down Expand Up @@ -314,7 +314,7 @@ public function reply($id)
* "sort": "id_asc"
* }
*/
#[Limit(20, 1, 50, 'Maximum number of posts to be returned'), SortId]
#[Limit(20, 1, 50, 'Maximum number of posts to be returned'), Sort('IdSort')]
public function show($id)
{
$topic = Topic::with(['forum'])->withTrashed()->findOrFail($id);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/MatchesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace App\Http\Controllers;

use App\Docs\Attributes\Limit;
use App\Docs\Attributes\SortId;
use App\Docs\Attributes\Sort;
use App\Models\LegacyMatch\LegacyMatch;
use App\Models\User;
use App\Transformers\LegacyMatch\EventTransformer;
Expand Down Expand Up @@ -60,7 +60,7 @@ public function __construct()
* "cursor_string": "eyJtYXRjaF9pZCI6MTE0NDI4Njg1fQ"
* }
*/
#[Limit(50, 1, 50), SortId]
#[Limit(50, 1, 50), Sort('IdSort')]
public function index()
{
$params = request()->all();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace App\Http\Controllers\Multiplayer\Rooms\Playlist;

use App\Docs\Attributes\Limit;
use App\Docs\Attributes\SortCustom;
use App\Docs\Attributes\Sort;
use App\Exceptions\InvariantException;
use App\Http\Controllers\Controller as BaseController;
use App\Libraries\ClientCheck;
Expand Down Expand Up @@ -47,7 +47,7 @@ public function __construct()
* @usesCursor
*/
#[Limit(50, 1, 50)]
#[SortCustom('MultiplayerScoresSort')]
#[Sort('MultiplayerScoresSort')]
public function index($roomId, $playlistId)
{
$playlist = PlaylistItem::where('room_id', $roomId)->findOrFail($playlistId);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Multiplayer/RoomsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace App\Http\Controllers\Multiplayer;

use App\Docs\Attributes\Limit;
use App\Docs\Attributes\SortCustom;
use App\Docs\Attributes\Sort;
use App\Exceptions\InvariantException;
use App\Http\Controllers\Controller as BaseController;
use App\Models\Model;
Expand All @@ -32,7 +32,7 @@ public function __construct()
* @queryParam season_id Season ID to return Rooms from. No-example
* @queryParam type_group `playlists` (default) or `realtime`. No-example
*/
#[Limit(250, 1, 250), SortCustom(['ended', 'created'])]
#[Limit(250, 1, 250), Sort(['ended', 'created'])]
public function index()
{
$apiVersion = api_version();
Expand Down
9 changes: 9 additions & 0 deletions resources/views/docs/_structures/id_sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## IdSort

Available sort types are `id_asc`, `id_desc`.

Name | Description
------- | ----------------------------
id_asc | Sort by oldest first.
id_desc | Sort by newest first.

0 comments on commit 7f62c0b

Please sign in to comment.