Skip to content

Commit

Permalink
Merge branch 'master' into feature/webpack-asset-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya authored Sep 14, 2023
2 parents 6dfe945 + 935e2f2 commit bbc2772
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 7 deletions.
27 changes: 26 additions & 1 deletion app/Http/Controllers/RankingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\User;
use App\Models\UserStatistics;
use App\Transformers\SelectOptionTransformer;
use App\Transformers\UserCompactTransformer;
use DB;
use Illuminate\Pagination\LengthAwarePaginator;

Expand Down Expand Up @@ -221,6 +222,21 @@ public function index($mode, $type)
return ext_view("rankings.{$type}", array_merge($this->defaultViewVars, compact('scores')));
}

/**
* Get Kudosu Ranking
*
* Gets the kudosu ranking.
*
* ---
*
* ### Response format
*
* Field | Type | Description
* ------- | --------------- | -----------
* ranking | [User](#user)[] | Includes `kudosu`.
*
* @queryParam page Ranking page. Example: 1
*/
public function kudosu()
{
static $maxResults = 1000;
Expand All @@ -229,10 +245,19 @@ public function kudosu()
$page = min(get_int(request('page')) ?? 1, $maxPage);

$scores = User::default()
->with('country')
->orderBy('osu_kudostotal', 'desc')
->paginate(static::PAGE_SIZE, ['*'], 'page', $page, $maxResults);

if (is_json_request()) {
return ['ranking' => json_collection(
$scores,
new UserCompactTransformer(),
'kudosu',
)];
}

$scores->loadMissing('country');

return ext_view('rankings.kudosu', compact('scores'));
}

Expand Down
9 changes: 9 additions & 0 deletions app/Transformers/UserCompactTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class UserCompactTransformer extends TransformerAbstract
'is_nat',
'is_restricted',
'is_silenced',
'kudosu',
'loved_beatmapset_count',
'mapping_follower_count',
'monthly_playcounts',
Expand Down Expand Up @@ -285,6 +286,14 @@ public function includeIsSilenced(User $user)
return $this->primitive($user->isSilenced());
}

public function includeKudosu(User $user): ResourceInterface
{
return $this->primitive([
'available' => $user->osu_kudosavailable,
'total' => $user->osu_kudostotal,
]);
}

public function includeLovedBeatmapsetCount(User $user)
{
return $this->primitive($user->profileBeatmapsetCountByGroupedStatus('loved'));
Expand Down
5 changes: 1 addition & 4 deletions app/Transformers/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class UserTransformer extends UserCompactTransformer
'is_nat',
'is_restricted',
'is_silenced',
'kudosu',
];

public function transform(User $user)
Expand All @@ -35,10 +36,6 @@ public function transform(User $user)
'has_supported' => $user->hasSupported(),
'interests' => $user->user_interests,
'join_date' => json_time($user->user_regdate),
'kudosu' => [
'total' => $user->osu_kudostotal,
'available' => $user->osu_kudosavailable,
],
'location' => $user->user_from,
'max_blocks' => $user->maxBlocks(),
'max_friends' => $user->maxFriends(),
Expand Down
10 changes: 10 additions & 0 deletions resources/views/docs/_structures/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ graveyard_beatmapset_count | number
groups | [UserGroup](#usergroup)[]
guest_beatmapset_count | number
is_restricted | boolean?
kudosu | [User.Kudosu](#user-kudosu)
loved_beatmapset_count | number
mapping_follower_count | number
monthly_playcounts | [UserMonthlyPlaycount](#usermonthlyplaycount)[]
Expand All @@ -75,6 +76,15 @@ unread_pm_count | |
user_achievements | |
user_preferences | |

<div id="user-kudosu" data-unique="user-kudosu"></div>

### Kudosu

Field | Type
----------|-----
available | number
total | number

<div id="user-profilebanner" data-unique="user-profilebanner"></div>

### ProfileBanner
Expand Down
3 changes: 1 addition & 2 deletions resources/views/docs/_structures/user_extended.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ discord | string? | |
has_supported | boolean | whether or not ever being a supporter in the past
interests | string? | |
join_date | Timestamp | |
kudosu.available | number | |
kudosu.total | number | |
location | string? | |
max_blocks | number | maximum number of users allowed to be blocked
max_friends | number | maximum number of friends allowed to be added
Expand All @@ -191,3 +189,4 @@ In addition, the following [optional attributes on User](#user-optionalattribute
- country
- cover
- is_restricted (present only if this is the currently authenticated user)
- kudosu
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@
// POST /api/v2/notifications/mark-read
Route::post('notifications/mark-read', 'NotificationsController@markRead')->name('notifications.mark-read');

Route::get('rankings/kudosu', 'RankingController@kudosu');
// GET /api/v2/rankings/:mode/:type
Route::get('rankings/{mode}/{type}', 'RankingController@index');
Route::resource('spotlights', 'SpotlightsController', ['only' => ['index']]);
Expand Down
16 changes: 16 additions & 0 deletions tests/api_routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,22 @@
],
"scopes": []
},
{
"uri": "api/v2/rankings/kudosu",
"methods": [
"GET",
"HEAD"
],
"controller": "App\\Http\\Controllers\\RankingController@kudosu",
"middlewares": [
"App\\Http\\Middleware\\ThrottleRequests:1200,1,api:",
"App\\Http\\Middleware\\RequireScopes",
"App\\Http\\Middleware\\RequireScopes:public"
],
"scopes": [
"public"
]
},
{
"uri": "api/v2/rankings/{mode}/{type}",
"methods": [
Expand Down

0 comments on commit bbc2772

Please sign in to comment.