Update Api Controllers

This commit is contained in:
Daniel Supernault 2019-02-10 21:49:54 -07:00
parent 125d694086
commit 1b8783a99f
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 81 additions and 11 deletions

View file

@ -141,10 +141,9 @@ class BaseApiController extends Controller
$statuses = $statuses->whereVisibility('public')->orderBy('id', 'desc')->paginate($limit); $statuses = $statuses->whereVisibility('public')->orderBy('id', 'desc')->paginate($limit);
} }
$resource = new Fractal\Resource\Collection($statuses, new StatusTransformer()); $resource = new Fractal\Resource\Collection($statuses, new StatusTransformer());
//$resource->setPaginator(new IlluminatePaginatorAdapter($statuses));
$res = $this->fractal->createData($resource)->toArray(); $res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT); return response()->json($res);
} }
public function followSuggestions(Request $request) public function followSuggestions(Request $request)
@ -302,12 +301,4 @@ class BaseApiController extends Controller
return response()->json($res); return response()->json($res);
} }
public function showAccount(Request $request, $id)
{
$profile = Profile::whereNull('domain')->whereNull('status')->findOrFail($id);
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
} }

View file

@ -340,7 +340,8 @@ class PublicApiController extends Controller
abort_if(!Auth::check(), 403); abort_if(!Auth::check(), 403);
$this->validate($request, [ $this->validate($request, [
'id' => 'required|array|min:1|max:20' 'id' => 'required|array|min:1|max:20',
'id.*' => 'required|integer'
]); ]);
$ids = collect($request->input('id')); $ids = collect($request->input('id'));
$filtered = $ids->filter(function($v) { $filtered = $ids->filter(function($v) {
@ -351,4 +352,82 @@ class PublicApiController extends Controller
$res = $this->fractal->createData($fractal)->toArray(); $res = $this->fractal->createData($fractal)->toArray();
return response()->json($res); return response()->json($res);
} }
public function account(Request $request, $id)
{
$profile = Profile::whereNull('status')->findOrFail($id);
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
public function accountFollowers(Request $request, $id)
{
$profile = Profile::findOrFail($id);
$followers = $profile->followers;
$resource = new Fractal\Resource\Collection($followers, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
public function accountFollowing(Request $request, $id)
{
$profile = Profile::findOrFail($id);
$following = $profile->following;
$resource = new Fractal\Resource\Collection($following, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
public function accountStatuses(Request $request, $id)
{
$this->validate($request, [
'only_media' => 'nullable',
'pinned' => 'nullable',
'exclude_replies' => 'nullable',
'max_id' => 'nullable|integer|min:1',
'since_id' => 'nullable|integer|min:1',
'min_id' => 'nullable|integer|min:1',
'limit' => 'nullable|integer|min:1|max:24'
]);
$limit = $request->limit ?? 20;
$max_id = $request->max_id ?? false;
$min_id = $request->min_id ?? false;
$since_id = $request->since_id ?? false;
$only_media = $request->only_media ?? false;
$user = Auth::user();
$account = Profile::findOrFail($id);
$statuses = $account->statuses()->getQuery();
if($only_media == true) {
$statuses = $statuses
->whereHas('media')
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id');
}
if($id == $account->id && !$max_id && !$min_id && !$since_id) {
$statuses = $statuses->orderBy('id', 'desc')
->paginate($limit);
} else if($since_id) {
$statuses = $statuses->where('id', '>', $since_id)
->orderBy('id', 'DESC')
->paginate($limit);
} else if($min_id) {
$statuses = $statuses->where('id', '>', $min_id)
->orderBy('id', 'ASC')
->paginate($limit);
} else if($max_id) {
$statuses = $statuses->where('id', '<', $max_id)
->orderBy('id', 'DESC')
->paginate($limit);
} else {
$statuses = $statuses->whereVisibility('public')->orderBy('id', 'desc')->paginate($limit);
}
$resource = new Fractal\Resource\Collection($statuses, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
}
} }