add set media fields
This commit is contained in:
parent
1ce7688d33
commit
fa8efd765f
10 changed files with 61 additions and 21 deletions
|
|
@ -25,13 +25,20 @@ class SetController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{id: int, name: string}
|
* @return array{
|
||||||
|
* id: int,
|
||||||
|
* name: string,
|
||||||
|
* description: string,
|
||||||
|
* iconImageUrl: string
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
private function buildSetPayload(DomainSet $set): array
|
private function buildSetPayload(DomainSet $set): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $set->getId(),
|
'id' => $set->getId(),
|
||||||
'name' => $set->getName(),
|
'name' => $set->getName(),
|
||||||
|
'description' => $set->getDescription(),
|
||||||
|
'iconImageUrl' => $set->getIconImageUrl(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ class CreateSetDto
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $name,
|
public string $name,
|
||||||
|
public string $description,
|
||||||
|
public string $iconImageUrl,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ class EloquentSetRepository implements SetRepository
|
||||||
{
|
{
|
||||||
$model = SetModel::create([
|
$model = SetModel::create([
|
||||||
'name' => $dto->name,
|
'name' => $dto->name,
|
||||||
|
'description' => $dto->description,
|
||||||
|
'icon_image_url' => $dto->iconImageUrl,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->toDomain($model);
|
return $this->toDomain($model);
|
||||||
|
|
@ -36,6 +38,8 @@ class EloquentSetRepository implements SetRepository
|
||||||
return new Set(
|
return new Set(
|
||||||
id: $model->id,
|
id: $model->id,
|
||||||
name: $model->name,
|
name: $model->name,
|
||||||
|
description: $model->description,
|
||||||
|
iconImageUrl: $model->icon_image_url,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ class Set
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private int $id,
|
private int $id,
|
||||||
private string $name,
|
private string $name,
|
||||||
|
private string $description,
|
||||||
|
private string $iconImageUrl,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,4 +21,14 @@ class Set
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIconImageUrl(): string
|
||||||
|
{
|
||||||
|
return $this->iconImageUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
|
* @property string $description
|
||||||
|
* @property string $icon_image_url
|
||||||
*
|
*
|
||||||
* @method static Builder<static>|SetModel newModelQuery()
|
* @method static Builder<static>|SetModel newModelQuery()
|
||||||
* @method static Builder<static>|SetModel newQuery()
|
* @method static Builder<static>|SetModel newQuery()
|
||||||
|
|
@ -23,5 +25,5 @@ class SetModel extends Model
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
protected $fillable = ['name'];
|
protected $fillable = ['name', 'description', 'icon_image_url'];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ return new class extends Migration
|
||||||
Schema::create('sets', function (Blueprint $table) {
|
Schema::create('sets', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
|
$table->text('description');
|
||||||
|
$table->string('icon_image_url');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ class SetSeeder extends Seeder
|
||||||
|
|
||||||
$set = $setRepository->create(new CreateSetDto(
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
name: $title,
|
name: $title,
|
||||||
|
description: 'Baderech HaAvodah is a way of living - '
|
||||||
|
. 'a structured path for inner and outer growth, '
|
||||||
|
. 'spiritual refinement, and personal development.',
|
||||||
|
iconImageUrl: '/assets/baderech-haavodah-icon.svg',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ class FakeSetRepository implements SetRepository
|
||||||
$set = new DomainSet(
|
$set = new DomainSet(
|
||||||
id: $id,
|
id: $id,
|
||||||
name: $dto->name,
|
name: $dto->name,
|
||||||
|
description: $dto->description,
|
||||||
|
iconImageUrl: $dto->iconImageUrl,
|
||||||
);
|
);
|
||||||
$this->setsById[$id] = $set;
|
$this->setsById[$id] = $set;
|
||||||
|
|
||||||
|
|
@ -52,6 +54,8 @@ class FakeSetRepository implements SetRepository
|
||||||
return new DomainSet(
|
return new DomainSet(
|
||||||
id: $set->getId(),
|
id: $set->getId(),
|
||||||
name: $set->getName(),
|
name: $set->getName(),
|
||||||
|
description: $set->getDescription(),
|
||||||
|
iconImageUrl: $set->getIconImageUrl(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,12 @@ class ElementTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testCreatesElementWithNullableParent(): void
|
public function testCreatesElementWithNullableParent(): void
|
||||||
{
|
{
|
||||||
$set = new DomainSet(1, 'Daily learning');
|
$set = new DomainSet(
|
||||||
|
id: 1,
|
||||||
|
name: 'Daily learning',
|
||||||
|
description: 'Daily learning description',
|
||||||
|
iconImageUrl: '/assets/daily-learning-icon.svg',
|
||||||
|
);
|
||||||
$rootElement = new Element(
|
$rootElement = new Element(
|
||||||
id: 1,
|
id: 1,
|
||||||
title: 'Root',
|
title: 'Root',
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use App\Element\UseCases\CreateElement\CreateElement;
|
||||||
use App\Element\UseCases\CreateElement\CreateElementRequest;
|
use App\Element\UseCases\CreateElement\CreateElementRequest;
|
||||||
use App\Exceptions\BadRequestException;
|
use App\Exceptions\BadRequestException;
|
||||||
use App\Set\CreateSetDto;
|
use App\Set\CreateSetDto;
|
||||||
|
use App\Set\Set as DomainSet;
|
||||||
use DomainException;
|
use DomainException;
|
||||||
use Tests\Fakes\FakeElementRepository;
|
use Tests\Fakes\FakeElementRepository;
|
||||||
use Tests\Fakes\FakeSetRepository;
|
use Tests\Fakes\FakeSetRepository;
|
||||||
|
|
@ -30,11 +31,18 @@ class CreateElementTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createSet(string $name): DomainSet
|
||||||
|
{
|
||||||
|
return $this->setRepo->create(new CreateSetDto(
|
||||||
|
name: $name,
|
||||||
|
description: "$name description",
|
||||||
|
iconImageUrl: '/assets/test-set-icon.svg',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreatesRootElement(): void
|
public function testCreatesRootElement(): void
|
||||||
{
|
{
|
||||||
$set = $this->setRepo->create(
|
$set = $this->createSet('Daily learning');
|
||||||
new CreateSetDto('Daily learning')
|
|
||||||
);
|
|
||||||
|
|
||||||
$element = $this->createElement->execute(new CreateElementRequest(
|
$element = $this->createElement->execute(new CreateElementRequest(
|
||||||
setId: $set->getId(),
|
setId: $set->getId(),
|
||||||
|
|
@ -50,9 +58,7 @@ class CreateElementTest extends TestCase
|
||||||
|
|
||||||
public function testCreatesChildElement(): void
|
public function testCreatesChildElement(): void
|
||||||
{
|
{
|
||||||
$set = $this->setRepo->create(
|
$set = $this->createSet('Daily learning');
|
||||||
new CreateSetDto('Daily learning')
|
|
||||||
);
|
|
||||||
$rootElement = $this->createElement->execute(
|
$rootElement = $this->createElement->execute(
|
||||||
new CreateElementRequest(
|
new CreateElementRequest(
|
||||||
setId: $set->getId(),
|
setId: $set->getId(),
|
||||||
|
|
@ -114,9 +120,7 @@ class CreateElementTest extends TestCase
|
||||||
|
|
||||||
public function testThrowsWhenParentElementDoesNotExist(): void
|
public function testThrowsWhenParentElementDoesNotExist(): void
|
||||||
{
|
{
|
||||||
$set = $this->setRepo->create(
|
$set = $this->createSet('Daily learning');
|
||||||
new CreateSetDto('Daily learning')
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->expectException(DomainException::class);
|
$this->expectException(DomainException::class);
|
||||||
$this->expectExceptionMessage(
|
$this->expectExceptionMessage(
|
||||||
|
|
@ -132,9 +136,7 @@ class CreateElementTest extends TestCase
|
||||||
|
|
||||||
public function testThrowsWhenRootElementAlreadyExists(): void
|
public function testThrowsWhenRootElementAlreadyExists(): void
|
||||||
{
|
{
|
||||||
$set = $this->setRepo->create(
|
$set = $this->createSet('Daily learning');
|
||||||
new CreateSetDto('Daily learning')
|
|
||||||
);
|
|
||||||
$this->createElement->execute(new CreateElementRequest(
|
$this->createElement->execute(new CreateElementRequest(
|
||||||
setId: $set->getId(),
|
setId: $set->getId(),
|
||||||
title: 'Root',
|
title: 'Root',
|
||||||
|
|
@ -155,12 +157,8 @@ class CreateElementTest extends TestCase
|
||||||
|
|
||||||
public function testThrowsWhenParentBelongsToAnotherSet(): void
|
public function testThrowsWhenParentBelongsToAnotherSet(): void
|
||||||
{
|
{
|
||||||
$parentSet = $this->setRepo->create(
|
$parentSet = $this->createSet('Parent set');
|
||||||
new CreateSetDto('Parent set')
|
$childSet = $this->createSet('Child set');
|
||||||
);
|
|
||||||
$childSet = $this->setRepo->create(
|
|
||||||
new CreateSetDto('Child set')
|
|
||||||
);
|
|
||||||
$parentElement = $this->createElement->execute(
|
$parentElement = $this->createElement->execute(
|
||||||
new CreateElementRequest(
|
new CreateElementRequest(
|
||||||
setId: $parentSet->getId(),
|
setId: $parentSet->getId(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue