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[] = [
'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);
}

View file

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

View file

@ -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;

View file

@ -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',
];

View file

@ -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,
);

View file

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

View file

@ -7,6 +7,7 @@ class CreateElementRequest
public function __construct(
public ?int $setId,
public ?string $title,
public ?string $description,
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(
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,
));
}

View file

@ -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,
);