Skip to content

Commit

Permalink
oauth response array
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Apr 5, 2024
1 parent 8d07ad9 commit ff1b88a
Show file tree
Hide file tree
Showing 15 changed files with 418 additions and 3 deletions.
93 changes: 93 additions & 0 deletions app/Http/Controllers/ForumController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\ForumResource;
use App\Models\Forum;
use Illuminate\Http\Request;

class ForumController extends Controller
{
/**
* Display a listing of the resource.
*
* @return array
*/
public function index(Request $request)
{
$forId = $request->forid;
$query = Forum::query()->orderBy("sort", "asc")->with("moderators");
if ($forId) {
$query->where("forid", $forId);
}
$list = $query->get();
$resource = ForumResource::collection($list);
return $this->success($resource);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function show(OverForum $overForum)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function edit(OverForum $overForum)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function update(Request $request, OverForum $overForum)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function destroy(OverForum $overForum)
{
//
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/OauthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public function userInfo(): array
{
$user = Auth::user();
$resource = new UserResource($user);
return $this->success($resource);
return $resource->response()->getData(true);
}
}
88 changes: 88 additions & 0 deletions app/Http/Controllers/OverForumController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\OverForumResource;
use App\Models\OverForum;
use Illuminate\Http\Request;

class OverForumController extends Controller
{
/**
* Display a listing of the resource.
*
* @return array
*/
public function index()
{
$list = OverForum::query()->orderBy("sort", "asc")->get();
$resource = OverForumResource::collection($list);
return $this->success($resource);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function show(OverForum $overForum)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function edit(OverForum $overForum)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function update(Request $request, OverForum $overForum)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function destroy(OverForum $overForum)
{
//
}
}
98 changes: 98 additions & 0 deletions app/Http/Controllers/TopicController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\ForumResource;
use App\Http\Resources\TopicResource;
use App\Models\Forum;
use App\Models\Topic;
use Illuminate\Http\Request;

class TopicController extends Controller
{
/**
* Display a listing of the resource.
*
* @return array
*/
public function index(Request $request)
{
$forumId = $request->forum_id;
$query = Topic::query()
->orderBy("sticky", "desc")
->with("user", "firstPost", "lastPost")
;
if ($forumId) {
$query->where("forumid", $forumId);
}
$list = $query->get();
$resource = TopicResource::collection($list);
return $this->success($resource);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function show(OverForum $overForum)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function edit(OverForum $overForum)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function update(Request $request, OverForum $overForum)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\OverForum $overForum
* @return \Illuminate\Http\Response
*/
public function destroy(OverForum $overForum)
{
//
}
}
26 changes: 26 additions & 0 deletions app/Http/Resources/ForumResource.php
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions app/Http/Resources/OverForumResource.php
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions app/Http/Resources/PostResource.php
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions app/Http/Resources/TopicResource.php
Original file line number Diff line number Diff line change
@@ -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')),
];
}
}
Loading

0 comments on commit ff1b88a

Please sign in to comment.