]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'chapter-templates' into development
authorDan Brown <redacted>
Thu, 1 Feb 2024 12:55:38 +0000 (12:55 +0000)
committerDan Brown <redacted>
Thu, 1 Feb 2024 12:55:38 +0000 (12:55 +0000)
1  2 
app/Entities/Controllers/ChapterApiController.php
dev/api/responses/chapters-create.json
dev/api/responses/chapters-update.json
tests/Api/ChaptersApiTest.php

index 85c81c2485c92e129c56f2a32ed3f09b5e00e62b,27b8206592d0a32b14742454e48d9d1527f1b0a4..3fbe852220579d2b0ad36b8b7f3237d5338af658
@@@ -15,20 -15,22 +15,22 @@@ class ChapterApiController extends ApiC
  {
      protected $rules = [
          'create' => [
-             'book_id'          => ['required', 'integer'],
-             'name'             => ['required', 'string', 'max:255'],
-             'description'      => ['string', 'max:1900'],
-             'description_html' => ['string', 'max:2000'],
-             'tags'             => ['array'],
-             'priority'         => ['integer'],
+             'book_id'             => ['required', 'integer'],
+             'name'                => ['required', 'string', 'max:255'],
+             'description'         => ['string', 'max:1900'],
+             'description_html'    => ['string', 'max:2000'],
+             'tags'                => ['array'],
+             'priority'            => ['integer'],
+             'default_template_id' => ['nullable', 'integer'],
          ],
          'update' => [
-             'book_id'          => ['integer'],
-             'name'             => ['string', 'min:1', 'max:255'],
-             'description'      => ['string', 'max:1900'],
-             'description_html' => ['string', 'max:2000'],
-             'tags'             => ['array'],
-             'priority'         => ['integer'],
+             'book_id'             => ['integer'],
+             'name'                => ['string', 'min:1', 'max:255'],
+             'description'         => ['string', 'max:1900'],
+             'description_html'    => ['string', 'max:2000'],
+             'tags'                => ['array'],
+             'priority'            => ['integer'],
+             'default_template_id' => ['nullable', 'integer'],
          ],
      ];
  
          $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 2d40444058751c6affd3dd819b0a81a8359e1a32,1e81a1e6363fc575770836aba0261f5ef3b48fed..3711d1cc9d6cea5248242e152dda3c9980ffb835
@@@ -11,7 -11,7 +11,8 @@@
    "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>",
+   "default_template_id": 25,
 +  "book_slug": "example-book",
    "tags": [
      {
        "name": "Category",
@@@ -24,4 -24,4 +25,4 @@@
        "order": 0
      }
    ]
--}
++}
index 3dad6aa0c12245c4ae4cdd870a96eb637a384ad5,4d8d0024e6ae5bce265adedf3c48fedd03a43a3a..96784dcedf7da605d962c2ddd39c6adeffaeb5f1
@@@ -11,7 -11,7 +11,8 @@@
    "updated_by": 1,
    "owned_by": 1,
    "description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>",
+   "default_template_id": 2428,
 +  "book_slug": "example-book",
    "tags": [
      {
        "name": "Category",
@@@ -24,4 -24,4 +25,4 @@@
        "order": 0
      }
    ]
--}
++}
index 002046c3a3b2388ab56fc89f5bfeff03e64fed5d,fdb80a4973eb761dfbb65437337314da4628ccb3..e2d6cfc81f0a8ce5e12172c7f4c793787feff2e4
@@@ -22,12 -22,11 +22,12 @@@ class ChaptersApiTest extends TestCas
          $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,
              ],
          ]]);
      }
@@@ -36,6 -35,7 +36,7 @@@
      {
          $this->actingAsApiEditor();
          $book = $this->entities->book();
+         $templatePage = $this->entities->templatePage();
          $details = [
              'name'        => 'My API chapter',
              'description' => 'A chapter created via the API',
@@@ -47,6 -47,7 +48,7 @@@
                  ],
              ],
              'priority' => 15,
+             'default_template_id' => $templatePage->id,
          ];
  
          $resp = $this->postJson($this->baseEndpoint, $details);
          $resp->assertJson([
              'id'         => $chapter->id,
              'slug'       => $chapter->slug,
 +            'book_slug'  => $chapter->book->slug,
              'created_by' => [
                  'name' => $chapter->createdBy->name,
              ],
                      'name' => $page->name,
                  ],
              ],
+             'default_template_id' => null,
          ]);
 +        $resp->assertJsonMissingPath('book');
          $resp->assertJsonCount($chapter->pages()->count(), 'pages');
      }
  
      {
          $this->actingAsApiEditor();
          $chapter = $this->entities->chapter();
+         $templatePage = $this->entities->templatePage();
          $details = [
              'name'        => 'My updated API chapter',
              'description' => 'A chapter updated via the API',
                  ],
              ],
              'priority'    => 15,
+             'default_template_id' => $templatePage->id,
          ];
  
          $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);