From 3bdf1a440375d6923815cee117894c8465e69853 Mon Sep 17 00:00:00 2001 From: clayton Date: Mon, 21 Jun 2021 01:30:37 -0700 Subject: [PATCH 1/3] Return UserRelation instead of UserCompact for friends API --- app/Http/Controllers/FriendsController.php | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/FriendsController.php b/app/Http/Controllers/FriendsController.php index f2bc0f67622..1854e25f1f0 100644 --- a/app/Http/Controllers/FriendsController.php +++ b/app/Http/Controllers/FriendsController.php @@ -32,6 +32,25 @@ public function __construct() public function index() { + if (is_api_request()) { + return json_collection( + auth()->user() + ->relations() + ->friends() + ->withMutual() + ->with(['target' => fn ($query) => $query->eagerloadForListing()]) + ->get(), + 'UserRelation', + [ + 'target', + 'target.cover', + 'target.country', + 'target.groups', + 'target.support_level', + ], + ); + } + $currentUser = auth()->user(); $currentMode = default_mode(); @@ -52,10 +71,6 @@ public function index() 'support_level', ]); - if (is_api_request()) { - return $usersJson; - } - return ext_view('friends.index', compact('usersJson')); } From 08adf9bf2a7881bafa030f4ef3461adc20ec7dad Mon Sep 17 00:00:00 2001 From: clayton Date: Mon, 21 Jun 2021 01:32:52 -0700 Subject: [PATCH 2/3] Add docs for friends API --- app/Http/Controllers/FriendsController.php | 72 +++++++++++++++++++ .../views/docs/_structures/user_relation.md | 22 ++++++ resources/views/docs/info.blade.php | 3 + 3 files changed, 97 insertions(+) create mode 100644 resources/views/docs/_structures/user_relation.md diff --git a/app/Http/Controllers/FriendsController.php b/app/Http/Controllers/FriendsController.php index 1854e25f1f0..9d78ea3d13a 100644 --- a/app/Http/Controllers/FriendsController.php +++ b/app/Http/Controllers/FriendsController.php @@ -12,6 +12,9 @@ use Auth; use Request; +/** + * @group Friends + */ class FriendsController extends Controller { public function __construct() @@ -30,6 +33,75 @@ public function __construct() return parent::__construct(); } + /** + * Get Friends + * + * Returns the authenticated user's friends list. + * + * --- + * + * ### Response Format + * + * A collection of [UserRelation](#userrelation) objects with `target` included. `target`s include `cover`, `country`, `groups`, and `support_level`. + * + * @response [ + * { + * "target_id": 2, + * "relation_type": "friend", + * "mutual": false, + * "target": { + * "avatar_url": "https://a.ppy.sh/2?1537409912.jpeg", + * "country_code": "AU", + * "default_group": "default", + * "id": 2, + * "is_active": true, + * "is_bot": false, + * "is_deleted": false, + * "is_online": false, + * "is_supporter": true, + * "last_visit": "2021-06-21T06:55:47+00:00", + * "pm_friends_only": false, + * "profile_colour": "#3366FF", + * "username": "peppy", + * "country": { + * "code": "AU", + * "name": "Australia" + * }, + * "cover": { + * "custom_url": "https://assets.ppy.sh/user-profile-covers/2/baba245ef60834b769694178f8f6d4f6166c5188c740de084656ad2b80f1eea7.jpeg", + * "url": "https://assets.ppy.sh/user-profile-covers/2/baba245ef60834b769694178f8f6d4f6166c5188c740de084656ad2b80f1eea7.jpeg", + * "id": null + * }, + * "groups": [ + * { + * "colour": "#0066FF", + * "has_listing": false, + * "has_playmodes": false, + * "id": 33, + * "identifier": "ppy", + * "is_probationary": false, + * "name": "ppy", + * "short_name": "PPY", + * "playmodes": null + * }, + * { + * "colour": "#EB47D0", + * "has_listing": true, + * "has_playmodes": false, + * "id": 11, + * "identifier": "dev", + * "is_probationary": false, + * "name": "Developers", + * "short_name": "DEV", + * "playmodes": null + * } + * ], + * "support_level": 3 + * } + * }, + * // ... + * ] + */ public function index() { if (is_api_request()) { diff --git a/resources/views/docs/_structures/user_relation.md b/resources/views/docs/_structures/user_relation.md new file mode 100644 index 00000000000..682e5be29b2 --- /dev/null +++ b/resources/views/docs/_structures/user_relation.md @@ -0,0 +1,22 @@ +## UserRelation +```json +{ + "target_id": 3, + "relation_type": "friend", + "mutual": true +} +``` + +Field | Type | Notes +--------------|---------------------|------------ +mutual | boolean | Always `false` for blocks. +relation_type | `block` \| `friend` | | +target_id | number | | + +### Optional Attributes + +The following are attributes which may be additionally included in responses. Relevant endpoints should list them if applicable. + +Field | Type +-------|----- +target | [UserCompact](#usercompact) diff --git a/resources/views/docs/info.blade.php b/resources/views/docs/info.blade.php index fcdd46fc48a..3860dd8c33d 100644 --- a/resources/views/docs/info.blade.php +++ b/resources/views/docs/info.blade.php @@ -304,6 +304,9 @@ ## Breaking Changes +### 2021-06-21 +- [`/friends`](#get-friends) returns a collection of [UserRelation](#userrelation) instead of [UserCompact](#usercompact). + ### 2021-06-09 - `ranked_and_approved_beatmapset_count` and `unranked_beatmapset_count` attributes in [UserCompact](#usercompact) object have been deprecated and replaced with `ranked_beatmapset_count` and `pending_beatmapset_count` respectively. - `ranked_and_approved` and `unranked` types in [Get User Beatmaps](#get-user-beatmaps) have been deprecated and replaced with `ranked` and `pending` respectively. From 1e6daa260af1dca8cb410bd6afd0376e860eac65 Mon Sep 17 00:00:00 2001 From: clayton Date: Mon, 21 Jun 2021 01:35:08 -0700 Subject: [PATCH 3/3] Sort --- app/Http/Controllers/FriendsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/FriendsController.php b/app/Http/Controllers/FriendsController.php index 9d78ea3d13a..896cc2648fe 100644 --- a/app/Http/Controllers/FriendsController.php +++ b/app/Http/Controllers/FriendsController.php @@ -42,7 +42,7 @@ public function __construct() * * ### Response Format * - * A collection of [UserRelation](#userrelation) objects with `target` included. `target`s include `cover`, `country`, `groups`, and `support_level`. + * A collection of [UserRelation](#userrelation) objects with `target` included. `target`s include `country`, `cover`, `groups`, and `support_level`. * * @response [ * { @@ -115,8 +115,8 @@ public function index() 'UserRelation', [ 'target', - 'target.cover', 'target.country', + 'target.cover', 'target.groups', 'target.support_level', ],