add element descriptions
This commit is contained in:
parent
f2dc1483dd
commit
72e4720787
10 changed files with 47 additions and 0 deletions
|
|
@ -36,6 +36,7 @@ class ElementController
|
|||
$childElements[] = [
|
||||
'id' => $childElement->getId(),
|
||||
'title' => $childElement->getTitle(),
|
||||
'description' => $childElement->getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -44,6 +45,7 @@ class ElementController
|
|||
'element' => [
|
||||
'id' => $element->getId(),
|
||||
'title' => $element->getTitle(),
|
||||
'description' => $element->getDescription(),
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class CreateElementDto
|
|||
public function __construct(
|
||||
public Set $set,
|
||||
public string $title,
|
||||
public string $description,
|
||||
public ?Element $parentElement,
|
||||
) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class Element
|
|||
public function __construct(
|
||||
private int $id,
|
||||
private string $title,
|
||||
private string $description,
|
||||
private Set $set,
|
||||
private ?Element $parentElement,
|
||||
) {
|
||||
|
|
@ -24,6 +25,11 @@ class Element
|
|||
return $this->title;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function getSet(): Set
|
||||
{
|
||||
return $this->set;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property int $id
|
||||
* @property int $set_id
|
||||
* @property string $title
|
||||
* @property string $description
|
||||
* @property int|null $parent_element_id
|
||||
*
|
||||
* @method static Builder<static>|ElementModel newModelQuery()
|
||||
|
|
@ -18,6 +19,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @method static Builder<static>|ElementModel whereParentElementId($value)
|
||||
* @method static Builder<static>|ElementModel whereSetId($value)
|
||||
* @method static Builder<static>|ElementModel whereTitle($value)
|
||||
* @method static Builder<static>|ElementModel whereDescription($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
|
|
@ -30,6 +32,7 @@ class ElementModel extends Model
|
|||
protected $fillable = [
|
||||
'set_id',
|
||||
'title',
|
||||
'description',
|
||||
'parent_element_id',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ class EloquentElementRepository implements ElementRepository
|
|||
$model = ElementModel::create([
|
||||
'set_id' => $dto->set->getId(),
|
||||
'title' => $dto->title,
|
||||
'description' => $dto->description,
|
||||
'parent_element_id' => $dto->parentElement?->getId(),
|
||||
]);
|
||||
|
||||
return new Element(
|
||||
id: $model->id,
|
||||
title: $dto->title,
|
||||
description: $dto->description,
|
||||
set: $dto->set,
|
||||
parentElement: $dto->parentElement,
|
||||
);
|
||||
|
|
@ -102,6 +104,7 @@ class EloquentElementRepository implements ElementRepository
|
|||
return new Element(
|
||||
id: $model->id,
|
||||
title: $model->title,
|
||||
description: $model->description,
|
||||
set: $set,
|
||||
parentElement: $parentElement,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class CreateElement
|
|||
if ($request->title === null || $request->title === '') {
|
||||
throw new BadRequestException('title is required');
|
||||
}
|
||||
$description = $request->description ?? '';
|
||||
|
||||
$set = $this->setRepo->find($request->setId);
|
||||
if ($set === null) {
|
||||
|
|
@ -44,6 +45,7 @@ class CreateElement
|
|||
return $this->elementRepo->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: $request->title,
|
||||
description: $description,
|
||||
parentElement: null,
|
||||
));
|
||||
}
|
||||
|
|
@ -65,6 +67,7 @@ class CreateElement
|
|||
return $this->elementRepo->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: $request->title,
|
||||
description: $description,
|
||||
parentElement: $parentElement,
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class CreateElementRequest
|
|||
public function __construct(
|
||||
public ?int $setId,
|
||||
public ?string $title,
|
||||
public ?string $description,
|
||||
public ?int $parentElementId,
|
||||
) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('elements', function (Blueprint $table) {
|
||||
$table->text('description')->default('');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('elements', function (Blueprint $table) {
|
||||
$table->dropColumn('description');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -17,16 +17,20 @@ class ElementSeeder extends Seeder
|
|||
$rootElement = $elementRepository->create(new CreateElementDto(
|
||||
set: $baderechSet,
|
||||
title: $baderechSet->getName(),
|
||||
description: $baderechSet->getDescription(),
|
||||
parentElement: null,
|
||||
));
|
||||
$elementRepository->create(new CreateElementDto(
|
||||
set: $baderechSet,
|
||||
title: 'Avodah Foundations',
|
||||
description: 'Core foundations for building a steady '
|
||||
. 'avodah practice.',
|
||||
parentElement: $rootElement,
|
||||
));
|
||||
$elementRepository->create(new CreateElementDto(
|
||||
set: $baderechSet,
|
||||
title: 'Daily Practice',
|
||||
description: 'Practical steps for consistent daily growth.',
|
||||
parentElement: $rootElement,
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class FakeElementRepository implements ElementRepository
|
|||
$element = new Element(
|
||||
id: $id,
|
||||
title: $dto->title,
|
||||
description: $dto->description,
|
||||
set: $dto->set,
|
||||
parentElement: $dto->parentElement,
|
||||
);
|
||||
|
|
@ -95,6 +96,7 @@ class FakeElementRepository implements ElementRepository
|
|||
return new Element(
|
||||
id: $element->getId(),
|
||||
title: $element->getTitle(),
|
||||
description: $element->getDescription(),
|
||||
set: $element->getSet(),
|
||||
parentElement: $parentElement,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue