]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'add-priority' into development
authorDan Brown <redacted>
Mon, 21 Aug 2023 14:43:16 +0000 (15:43 +0100)
committerDan Brown <redacted>
Mon, 21 Aug 2023 14:43:16 +0000 (15:43 +0100)
14 files changed:
app/Api/ApiEntityListFormatter.php
app/Entities/Controllers/ChapterApiController.php
app/Entities/Controllers/PageApiController.php
app/Entities/Repos/ChapterRepo.php
app/Entities/Repos/PageRepo.php
dev/api/requests/chapters-create.json
dev/api/requests/chapters-update.json
dev/api/requests/pages-create.json
dev/api/requests/pages-update.json
dev/api/responses/chapters-create.json
dev/api/responses/chapters-update.json
dev/api/responses/pages-create.json
tests/Api/ChaptersApiTest.php
tests/Api/PagesApiTest.php

index c170ecf0c9d51bf30b3fdb3b7ee270f936ef71a7..436d66d598e8f2fb86fc27622f9016900b2a7c8e 100644 (file)
@@ -10,7 +10,7 @@ class ApiEntityListFormatter
      * The list to be formatted.
      * @var Entity[]
      */
-    protected $list = [];
+    protected array $list = [];
 
     /**
      * The fields to show in the formatted data.
@@ -19,9 +19,9 @@ class ApiEntityListFormatter
      * will be used for the resultant value. A null return value will omit the property.
      * @var array<string|int, string|callable>
      */
-    protected $fields = [
-        'id', 'name', 'slug', 'book_id', 'chapter_id',
-        'draft', 'template', 'created_at', 'updated_at',
+    protected array $fields = [
+        'id', 'name', 'slug', 'book_id', 'chapter_id', 'draft',
+        'template', 'priority', 'created_at', 'updated_at',
     ];
 
     public function __construct(array $list)
index 403c58de3c5a1a346c3e6f778a0b336c0ba1b23d..7f01e445a576d3d86cbbf097da50a09014472c44 100644 (file)
@@ -19,12 +19,14 @@ class ChapterApiController extends ApiController
             'name'        => ['required', 'string', 'max:255'],
             'description' => ['string', 'max:1000'],
             'tags'        => ['array'],
+            'priority'    => ['integer'],
         ],
         'update' => [
             'book_id'     => ['integer'],
             'name'        => ['string', 'min:1', 'max:255'],
             'description' => ['string', 'max:1000'],
             'tags'        => ['array'],
+            'priority'    => ['integer'],
         ],
     ];
 
index 0e8893450fe8e906522c96cea463cea61f4e2f6b..d2947f1bb7227c560214fba3e472c0cb2ef0b5d1 100644 (file)
@@ -21,6 +21,7 @@ class PageApiController extends ApiController
             'html'       => ['required_without:markdown', 'string'],
             'markdown'   => ['required_without:html', 'string'],
             'tags'       => ['array'],
+            'priority'   => ['integer'],
         ],
         'update' => [
             'book_id'    => ['integer'],
@@ -29,6 +30,7 @@ class PageApiController extends ApiController
             'html'       => ['string'],
             'markdown'   => ['string'],
             'tags'       => ['array'],
+            'priority'   => ['integer'],
         ],
     ];
 
index 588854c7e91c34b05280a3458ed13ff72d5f7fa1..977193d85bbd0229a2d1a1e745dbf5fd01dd4a83 100644 (file)
@@ -16,14 +16,9 @@ use Exception;
 
 class ChapterRepo
 {
-    protected $baseRepo;
-
-    /**
-     * ChapterRepo constructor.
-     */
-    public function __construct(BaseRepo $baseRepo)
-    {
-        $this->baseRepo = $baseRepo;
+    public function __construct(
+        protected BaseRepo $baseRepo
+    ) {
     }
 
     /**
index 521519dc08d607d8a831015adc55e942f46b47bd..61a1db63e397dbdfa944d7a2818a37d5f2b9d296 100644 (file)
@@ -23,24 +23,12 @@ use Illuminate\Pagination\LengthAwarePaginator;
 
 class PageRepo
 {
-    protected BaseRepo $baseRepo;
-    protected RevisionRepo $revisionRepo;
-    protected ReferenceStore $referenceStore;
-    protected ReferenceUpdater $referenceUpdater;
-
-    /**
-     * PageRepo constructor.
-     */
     public function __construct(
-        BaseRepo $baseRepo,
-        RevisionRepo $revisionRepo,
-        ReferenceStore $referenceStore,
-        ReferenceUpdater $referenceUpdater
+        protected BaseRepo $baseRepo,
+        protected RevisionRepo $revisionRepo,
+        protected ReferenceStore $referenceStore,
+        protected ReferenceUpdater $referenceUpdater
     ) {
-        $this->baseRepo = $baseRepo;
-        $this->revisionRepo = $revisionRepo;
-        $this->referenceStore = $referenceStore;
-        $this->referenceUpdater = $referenceUpdater;
     }
 
     /**
@@ -159,13 +147,11 @@ class PageRepo
      */
     public function publishDraft(Page $draft, array $input): Page
     {
-        $this->updateTemplateStatusAndContentFromInput($draft, $input);
-        $this->baseRepo->update($draft, $input);
-
         $draft->draft = false;
         $draft->revision_count = 1;
         $draft->priority = $this->getNewPriority($draft);
-        $draft->save();
+        $this->updateTemplateStatusAndContentFromInput($draft, $input);
+        $this->baseRepo->update($draft, $input);
 
         $this->revisionRepo->storeNewForPage($draft, trans('entities.pages_initial_revision'));
         $this->referenceStore->updateForPage($draft);
index ca06fc29859bdb0b82f7b6330326535d2f7133c6..a7a0e072c6c6db48a8727400399edd2907c37999 100644 (file)
@@ -2,8 +2,9 @@
   "book_id": 1,
   "name": "My fantastic new chapter",
   "description": "This is a great new chapter that I've created via the API",
+  "priority": 15,
   "tags": [
     {"name": "Category", "value": "Top Content"},
     {"name": "Rating", "value": "Highest"}
   ]
-}
\ No newline at end of file
+}
index 6bd3a3e5c092ac8d8c95faf5ddfdb4e491e00531..18c40301b6d7a6784b4ee3c88ddcf1b1967d3b1d 100644 (file)
@@ -2,8 +2,9 @@
   "book_id": 1,
   "name": "My fantastic updated chapter",
   "description": "This is an updated chapter that I've altered via the API",
+  "priority": 16,
   "tags": [
     {"name": "Category", "value": "Kinda Good Content"},
     {"name": "Rating", "value": "Medium"}
   ]
-}
\ No newline at end of file
+}
index 1f53b42d48901a3b532fb8413f29f0931e7df0ef..bb32943a2355544b7933247ba11e7d0b52aa2f5a 100644 (file)
@@ -2,8 +2,9 @@
        "book_id": 1,
        "name": "My API Page",
        "html": "<p>my new API page</p>",
