add element descriptions

This commit is contained in:
Yisroel Baum 2026-05-26 21:12:28 +03:00
parent f2dc1483dd
commit 72e4720787
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
10 changed files with 47 additions and 0 deletions

View file

@ -36,6 +36,7 @@ class ElementController
$childElements[] = [ $childElements[] = [
'id' => $childElement->getId(), 'id' => $childElement->getId(),
'title' => $childElement->getTitle(), 'title' => $childElement->getTitle(),
'description' => $childElement->getDescription(),
]; ];
} }
@ -44,6 +45,7 @@ class ElementController
'element' => [ 'element' => [
'id' => $element->getId(), 'id' => $element->getId(),
'title' => $element->getTitle(), 'title' => $element->getTitle(),
'description' => $element->getDescription(),
], ],
], 200); ], 200);
} }

View file

@ -9,6 +9,7 @@ class CreateElementDto
public function __construct( public function __construct(
public Set $set, public Set $set,
public string $title, public string $title,
public string $description,
public ?Element $parentElement, public ?Element $parentElement,
) { ) {
} }

View file

@ -9,6 +9,7 @@ class Element
public function __construct( public function __construct(
private int $id, private int $id,
private string $title, private string $title,
private string $description,
private Set $set, private Set $set,
private ?Element $parentElement, private ?Element $parentElement,
) { ) {
@ -24,6 +25,11 @@ class Element
return $this->title; return $this->title;
} }
public function getDescription(): string
{
return $this->description;
}
public function getSet(): Set public function getSet(): Set
{ {
return $this->set; return $this->set;

View file

@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id * @property int $id
* @property int $set_id * @property int $set_id
* @property string $title * @property string $title
* @property string $description
* @property int|null $parent_element_id * @property int|null $parent_element_id
* *
* @method static Builder<static>|ElementModel newModelQuery() * @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 whereParentElementId($value)
* @method static Builder<static>|ElementModel whereSetId($value) * @method static Builder<static>|ElementModel whereSetId($value)
* @method static Builder<static>|ElementModel whereTitle($value) * @method static Builder<static>|ElementModel whereTitle($value)
* @method static Builder<static>|ElementModel whereDescription($value)
* *
* @mixin \Eloquent * @mixin \Eloquent
*/ */
@ -30,6 +32,7 @@ class ElementModel extends Model
protected $fillable = [ protected $fillable = [
'set_id', 'set_id',
'title', 'title',
'description',
'parent_element_id', 'parent_element_id',
]; ];

View file

@ -17,12 +17,14 @@ class EloquentElementRepository implements ElementRepository
$model = ElementModel::create([ $model = ElementModel::create([
'set_id' => $dto->set->getId(), 'set_id' => $dto->set->getId(),
'title' => $dto->title, 'title' => $dto->title,
'description' => $dto->description,
'parent_element_id' => $dto->parentElement?->getId(), 'parent_element_id' => $dto->parentElement?->getId(),
]); ]);
return new Element( return new Element(
id: $model->id, id: $model->id,
title: $dto->title, title: $dto->title,
description: $dto->description,
set: $dto->set, set: $dto->set,
parentElement: $dto->parentElement, parentElement: $dto->parentElement,
); );
@ -102,6 +104,7 @@ class EloquentElementRepository implements ElementRepository
return new Element( return new Element(
id: $model->id, id: $model->id,
title: $model->title, title: $model->title,
description: $model->description,
set: $set, set: $set,
parentElement: $parentElement, parentElement: $parentElement,
); );

View file

@ -30,6 +30,7 @@ class CreateElement
if ($request->title === null || $request->title === '') { if ($request->title === null || $request->title === '') {
throw new BadRequestException('title is required'); throw new BadRequestException('title is required');
} }
$description = $request->description ?? '';
$set = $this->setRepo->find($request->setId); $set = $this->setRepo->find($request->setId);
if ($set === null) { if ($set === null) {
@ -44,6 +45,7 @@ class CreateElement
return $this->elementRepo->create(new CreateElementDto( return $this->elementRepo->create(new CreateElementDto(
set: $set, set: $set,
title: $request->title, title: $request->title,
description: $description,
parentElement: null, parentElement: null,
)); ));
} }
@ -65,6 +67,7 @@ class CreateElement
return $this->elementRepo->create(new CreateElementDto( return $this->elementRepo->create(new CreateElementDto(
set: $set, set: $set,
title: $request->title, title: $request->title,
description: $description,
parentElement: $parentElement, parentElement: $parentElement,
)); ));
} }

View file

@ -7,6 +7,7 @@ class CreateElementRequest
public function __construct( public function __construct(
public ?int $setId, public ?int $setId,
public ?string $title, public ?string $title,
public ?string $description,
public ?int $parentElementId, public ?int $parentElementId,
) { ) {
} }

View file

@ -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');
});
}
};

View file

@ -17,16 +17,20 @@ class ElementSeeder extends Seeder
$rootElement = $elementRepository->create(new CreateElementDto( $rootElement = $elementRepository->create(new CreateElementDto(
set: $baderechSet, set: $baderechSet,
title: $baderechSet->getName(), title: $baderechSet->getName(),
description: $baderechSet->getDescription(),
parentElement: null, parentElement: null,
)); ));
$elementRepository->create(new CreateElementDto( $elementRepository->create(new CreateElementDto(
set: $baderechSet, set: $baderechSet,
title: 'Avodah Foundations', title: 'Avodah Foundations',
description: 'Core foundations for building a steady '
. 'avodah practice.',
parentElement: $rootElement, parentElement: $rootElement,
)); ));
$elementRepository->create(new CreateElementDto( $elementRepository->create(new CreateElementDto(
set: $baderechSet, set: $baderechSet,
title: 'Daily Practice', title: 'Daily Practice',
description: 'Practical steps for consistent daily growth.',
parentElement: $rootElement, parentElement: $rootElement,
)); ));
} }

View file

@ -20,6 +20,7 @@ class FakeElementRepository implements ElementRepository
$element = new Element( $element = new Element(
id: $id, id: $id,
title: $dto->title, title: $dto->title,
description: $dto->description,
set: $dto->set, set: $dto->set,
parentElement: $dto->parentElement, parentElement: $dto->parentElement,
); );
@ -95,6 +96,7 @@ class FakeElementRepository implements ElementRepository
return new Element( return new Element(
id: $element->getId(), id: $element->getId(),
title: $element->getTitle(), title: $element->getTitle(),
description: $element->getDescription(),
set: $element->getSet(), set: $element->getSet(),
parentElement: $parentElement, parentElement: $parentElement,
); );