Files
Mangarr/src/Domain/Manga/Infrastructure/ApiPlatform/Resource/EditMangaResource.php

56 lines
2.3 KiB
PHP

<?php
namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Put;
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\EditMangaProcessor;
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider\GetMangaStateProvider;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
shortName: 'Manga',
operations: [
new Put(
uriTemplate: '/mangas/{id}/edit',
processor: EditMangaProcessor::class,
provider: GetMangaStateProvider::class,
openapiContext: [
'summary' => 'Edit an existing manga',
'description' => 'Updates an existing manga with provided data (partial update supported)'
]
)
]
)]
class EditMangaResource
{
#[Assert\Length(min: 1, max: 255, minMessage: 'Le titre doit contenir au moins {{ limit }} caractère', maxMessage: 'Le titre ne peut pas dépasser {{ limit }} caractères')]
public ?string $title = null;
public ?string $description = null;
public ?string $author = null;
#[Assert\Type(type: 'integer', message: 'L\'année de publication doit être un nombre entier')]
#[Assert\Range(min: 1900, max: 2100, notInRangeMessage: 'L\'année de publication doit être comprise entre {{ min }} et {{ max }}')]
public ?int $publicationYear = null;
#[Assert\Type(type: 'array', message: 'Les genres doivent être une liste')]
#[Assert\Count(min: 1, minMessage: 'Vous devez spécifier au moins un genre')]
public ?array $genres = null;
#[Assert\Choice(choices: ['ongoing', 'completed', 'hiatus'], message: 'Le statut doit être l\'un des suivants : ongoing, completed, hiatus')]
public ?string $status = null;
#[Assert\Type(type: 'float', message: 'La note doit être un nombre décimal')]
#[Assert\Range(min: 0, max: 10, notInRangeMessage: 'La note doit être comprise entre {{ min }} et {{ max }}')]
public ?float $rating = null;
#[Assert\Type(type: 'array', message: 'Les slugs alternatifs doivent être une liste')]
#[Assert\All([
new Assert\Type('string'),
new Assert\Regex(pattern: '/^[a-z0-9-]+$/', message: 'Chaque slug alternatif ne peut contenir que des lettres minuscules, des chiffres et des tirets')
])]
public ?array $alternativeSlugs = null;
}