33namespace BookStack \Entities \Controllers ;
44
55use BookStack \Entities \Models \Bookshelf ;
6+ use BookStack \Entities \Queries \BookshelfQueries ;
67use BookStack \Entities \Repos \BookshelfRepo ;
78use BookStack \Http \ApiController ;
89use Exception ;
1314class BookshelfApiController extends ApiController
1415{
1516 public function __construct (
16- protected BookshelfRepo $ bookshelfRepo
17+ protected BookshelfRepo $ bookshelfRepo ,
18+ protected BookshelfQueries $ queries ,
1719 ) {
1820 }
1921
@@ -22,7 +24,7 @@ public function __construct(
2224 */
2325 public function list ()
2426 {
25- $ shelves = Bookshelf:: visible ();
27+ $ shelves = $ this -> queries -> visibleForList ();
2628
2729 return $ this ->apiListingResponse ($ shelves , [
2830 'id ' , 'name ' , 'slug ' , 'description ' , 'created_at ' , 'updated_at ' , 'created_by ' , 'updated_by ' , 'owned_by ' ,
@@ -54,7 +56,7 @@ public function create(Request $request)
5456 */
5557 public function read (string $ id )
5658 {
57- $ shelf = Bookshelf:: visible ()-> findOrFail ( $ id );
59+ $ shelf = $ this -> queries -> findVisibleByIdOrFail ( intval ( $ id) );
5860 $ shelf = $ this ->forJsonDisplay ($ shelf );
5961 $ shelf ->load ([
6062 'createdBy ' , 'updatedBy ' , 'ownedBy ' ,
@@ -78,7 +80,7 @@ public function read(string $id)
7880 */
7981 public function update (Request $ request , string $ id )
8082 {
81- $ shelf = Bookshelf:: visible ()-> findOrFail ( $ id );
83+ $ shelf = $ this -> queries -> findVisibleByIdOrFail ( intval ( $ id) );
8284 $ this ->checkOwnablePermission ('bookshelf-update ' , $ shelf );
8385
8486 $ requestData = $ this ->validate ($ request , $ this ->rules ()['update ' ]);
@@ -97,7 +99,7 @@ public function update(Request $request, string $id)
9799 */
98100 public function delete (string $ id )
99101 {
100- $ shelf = Bookshelf:: visible ()-> findOrFail ( $ id );
102+ $ shelf = $ this -> queries -> findVisibleByIdOrFail ( intval ( $ id) );
101103 $ this ->checkOwnablePermission ('bookshelf-delete ' , $ shelf );
102104
103105 $ this ->bookshelfRepo ->destroy ($ shelf );
0 commit comments