Aligns with what we provide in the UI.
Added/updated tests to cover, and updated API examples.
For 5180.
{
$books = $this->queries
->visibleForList()
+ ->with(['cover:id,name,url'])
->addSelect(['created_by', 'updated_by']);
return $this->apiListingResponse($books, [
{
$shelves = $this->queries
->visibleForList()
+ ->with(['cover:id,name,url'])
->addSelect(['created_by', 'updated_by']);
return $this->apiListingResponse($shelves, [
"updated_at": "2019-12-11T20:57:31.000000Z",
"created_by": 1,
"updated_by": 1,
- "owned_by": 1
+ "owned_by": 1,
+ "cover": null
},
{
"id": 2,
"updated_at": "2019-12-11T20:57:23.000000Z",
"created_by": 4,
"updated_by": 3,
- "owned_by": 3
+ "owned_by": 3,
+ "cover": {
+ "id": 11,
+ "name": "cat_banner.jpg",
+ "url": "https://example.com/uploads/images/cover_book/2021-10/cat-banner.jpg"
+ }
}
],
"total": 14
"updated_at": "2020-04-10T13:00:45.000000Z",
"created_by": 4,
"updated_by": 1,
- "owned_by": 1
+ "owned_by": 1,
+ "cover": {
+ "id": 4,
+ "name": "shelf.jpg",
+ "url": "https://example.com/uploads/images/cover_bookshelf/2024-12/shelf.jpg"
+ }
},
{
"id": 9,
"updated_at": "2020-04-10T13:00:58.000000Z",
"created_by": 4,
"updated_by": 1,
- "owned_by": 1
+ "owned_by": 1,
+ "cover": null
},
{
"id": 10,
"updated_at": "2020-04-10T13:00:53.000000Z",
"created_by": 4,
"updated_by": 1,
- "owned_by": 4
+ "owned_by": 4,
+ "cover": null
}
],
"total": 3
namespace Tests\Api;
use BookStack\Entities\Models\Book;
+use BookStack\Entities\Repos\BaseRepo;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
'owned_by' => $firstBook->owned_by,
'created_by' => $firstBook->created_by,
'updated_by' => $firstBook->updated_by,
+ 'cover' => null,
+ ],
+ ]]);
+ }
+
+ public function test_index_endpoint_includes_cover_if_set()
+ {
+ $this->actingAsApiEditor();
+ $book = $this->entities->book();
+
+ $baseRepo = $this->app->make(BaseRepo::class);
+ $image = $this->files->uploadedImage('book_cover');
+ $baseRepo->updateCoverImage($book, $image);
+
+ $resp = $this->getJson($this->baseEndpoint . '?filter[id]=' . $book->id);
+ $resp->assertJson(['data' => [
+ [
+ 'id' => $book->id,
+ 'cover' => [
+ 'id' => $book->cover->id,
+ 'url' => $book->cover->url,
+ ],
],
]]);
}
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
+use BookStack\Entities\Repos\BaseRepo;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
'owned_by' => $firstBookshelf->owned_by,
'created_by' => $firstBookshelf->created_by,
'updated_by' => $firstBookshelf->updated_by,
+ 'cover' => null,
+ ],
+ ]]);
+ }
+
+ public function test_index_endpoint_includes_cover_if_set()
+ {
+ $this->actingAsApiEditor();
+ $shelf = $this->entities->shelf();
+
+ $baseRepo = $this->app->make(BaseRepo::class);
+ $image = $this->files->uploadedImage('shelf_cover');
+ $baseRepo->updateCoverImage($shelf, $image);
+
+ $resp = $this->getJson($this->baseEndpoint . '?filter[id]=' . $shelf->id);
+ $resp->assertJson(['data' => [
+ [
+ 'id' => $shelf->id,
+ 'cover' => [
+ 'id' => $shelf->cover->id,
+ 'url' => $shelf->cover->url,
+ ],
],
]]);
}
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Entity;
+use BookStack\Entities\Models\HasCoverImage;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\BookRepo;
use BookStack\Entities\Repos\BookshelfRepo;