oauth response array

This commit is contained in:
xiaomlove
2024-04-05 22:40:06 +08:00
parent 8d07ad98f7
commit ff1b88a25f
15 changed files with 418 additions and 3 deletions
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class ForumResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'postcount' => $this->postcount,
'topiccount' => $this->topiccount,
'moderators' => UserResource::collection($this->whenLoaded("moderators")),
];
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class OverForumResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
];
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class PostResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'added' => format_datetime($this->added),
'body' => $this->body,
'user' => new UserResource($this->whenLoaded('user')),
];
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class TopicResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'subject' => $this->subject,
'locked' => $this->locked,
'forumid' => $this->forumid,
'sticky' => $this->sticky,
'hlcolor' => $this->hlcolor,
'views' => $this->views,
'user' => new UserResource($this->whenLoaded('user')),
'lastPost' => new PostResource($this->whenLoaded('lastPost')),
'firstPost' => new PostResource($this->whenLoaded('firstPost')),
];
}
}
+3
View File
@@ -54,6 +54,9 @@ class UserResource extends JsonResource
$out['completed_torrents_count'] = $this->completed_torrents_count;
$out['incomplete_torrents_count'] = $this->incomplete_torrents_count;
}
if ($request->routeIs("oauth.user_info")) {
$out['name'] = $this->username;
}
if (nexus()->isPlatformAdmin() && $request->routeIs('users.show')) {
$out['two_step_secret'] = $this->two_step_secret;