File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public function list()
3030 {
3131 $ books = $ this ->queries
3232 ->visibleForList ()
33+ ->with (['cover:id,name,url ' ])
3334 ->addSelect (['created_by ' , 'updated_by ' ]);
3435
3536 return $ this ->apiListingResponse ($ books , [
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public function list()
2626 {
2727 $ shelves = $ this ->queries
2828 ->visibleForList ()
29+ ->with (['cover:id,name,url ' ])
2930 ->addSelect (['created_by ' , 'updated_by ' ]);
3031
3132 return $ this ->apiListingResponse ($ shelves , [
Original file line number Diff line number Diff line change 99 "updated_at" : " 2019-12-11T20:57:31.000000Z" ,
1010 "created_by" : 1 ,
1111 "updated_by" : 1 ,
12- "owned_by" : 1
12+ "owned_by" : 1 ,
13+ "cover" : null
1314 },
1415 {
1516 "id" : 2 ,
2021 "updated_at" : " 2019-12-11T20:57:23.000000Z" ,
2122 "created_by" : 4 ,
2223 "updated_by" : 3 ,
23- "owned_by" : 3
24+ "owned_by" : 3 ,
25+ "cover" : {
26+ "id" : 11 ,
27+ "name" : " cat_banner.jpg" ,
28+ "url" : " https://example.com/uploads/images/cover_book/2021-10/cat-banner.jpg"
29+ }
2430 }
2531 ],
2632 "total" : 14
Original file line number Diff line number Diff line change 99 "updated_at" : " 2020-04-10T13:00:45.000000Z" ,
1010 "created_by" : 4 ,
1111 "updated_by" : 1 ,
12- "owned_by" : 1
12+ "owned_by" : 1 ,
13+ "cover" : {
14+ "id" : 4 ,
15+ "name" : " shelf.jpg" ,
16+ "url" : " https://example.com/uploads/images/cover_bookshelf/2024-12/shelf.jpg"
17+ }
1318 },
1419 {
1520 "id" : 9 ,
2025 "updated_at" : " 2020-04-10T13:00:58.000000Z" ,
2126 "created_by" : 4 ,
2227 "updated_by" : 1 ,
23- "owned_by" : 1
28+ "owned_by" : 1 ,
29+ "cover" : null
2430 },
2531 {
2632 "id" : 10 ,
3137 "updated_at" : " 2020-04-10T13:00:53.000000Z" ,
3238 "created_by" : 4 ,
3339 "updated_by" : 1 ,
34- "owned_by" : 4
40+ "owned_by" : 4 ,
41+ "cover" : null
3542 }
3643 ],
3744 "total" : 3
Original file line number Diff line number Diff line change 33namespace Tests \Api ;
44
55use BookStack \Entities \Models \Book ;
6+ use BookStack \Entities \Repos \BaseRepo ;
67use Carbon \Carbon ;
78use Illuminate \Support \Facades \DB ;
89use Tests \TestCase ;
@@ -27,6 +28,28 @@ public function test_index_endpoint_returns_expected_book()
2728 'owned_by ' => $ firstBook ->owned_by ,
2829 'created_by ' => $ firstBook ->created_by ,
2930 'updated_by ' => $ firstBook ->updated_by ,
31+ 'cover ' => null ,
32+ ],
33+ ]]);
34+ }
35+
36+ public function test_index_endpoint_includes_cover_if_set ()
37+ {
38+ $ this ->actingAsApiEditor ();
39+ $ book = $ this ->entities ->book ();
40+
41+ $ baseRepo = $ this ->app ->make (BaseRepo::class);
42+ $ image = $ this ->files ->uploadedImage ('book_cover ' );
43+ $ baseRepo ->updateCoverImage ($ book , $ image );
44+
45+ $ resp = $ this ->getJson ($ this ->baseEndpoint . '?filter[id]= ' . $ book ->id );
46+ $ resp ->assertJson (['data ' => [
47+ [
48+ 'id ' => $ book ->id ,
49+ 'cover ' => [
50+ 'id ' => $ book ->cover ->id ,
51+ 'url ' => $ book ->cover ->url ,
52+ ],
3053 ],
3154 ]]);
3255 }
Original file line number Diff line number Diff line change 44
55use BookStack \Entities \Models \Book ;
66use BookStack \Entities \Models \Bookshelf ;
7+ use BookStack \Entities \Repos \BaseRepo ;
78use Carbon \Carbon ;
89use Illuminate \Support \Facades \DB ;
910use Tests \TestCase ;
@@ -28,6 +29,28 @@ public function test_index_endpoint_returns_expected_shelf()
2829 'owned_by ' => $ firstBookshelf ->owned_by ,
2930 'created_by ' => $ firstBookshelf ->created_by ,
3031 'updated_by ' => $ firstBookshelf ->updated_by ,
32+ 'cover ' => null ,
33+ ],
34+ ]]);
35+ }
36+
37+ public function test_index_endpoint_includes_cover_if_set ()
38+ {
39+ $ this ->actingAsApiEditor ();
40+ $ shelf = $ this ->entities ->shelf ();
41+
42+ $ baseRepo = $ this ->app ->make (BaseRepo::class);
43+ $ image = $ this ->files ->uploadedImage ('shelf_cover ' );
44+ $ baseRepo ->updateCoverImage ($ shelf , $ image );
45+
46+ $ resp = $ this ->getJson ($ this ->baseEndpoint . '?filter[id]= ' . $ shelf ->id );
47+ $ resp ->assertJson (['data ' => [
48+ [
49+ 'id ' => $ shelf ->id ,
50+ 'cover ' => [
51+ 'id ' => $ shelf ->cover ->id ,
52+ 'url ' => $ shelf ->cover ->url ,
53+ ],
3154 ],
3255 ]]);
3356 }
Original file line number Diff line number Diff line change 66use BookStack \Entities \Models \Bookshelf ;
77use BookStack \Entities \Models \Chapter ;
88use BookStack \Entities \Models \Entity ;
9+ use BookStack \Entities \Models \HasCoverImage ;
910use BookStack \Entities \Models \Page ;
1011use BookStack \Entities \Repos \BookRepo ;
1112use BookStack \Entities \Repos \BookshelfRepo ;
You can’t perform that action at this time.
0 commit comments