1313use App \Http \Requests \Album \GetAlbumPhotosRequest ;
1414use App \Http \Resources \Collections \PaginatedPhotosResource ;
1515use App \Models \Album ;
16+ use App \Models \Extensions \SortingDecorator ;
17+ use App \Models \Photo ;
1618use App \Models \TagAlbum ;
1719use App \Policies \AlbumPolicy ;
1820use App \Repositories \ConfigManager ;
@@ -41,6 +43,7 @@ public function __construct(private PhotoRepository $photo_repository)
4143 */
4244 public function get (GetAlbumPhotosRequest $ request ): PaginatedPhotosResource
4345 {
46+ /** @var Album|TagAlbum|BaseSmartAlbum $album */
4447 $ album = $ request ->album ();
4548
4649 $ per_page = $ request ->configs ()->getValueAsInt ('photos_per_page ' );
@@ -55,13 +58,26 @@ public function get(GetAlbumPhotosRequest $request): PaginatedPhotosResource
5558 photo_timeline: $ config_manager ->getValueAsEnum ('timeline_photos_granularity ' , TimelinePhotoGranularity::class),
5659 );
5760 }
61+
62+ $ sorting = $ album ->getEffectivePhotoSorting ();
63+
5864 // grants_full_photo_access
5965 if ($ album instanceof TagAlbum) {
6066 $ config_manager = resolve (ConfigManager::class);
6167
68+ // @phpstan-ignore method.private
69+ $ query = $ album ->photos ()->with (['size_variants ' , 'tags ' , 'palette ' , 'statistics ' , 'rating ' ]);
70+
71+ // Apply sorting via SortingDecorator
72+ /** @var SortingDecorator<Photo> */
73+ $ sorting_decorator = new SortingDecorator ($ query );
74+
75+ $ paginated_photos = $ sorting_decorator
76+ ->orderPhotosBy ($ sorting ->column , $ sorting ->order )
77+ ->paginate ($ per_page );
78+
6279 return new PaginatedPhotosResource (
63- /** @phpstan-ignore method.private (It is NOT private and it works.) */
64- paginated_photos: $ album ->photos ()->with (['size_variants ' , 'tags ' , 'palette ' , 'statistics ' , 'rating ' ])->paginate ($ config_manager ->getValueAsInt ('photos_per_page ' )),
80+ paginated_photos: $ paginated_photos ,
6581 album_id: $ album ->id ,
6682 should_downgrade: Gate::check (AlbumPolicy::CAN_ACCESS_FULL_PHOTO , [AbstractAlbum::class, $ album ]) === false ,
6783 photo_timeline: $ album ->photo_timeline ,
@@ -74,7 +90,7 @@ public function get(GetAlbumPhotosRequest $request): PaginatedPhotosResource
7490
7591 $ paginator = $ this ->photo_repository ->getPhotosForAlbumPaginated (
7692 $ album ->id ,
77- $ album -> getEffectivePhotoSorting () ,
93+ $ sorting ,
7894 $ per_page ,
7995 count ($ tag_ids ) > 0 ? $ tag_ids : null ,
8096 $ tag_logic
0 commit comments