feat: ajout d'une modale de gestion des chapitres, permettant la création, l'édition et le déplacement de chapitres. Mise à jour de l'API pour gérer les modifications en lot des chapitres, ainsi que l'intégration de tests pour valider cette nouvelle fonctionnalité. Amélioration de l'interface utilisateur pour une gestion plus fluide des chapitres.
This commit is contained in:
parent
00d63dffeb
commit
551db0bf77
12
src/Domain/Manga/Application/Command/ChapterEditData.php
Normal file
12
src/Domain/Manga/Application/Command/ChapterEditData.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Command;
|
||||
|
||||
readonly class ChapterEditData
|
||||
{
|
||||
public function __construct(
|
||||
public string $id,
|
||||
public ?string $title = null,
|
||||
public ?int $volume = null
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Command;
|
||||
|
||||
readonly class EditMultipleChapters
|
||||
{
|
||||
/**
|
||||
* @param array<ChapterEditData> $chapters
|
||||
*/
|
||||
public function __construct(
|
||||
public array $chapters
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\CommandHandler;
|
||||
|
||||
use App\Domain\Manga\Application\Command\EditMultipleChapters;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
|
||||
|
||||
readonly class EditMultipleChaptersHandler
|
||||
{
|
||||
public function __construct(
|
||||
private ChapterRepositoryInterface $chapterRepository
|
||||
) {}
|
||||
|
||||
public function handle(EditMultipleChapters $command): void
|
||||
{
|
||||
foreach ($command->chapters as $chapterData) {
|
||||
$chapter = $this->chapterRepository->findById($chapterData->id);
|
||||
|
||||
if (!$chapter) {
|
||||
throw new ChapterNotFoundException($chapterData->id);
|
||||
}
|
||||
|
||||
$updatedChapter = $chapter;
|
||||
|
||||
if ($chapterData->title !== null) {
|
||||
$updatedChapter = $updatedChapter->updateTitle($chapterData->title);
|
||||
}
|
||||
|
||||
if ($chapterData->volume !== null) {
|
||||
$updatedChapter = $updatedChapter->updateVolume($chapterData->volume);
|
||||
}
|
||||
|
||||
$this->chapterRepository->save($updatedChapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user