Skip to content

Commit adf1806

Browse files
committed
Chapters API: Added missing book_slug field
Was removed during previous changes, but reflected in response examples. This adds into all standard single chapter responses. For #4765
1 parent afbbcaf commit adf1806

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

app/Entities/Controllers/ChapterApiController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ protected function forJsonDisplay(Chapter $chapter): Chapter
134134
$chapter->unsetRelations()->refresh();
135135

136136
$chapter->load(['tags']);
137-
$chapter->makeVisible('description_html')
138-
->setAttribute('description_html', $chapter->descriptionHtml());
137+
$chapter->makeVisible('description_html');
138+
$chapter->setAttribute('description_html', $chapter->descriptionHtml());
139+
$chapter->setAttribute('book_slug', $chapter->book()->first()->slug);
139140

140141
return $chapter;
141142
}

dev/api/responses/chapters-create.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"updated_by": 1,
1212
"owned_by": 1,
1313
"description_html": "<p>This is a <strong>great new chapter<\/strong> that I've created via the API<\/p>",
14+
"book_slug": "example-book",
1415
"tags": [
1516
{
1617
"name": "Category",

dev/api/responses/chapters-update.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"updated_by": 1,
1212
"owned_by": 1,
1313
"description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>",
14+
"book_slug": "example-book",
1415
"tags": [
1516
{
1617
"name": "Category",

tests/Api/ChaptersApiTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ public function test_index_endpoint_returns_expected_chapter()
2222
$resp = $this->getJson($this->baseEndpoint . '?count=1&sort=+id');
2323
$resp->assertJson(['data' => [
2424
[
25-
'id' => $firstChapter->id,
26-
'name' => $firstChapter->name,
27-
'slug' => $firstChapter->slug,
28-
'book_id' => $firstChapter->book->id,
29-
'priority' => $firstChapter->priority,
25+
'id' => $firstChapter->id,
26+
'name' => $firstChapter->name,
27+
'slug' => $firstChapter->slug,
28+
'book_id' => $firstChapter->book->id,
29+
'priority' => $firstChapter->priority,
30+
'book_slug' => $firstChapter->book->slug,
3031
],
3132
]]);
3233
}
@@ -130,6 +131,7 @@ public function test_read_endpoint()
130131
$resp->assertJson([
131132
'id' => $chapter->id,
132133
'slug' => $chapter->slug,
134+
'book_slug' => $chapter->book->slug,
133135
'created_by' => [
134136
'name' => $chapter->createdBy->name,
135137
],
@@ -148,6 +150,7 @@ public function test_read_endpoint()
148150
],
149151
],
150152
]);
153+
$resp->assertJsonMissingPath('book');
151154
$resp->assertJsonCount($chapter->pages()->count(), 'pages');
152155
}
153156

0 commit comments

Comments
 (0)