22
33namespace BookStack \Entities \Controllers ;
44
5- use BookStack \Entities \Models \Book ;
65use BookStack \Entities \Models \Chapter ;
6+ use BookStack \Entities \Queries \BookQueries ;
7+ use BookStack \Entities \Queries \ChapterQueries ;
78use BookStack \Entities \Repos \ChapterRepo ;
89use BookStack \Exceptions \PermissionsException ;
910use BookStack \Http \ApiController ;
@@ -35,7 +36,9 @@ class ChapterApiController extends ApiController
3536 ];
3637
3738 public function __construct (
38- protected ChapterRepo $ chapterRepo
39+ protected ChapterRepo $ chapterRepo ,
40+ protected ChapterQueries $ queries ,
41+ protected BookQueries $ bookQueries ,
3942 ) {
4043 }
4144
@@ -44,7 +47,7 @@ public function __construct(
4447 */
4548 public function list ()
4649 {
47- $ chapters = Chapter:: visible ();
50+ $ chapters = $ this -> queries -> visibleForList ();
4851
4952 return $ this ->apiListingResponse ($ chapters , [
5053 'id ' , 'book_id ' , 'name ' , 'slug ' , 'description ' , 'priority ' ,
@@ -60,7 +63,7 @@ public function create(Request $request)
6063 $ requestData = $ this ->validate ($ request , $ this ->rules ['create ' ]);
6164
6265 $ bookId = $ request ->get ('book_id ' );
63- $ book = Book:: visible ()-> findOrFail ( $ bookId );
66+ $ book = $ this -> bookQueries -> findVisibleByIdOrFail ( intval ( $ bookId) );
6467 $ this ->checkOwnablePermission ('chapter-create ' , $ book );
6568
6669 $ chapter = $ this ->chapterRepo ->create ($ requestData , $ book );
@@ -73,7 +76,7 @@ public function create(Request $request)
7376 */
7477 public function read (string $ id )
7578 {
76- $ chapter = Chapter:: visible ()-> findOrFail ( $ id );
79+ $ chapter = $ this -> queries -> findVisibleByIdOrFail ( intval ( $ id) );
7780 $ chapter = $ this ->forJsonDisplay ($ chapter );
7881
7982 $ chapter ->load ([
@@ -94,7 +97,7 @@ public function read(string $id)
9497 public function update (Request $ request , string $ id )
9598 {
9699 $ requestData = $ this ->validate ($ request , $ this ->rules ()['update ' ]);
97- $ chapter = Chapter:: visible ()-> findOrFail ( $ id );
100+ $ chapter = $ this -> queries -> findVisibleByIdOrFail ( intval ( $ id) );
98101 $ this ->checkOwnablePermission ('chapter-update ' , $ chapter );
99102
100103 if ($ request ->has ('book_id ' ) && $ chapter ->book_id !== intval ($ requestData ['book_id ' ])) {
@@ -122,7 +125,7 @@ public function update(Request $request, string $id)
122125 */
123126 public function delete (string $ id )
124127 {
125- $ chapter = Chapter:: visible ()-> findOrFail ( $ id );
128+ $ chapter = $ this -> queries -> findVisibleByIdOrFail ( intval ( $ id) );
126129 $ this ->checkOwnablePermission ('chapter-delete ' , $ chapter );
127130
128131 $ this ->chapterRepo ->destroy ($ chapter );
0 commit comments