mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-25 12:37:23 +08:00
[API] comments list
This commit is contained in:
@@ -25,17 +25,8 @@ class CommentController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$torrentId = $request->torrent_id;
|
||||
$with = ['create_user', 'update_user'];
|
||||
$comments = Comment::query()
|
||||
->with($with)
|
||||
->where('torrent', $torrentId)
|
||||
->paginate();
|
||||
$comments = $this->repository->getList($request, Auth::user());
|
||||
$resource = CommentResource::collection($comments);
|
||||
// $resource->additional([
|
||||
// 'page_title' => nexus_trans('comment.index.page_title'),
|
||||
// ]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,13 @@ class CommentResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$descriptionArr = format_description($this->text);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'description' => $descriptionArr,
|
||||
'images' => get_image_from_description($descriptionArr),
|
||||
'updated_at_human' => format_datetime($this->editdate),
|
||||
'created_at_human' => $this->added->format('Y-m-d H:i'),
|
||||
'text' => $this->text,
|
||||
'updated_at' => format_datetime($this->editdate),
|
||||
'created_at' => format_datetime($this->added),
|
||||
'create_user' => new UserResource($this->whenLoaded('create_user')),
|
||||
'update_user' => new UserResource($this->whenLoaded('update_user')),
|
||||
'update_user' => $this->when($this->editedby > 0, new UserResource($this->whenLoaded('update_user'))),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,26 +9,27 @@ use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Hamcrest\Core\Set;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class CommentRepository extends BaseRepository
|
||||
{
|
||||
public function getList(array $params)
|
||||
public function getList(Request $request, Authenticatable $user)
|
||||
{
|
||||
$query = Comment::query()->with(['create_user', 'update_user']);
|
||||
if (!empty($params['torrent_id'])) {
|
||||
$query->where('torrent', $params['torrent_id']);
|
||||
if (!empty($request->torrent_id)) {
|
||||
$query->where('torrent', $request->torrent_id);
|
||||
}
|
||||
if (!empty($params['offer_id'])) {
|
||||
$query->where('offer', $params['offer_id']);
|
||||
if (!empty($request->offer_id)) {
|
||||
$query->where('offer', $request->offer_id);
|
||||
}
|
||||
if (!empty($params['request_id'])) {
|
||||
$query->where('request', $params['request_id']);
|
||||
if (!empty($request->request_id)) {
|
||||
$query->where('request', $request->request_id);
|
||||
}
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
return $query->paginate();
|
||||
$query->orderBy('id', 'desc');
|
||||
return $query->paginate($this->getPerPageFromRequest($request));
|
||||
}
|
||||
|
||||
public function store(array $params, User $user)
|
||||
|
||||
Reference in New Issue
Block a user