* The list to be formatted.
* @var Entity[]
*/
- protected $list = [];
+ protected array $list = [];
/**
* The fields to show in the formatted data.
* 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',
- 'priority'
+ protected array $fields = [
+ 'id', 'name', 'slug', 'book_id', 'chapter_id', 'draft',
+ 'template', 'priority', 'created_at', 'updated_at',
];
public function __construct(array $list)
class ChapterRepo
{
- protected $baseRepo;
-
- /**
- * ChapterRepo constructor.
- */
- public function __construct(BaseRepo $baseRepo)
- {
- $this->baseRepo = $baseRepo;
+ public function __construct(
+ protected BaseRepo $baseRepo
+ ) {
}
/**
{
$chapter = new Chapter();
$chapter->book_id = $parentBook->id;
- $chapter->priority = $chapter->priority ?: (new BookContents($parentBook))->getLastPriority() + 1;
+ $chapter->priority = (new BookContents($parentBook))->getLastPriority() + 1;
$this->baseRepo->create($chapter, $input);
Activity::add(ActivityType::CHAPTER_CREATE, $chapter);
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;
}
/**
*/
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 = $draft->priority ?: $this->getNewPriority($draft);
- $draft->save();
+ $draft->priority = $this->getNewPriority($draft);
+ $this->updateTemplateStatusAndContentFromInput($draft, $input);
+ $this->baseRepo->update($draft, $input);
$this->revisionRepo->storeNewForPage($draft, trans('entities.pages_initial_revision'));
$this->referenceStore->updateForPage($draft);
"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"}
- ],
- "priority": 15
-}
+ ]
}
"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"}
- ],
- "priority": 15
+ ]
}
"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"}
- ],
- "priority": 15
+ ]
}
"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"}
- ],
- "priority": 15
+ ]
}
"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,
"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,
"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": {
'value' => 'tagvalue',
],
],
- ];
-
- $resp = $this->postJson($this->baseEndpoint, $details);
- $resp->assertStatus(200);
- $newItem = Chapter::query()->orderByDesc('id')->where('name', '=', $details['name'])->first();
- $resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug]));
- $this->assertDatabaseHas('tags', [
- 'entity_id' => $newItem->id,
- 'entity_type' => $newItem->getMorphClass(),
- 'name' => 'tagname',
- 'value' => 'tagvalue',
- ]);
- $resp->assertJsonMissing(['pages' => []]);
- $this->assertActivityExists('chapter_create', $newItem);
- }
-
- public function test_create_applies_correct_priority()
- {
- $this->actingAsApiEditor();
- $book = $this->entities->book();
- $details = [
- 'name' => 'My API chapter',
- 'description' => 'A chapter created via the API',
- 'book_id' => $book->id,
- 'tags' => [
- [
- 'name' => 'tagname',
- 'value' => 'tagvalue',
- ],
- ],
- 'priority' => 15,
+ 'priority' => 15,
];
$resp = $this->postJson($this->baseEndpoint, $details);
}
public function test_create_endpoint()
- {
- $this->actingAsApiEditor();
- $book = $this->entities->book();
- $details = [
- 'name' => 'My API page',
- 'book_id' => $book->id,
- 'html' => '<p>My new page content</p>',
- 'tags' => [
- [
- 'name' => 'tagname',
- 'value' => 'tagvalue',
- ],
- ],
- ];
-
- $resp = $this->postJson($this->baseEndpoint, $details);
- unset($details['html']);
- $resp->assertStatus(200);
- $newItem = Page::query()->orderByDesc('id')->where('name', '=', $details['name'])->first();
- $resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug]));
- $this->assertDatabaseHas('tags', [
- 'entity_id' => $newItem->id,
- 'entity_type' => $newItem->getMorphClass(),
- 'name' => 'tagname',
- 'value' => 'tagvalue',
- ]);
- $resp->assertSeeText('My new page content');
- $resp->assertJsonMissing(['book' => []]);
- $this->assertActivityExists('page_create', $newItem);
- }
-
- public function test_create_applies_correct_priority()
{
$this->actingAsApiEditor();
$book = $this->entities->book();