mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Add places api endpoints
This commit is contained in:
parent
94395be9c4
commit
9ab9ffbafe
3 changed files with 40 additions and 0 deletions
|
@ -11,6 +11,7 @@ use League\Fractal\Serializer\ArraySerializer;
|
||||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
use App\AccountLog;
|
use App\AccountLog;
|
||||||
use App\EmailVerification;
|
use App\EmailVerification;
|
||||||
|
use App\Place;
|
||||||
use App\Status;
|
use App\Status;
|
||||||
use App\Report;
|
use App\Report;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
|
@ -633,4 +634,35 @@ class ApiV1Dot1Controller extends Controller
|
||||||
|
|
||||||
return StatusStateless::collection($statuses);
|
return StatusStateless::collection($statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function placesById(Request $request, $id, $slug)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$place = Place::whereSlug($slug)->findOrFail($id);
|
||||||
|
|
||||||
|
$posts = Cache::remember('pf-api:v1.1:places-by-id:' . $place->id, 3600, function() use($place) {
|
||||||
|
return Status::wherePlaceId($place->id)
|
||||||
|
->whereNull('uri')
|
||||||
|
->whereScope('public')
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->limit(60)
|
||||||
|
->pluck('id');
|
||||||
|
});
|
||||||
|
|
||||||
|
$posts = $posts->map(function($id) {
|
||||||
|
return StatusService::get($id);
|
||||||
|
})
|
||||||
|
->filter()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
return ['place' => [
|
||||||
|
'id' => $place->id,
|
||||||
|
'name' => $place->name,
|
||||||
|
'slug' => $place->slug,
|
||||||
|
'country' => $place->country,
|
||||||
|
'lat' => $place->lat,
|
||||||
|
'long' => $place->long
|
||||||
|
], 'posts' => $posts];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,10 @@ class PlaceController extends Controller
|
||||||
|
|
||||||
public function show(Request $request, $id, $slug)
|
public function show(Request $request, $id, $slug)
|
||||||
{
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'page' => 'sometimes|max:10'
|
||||||
|
]);
|
||||||
|
|
||||||
$place = Place::whereSlug($slug)->findOrFail($id);
|
$place = Place::whereSlug($slug)->findOrFail($id);
|
||||||
$posts = Status::wherePlaceId($place->id)
|
$posts = Status::wherePlaceId($place->id)
|
||||||
->whereNull('uri')
|
->whereNull('uri')
|
||||||
|
|
|
@ -137,6 +137,10 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
||||||
Route::get('list', 'Api\ApiV1Dot1Controller@archivedPosts')->middleware($middleware);
|
Route::get('list', 'Api\ApiV1Dot1Controller@archivedPosts')->middleware($middleware);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::group(['prefix' => 'places'], function () use($middleware) {
|
||||||
|
Route::get('posts/{id}/{slug}', 'Api\ApiV1Dot1Controller@placesById')->middleware($middleware);
|
||||||
|
});
|
||||||
|
|
||||||
Route::group(['prefix' => 'stories'], function () use($middleware) {
|
Route::group(['prefix' => 'stories'], function () use($middleware) {
|
||||||
Route::get('recent', 'StoryController@recent')->middleware($middleware);
|
Route::get('recent', 'StoryController@recent')->middleware($middleware);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue