Skip to content

Commit

Permalink
Update CollectionController, fix broken unauthenticated access. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Feb 16, 2022
1 parent 46ebe46 commit bd249f0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/Http/Controllers/CollectionController.php
Expand Up @@ -17,6 +17,7 @@
};
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Services\StatusService;

class CollectionController extends Controller
{
Expand Down Expand Up @@ -166,12 +167,16 @@ public function getItems(Request $request, int $id)
if($collection->visibility !== 'public') {
abort_if(!Auth::check() || Auth::user()->profile_id != $collection->profile_id, 404);
}
$posts = $collection->posts()->orderBy('order', 'asc')->get();

$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Collection($posts, new StatusTransformer());
$res = $fractal->createData($resource)->toArray();
$res = CollectionItem::whereCollectionId($id)
->pluck('object_id')
->map(function($id) {
return StatusService::get($id);
})
->filter(function($post) {
return $post && isset($post['account']);
})
->values();

return response()->json($res);
}
Expand All @@ -197,11 +202,12 @@ public function getUserCollections(Request $request, int $id)
->paginate(9)
->map(function($collection) {
return [
'id' => $collection->id,
'id' => (string) $collection->id,
'title' => $collection->title,
'description' => $collection->description,
'thumb' => $collection->posts()->first()->thumb(),
'url' => $collection->url(),
'post_count' => $collection->posts()->count(),
'published_at' => $collection->published_at
];
});
Expand Down

1 comment on commit bd249f0

@pylapp
Copy link

@pylapp pylapp commented on bd249f0 Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Please sign in to comment.