+       "priority": 15,
        "tags": [
                {"name": "Category", "value": "Not Bad Content"},
                {"name": "Rating", "value": "Average"}
        ]
-}
\ No newline at end of file
+}
index b9bfeb630decbf8d98cb8323bd0fd7f9218ddae4..e3ca9004e5e4c3599ab1c9c0582bc7b897b41ed2 100644 (file)
@@ -2,8 +2,9 @@
        "chapter_id": 1,
        "name": "My updated API Page",
        "html": "<p>my new API page - Updated</p>",
+       "priority": 16,
        "tags": [
                {"name": "Category", "value": "API Examples"},
                {"name": "Rating", "value": "Alright"}
        ]
-}
\ No newline at end of file
+}
index 4dbc764b157d29b035edf6407a2dc2dacd3b4cef..cf47b123df7bb1027a2a5a5fe96bb61afd9d667a 100644 (file)
@@ -4,7 +4,7 @@
   "slug": "my-fantastic-new-chapter",
   "name": "My fantastic new chapter",
   "description": "This is a great new chapter that I've created via the API",
-  "priority": 6,
+  "priority": 15,
   "created_by": 1,
   "updated_by": 1,
   "owned_by": 1,
index cc454d74086bad6705bda16dd2021226440192f5..a4940af2df535d35e5cb65682984cdb821a76449 100644 (file)
@@ -4,7 +4,7 @@
   "slug": "my-fantastic-updated-chapter",
   "name": "My fantastic updated chapter",
   "description": "This is an updated chapter that I've altered via the API",
-  "priority": 7,
+  "priority": 16,
   "created_at": "2020-05-22T23:03:35.000000Z",
   "updated_at": "2020-05-22T23:07:20.000000Z",
   "created_by": 1,
index 385d5384e72cb014ad7afb6c9c79013138c1afb4..11f5ab8c8a5e3bec5459a697fbf5d0941ef6e202 100644 (file)
@@ -6,7 +6,7 @@
        "slug": "my-api-page",
        "html": "<p id=\"bkmrk-my-new-api-page\">my new API page</p>",
        "raw_html": "<p id=\"bkmrk-my-new-api-page\">my new API page</p>",
-       "priority": 14,
+       "priority": 15,
        "created_at": "2020-11-28T15:01:39.000000Z",
        "updated_at": "2020-11-28T15:01:39.000000Z",
        "created_by": {
index 713d8bba4bab6156b1c5b326ec5df2cc7efe26b6..0629f3aedae61fadd338fcc9dc20cfefc959da2d 100644 (file)
@@ -45,6 +45,7 @@ class ChaptersApiTest extends TestCase
                     'value' => 'tagvalue',
                 ],
             ],
+            'priority' => 15,
         ];
 
         $resp = $this->postJson($this->baseEndpoint, $details);
@@ -137,6 +138,7 @@ class ChaptersApiTest extends TestCase
                     'value' => 'freshtagval',
                 ],
             ],
+            'priority'    => 15,
         ];
 
         $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);
index 4a81f738bbdb092f12ce922331a7011600331b71..0d084472d1a43e0caf78136a78b07801b8c816ed 100644 (file)
@@ -45,6 +45,7 @@ class PagesApiTest extends TestCase
                     'value' => 'tagvalue',
                 ],
             ],
+            'priority' => 15,
         ];
 
         $resp = $this->postJson($this->baseEndpoint, $details);
@@ -207,6 +208,7 @@ class PagesApiTest extends TestCase
                     'value' => 'freshtagval',
                 ],
             ],
+            'priority' => 15,
         ];
 
         $resp = $this->putJson($this->baseEndpoint . "/{$page->id}", $details);