<?php
namespace App\Domain\Entity\Comment;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use App\Application\Controller\Api\Comment\TranslateCommentAction;
use App\Domain\Entity\Comment;
use App\Domain\Entity\Locale;
use App\Domain\Entity\Person;
use App\Domain\Entity\PointOfInterest;
use DateTime;
/**
* Class Comment
*
* @package App\Domain\Entity
*/
#[ApiResource(
operations: [
new GetCollection(
filters: [
'comment.search_filter',
'comment.exists_filter',
'soft_delete_filter',
'comment.order_filter',
'comment.null_filter',
],
),
new GetCollection(
uriTemplate: '/point_of_interest_comments/list',
filters: [
'comment.search_filter',
'comment.exists_filter',
'soft_delete_filter',
'comment.order_filter',
'comment.null_filter',
],
normalizationContext: ['groups' => ['comment_read_list']],
),
new Get(
uriTemplate: '/point_of_interest_comments/{uuid}/translation',
controller: TranslateCommentAction::class,
name: 'translate',
)
],
normalizationContext: ['groups' => ['comment_read']],
denormalizationContext: ['groups' => ['comment_write']],
filters: ['translation.groups'],
order: ['createdAt' => 'DESC'],
)]
#[ApiResource(
uriTemplate: '/point_of_interests/{uuid}/comments',
operations: [
new GetCollection(
filters: [
'comment.search_filter',
'comment.exists_filter',
'soft_delete_filter',
'comment.order_filter',
'comment.null_filter',
],
),
],
uriVariables: [
'uuid' => new Link(toProperty: 'pointOfInterest', fromClass: PointOfInterest::class),
],
normalizationContext: ['groups' => ['comment_read']],
denormalizationContext: ['groups' => ['comment_write']],
filters: ['translation.groups'],
order: ['createdAt' => 'DESC'],
)]
class PointOfInterestComment extends Comment
{
/**
* @param Person $author
* @param PointOfInterest $pointOfInterest
* @param Locale|null $authorLocale
* @param string $status
* @param int $notation
* @param Comment|null $parent
* @param DateTime|null $zhistUpdate
*/
public function __construct(
public Person $author,
public PointOfInterest $pointOfInterest,
public Locale | null $authorLocale = null,
public string $status = self::COMMENT_NEW,
public int $notation = 0,
public Comment | null $parent = null,
public ?DateTime $zhistUpdate = null,
public ?DateTime $lastUserUpdate = null,
) {
parent::__construct(
author: $author,
authorLocale: $authorLocale,
status: $status,
notation: $notation,
parent: $parent,
zhistUpdate: $zhistUpdate,
lastUserUpdate: $lastUserUpdate,
);
}
}