Skip to content

Commit a19386a

Browse files
authored
Merge pull request #4343 from HDInnovations/Request-3747
(Add) Request #3747
2 parents 8b481d2 + a279ef6 commit a19386a

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author HDVinnie <hdinnovations@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
namespace App\Http\Controllers\API;
18+
19+
use App\Http\Resources\UserResource;
20+
21+
class UserController extends BaseController
22+
{
23+
final public function show(): UserResource
24+
{
25+
$user = auth()->user();
26+
27+
UserResource::withoutWrapping();
28+
29+
return new UserResource($user);
30+
}
31+
}

app/Http/Resources/UserResource.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,28 @@
1717
namespace App\Http\Resources;
1818

1919
use Illuminate\Http\Resources\Json\JsonResource;
20-
use JsonSerializable;
2120

21+
/**
22+
* @mixin \App\Models\User
23+
*/
2224
class UserResource extends JsonResource
2325
{
2426
/**
2527
* Transform the resource into an array.
2628
*/
27-
public function toArray($request): array|\Illuminate\Contracts\Support\Arrayable|JsonSerializable
29+
public function toArray($request): array
2830
{
29-
return parent::toArray($request);
31+
return [
32+
'username' => $this->username,
33+
'group' => $this->group->name,
34+
'uploaded' => str_replace("\u{00A0}", ' ', $this->formatted_uploaded),
35+
'downloaded' => str_replace("\u{00A0}", ' ', $this->formatted_downloaded),
36+
'ratio' => $this->formatted_ratio,
37+
'buffer' => str_replace("\u{00A0}", ' ', $this->formatted_buffer),
38+
'seeding' => \count($this->seedingTorrents) ? $this->seedingTorrents : 0,
39+
'leeching' => \count($this->leechingTorrents) ? $this->leechingTorrents : 0,
40+
'seedbonus' => $this->seedbonus,
41+
'hit_and_runs' => $this->hitandruns,
42+
];
3043
}
3144
}

phpstan-baseline.neon

-5
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,6 @@ parameters:
535535
count: 1
536536
path: app/Http/Resources/UserResource.php
537537

538-
-
539-
message: "#^Method App\\\\Http\\\\Resources\\\\UserResource\\:\\:toArray\\(\\) return type with generic interface Illuminate\\\\Contracts\\\\Support\\\\Arrayable does not specify its types\\: TKey, TValue$#"
540-
count: 1
541-
path: app/Http/Resources/UserResource.php
542-
543538
-
544539
message: "#^Strict comparison using \\=\\=\\= between float\\|null and 0 will always evaluate to false\\.$#"
545540
count: 1

routes/api.php

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
Route::post('/upload', [App\Http\Controllers\API\TorrentController::class, 'store']);
4343
});
4444

45+
// User
46+
Route::middleware(['auth:api', 'banned'])->get('/user', [App\Http\Controllers\API\UserController::class, 'show']);
47+
4548
// Internal front-end web API routes
4649
Route::middleware(['web', 'auth', 'banned', 'verified'])->group(function (): void {
4750
Route::prefix('bookmarks')->group(function (): void {

0 commit comments

Comments
 (0)