]> BookStack Code Mirror - bookstack/commitdiff
Chapters API: Added missing book_slug field
authorDan Brown <redacted>
Tue, 16 Jan 2024 12:06:13 +0000 (12:06 +0000)
committerDan Brown <redacted>
Tue, 16 Jan 2024 12:06:13 +0000 (12:06 +0000)
Was removed during previous changes, but reflected in response examples.
This adds into all standard single chapter responses.
For #4765

app/Entities/Controllers/ChapterApiController.php
dev/api/responses/chapters-create.json
dev/api/responses/chapters-update.json
tests/Api/ChaptersApiTest.php

index c2132326200c5f186fdcfb82d680103a985ad20f..85c81c2485c92e129c56f2a32ed3f09b5e00e62b 100644 (file)
@@ -134,8 +134,9 @@ class ChapterApiController extends ApiController
         $chapter->unsetRelations()->refresh();
 
         $chapter->load(['tags']);
-        $chapter->makeVisible('description_html')
-            ->setAttribute('description_html', $chapter->descriptionHtml());
+        $chapter->makeVisible('description_html');
+        $chapter->setAttribute('description_html', $chapter->descriptionHtml());
+        $chapter->setAttribute('book_slug', $chapter->book()->first()->slug);
 
         return $chapter;
     }
index 183186b0b4295d1a895254a11cb097dd7c082cd4..2d40444058751c6affd3dd819b0a81a8359e1a32 100644 (file)
@@ -11,6 +11,7 @@
   "updated_by": 1,
   "owned_by": 1,
   "description_html": "<p>This is a <strong>great new chapter<\/strong> that I've created via the API<\/p>",
+  "book_slug": "example-book",
   "tags": [
     {
       "name": "Category",
index 5ac3c64c12fdfa0684b0e9046c93dc483215725c..3dad6aa0c12245c4ae4cdd870a96eb637a384ad5 100644 (file)
@@ -11,6 +11,7 @@
   "updated_by": 1,
   "owned_by": 1,
   "description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>",
+  "book_slug": "example-book",
   "tags": [
     {
       "name": "Category",
index 81a91887794f693acaa5d6df28df9dfca259b716..002046c3a3b2388ab56fc89f5bfeff03e64fed5d 100644 (file)
@@ -22,11 +22,12 @@ class ChaptersApiTest extends TestCase
         $resp = $this->getJson($this->baseEndpoint . '?count=1&sort=+id');
         $resp->assertJson(['data' => [
             [
-                'id'       => $firstChapter->id,
-                'name'     => $firstChapter->name,
-                'slug'     => $firstChapter->slug,
-                'book_id'  => $firstChapter->book->id,
-                'priority' => $firstChapter->priority,
+                'id'        => $firstChapter->id,
+                'name'      => $firstChapter->name,
+                'slug'      => $firstChapter->slug,
+                'book_id'   => $firstChapter->book->id,
+                'priority'  => $firstChapter->priority,
+                'book_slug' => $firstChapter->book->slug,
             ],
         ]]);
     }
@@ -130,6 +131,7 @@ class ChaptersApiTest extends TestCase
         $resp->assertJson([
             'id'         => $chapter->id,
             'slug'       => $chapter->slug,
+            'book_slug'  => $chapter->book->slug,
             'created_by' => [
                 'name' => $chapter->createdBy->name,
             ],
@@ -148,6 +150,7 @@ class ChaptersApiTest extends TestCase
                 ],
             ],
         ]);
+        $resp->assertJsonMissingPath('book');
         $resp->assertJsonCount($chapter->pages()->count(), 'pages');
     }