File tree 7 files changed +67
-5
lines changed
7 files changed +67
-5
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public function list()
30
30
{
31
31
$ books = $ this ->queries
32
32
->visibleForList ()
33
+ ->with (['cover:id,name,url ' ])
33
34
->addSelect (['created_by ' , 'updated_by ' ]);
34
35
35
36
return $ this ->apiListingResponse ($ books , [
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public function list()
26
26
{
27
27
$ shelves = $ this ->queries
28
28
->visibleForList ()
29
+ ->with (['cover:id,name,url ' ])
29
30
->addSelect (['created_by ' , 'updated_by ' ]);
30
31
31
32
return $ this ->apiListingResponse ($ shelves , [
Original file line number Diff line number Diff line change 9
9
"updated_at" : " 2019-12-11T20:57:31.000000Z" ,
10
10
"created_by" : 1 ,
11
11
"updated_by" : 1 ,
12
- "owned_by" : 1
12
+ "owned_by" : 1 ,
13
+ "cover" : null
13
14
},
14
15
{
15
16
"id" : 2 ,
20
21
"updated_at" : " 2019-12-11T20:57:23.000000Z" ,
21
22
"created_by" : 4 ,
22
23
"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
+ }
24
30
}
25
31
],
26
32
"total" : 14
Original file line number Diff line number Diff line change 9
9
"updated_at" : " 2020-04-10T13:00:45.000000Z" ,
10
10
"created_by" : 4 ,
11
11
"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
+ }
13
18
},
14
19
{
15
20
"id" : 9 ,
20
25
"updated_at" : " 2020-04-10T13:00:58.000000Z" ,
21
26
"created_by" : 4 ,
22
27
"updated_by" : 1 ,
23
- "owned_by" : 1
28
+ "owned_by" : 1 ,
29
+ "cover" : null
24
30
},
25
31
{
26
32
"id" : 10 ,
31
37
"updated_at" : " 2020-04-10T13:00:53.000000Z" ,
32
38
"created_by" : 4 ,
33
39
"updated_by" : 1 ,
34
- "owned_by" : 4
40
+ "owned_by" : 4 ,
41
+ "cover" : null
35
42
}
36
43
],
37
44
"total" : 3
Original file line number Diff line number Diff line change 3
3
namespace Tests \Api ;
4
4
5
5
use BookStack \Entities \Models \Book ;
6
+ use BookStack \Entities \Repos \BaseRepo ;
6
7
use Carbon \Carbon ;
7
8
use Illuminate \Support \Facades \DB ;
8
9
use Tests \TestCase ;
@@ -27,6 +28,28 @@ public function test_index_endpoint_returns_expected_book()
27
28
'owned_by ' => $ firstBook ->owned_by ,
28
29
'created_by ' => $ firstBook ->created_by ,
29
30
'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
+ ],
30
53
],
31
54
]]);
32
55
}
Original file line number Diff line number Diff line change 4
4
5
5
use BookStack \Entities \Models \Book ;
6
6
use BookStack \Entities \Models \Bookshelf ;
7
+ use BookStack \Entities \Repos \BaseRepo ;
7
8
use Carbon \Carbon ;
8
9
use Illuminate \Support \Facades \DB ;
9
10
use Tests \TestCase ;
@@ -28,6 +29,28 @@ public function test_index_endpoint_returns_expected_shelf()
28
29
'owned_by ' => $ firstBookshelf ->owned_by ,
29
30
'created_by ' => $ firstBookshelf ->created_by ,
30
31
'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
+ ],
31
54
],
32
55
]]);
33
56
}
Original file line number Diff line number Diff line change 6
6
use BookStack \Entities \Models \Bookshelf ;
7
7
use BookStack \Entities \Models \Chapter ;
8
8
use BookStack \Entities \Models \Entity ;
9
+ use BookStack \Entities \Models \HasCoverImage ;
9
10
use BookStack \Entities \Models \Page ;
10
11
use BookStack \Entities \Repos \BookRepo ;
11
12
use BookStack \Entities \Repos \BookshelfRepo ;
You can’t perform that action at this time.
0 commit comments