Skip to content

Commit

Permalink
feat: Expose WebResponse optional maxAge and populate with Node's T…
Browse files Browse the repository at this point in the history
…TL when available
  • Loading branch information
ambroisemaupate committed Mar 20, 2024
1 parent 3c9eda6 commit 1a020de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function transform(PersistableInterface $object, string $to, array $conte
], UrlGeneratorInterface::ABSOLUTE_PATH));
$output->setHead($this->nodesSourcesHeadFactory->createForNodeSource($object));
$output->setBreadcrumbs($this->breadcrumbsFactory->create($object));
$output->setMaxAge($object->getNode()->getTtl() * 60);
}
if ($object instanceof TranslationInterface) {
$output->setHead($this->nodesSourcesHeadFactory->createForTranslation($object));
Expand Down
2 changes: 2 additions & 0 deletions lib/RoadizCoreBundle/src/Api/Model/WebResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public function setBreadcrumbs(?BreadcrumbsInterface $breadcrumbs): self;
public function setItem(?PersistableInterface $item): self;
public function setPath(?string $path): self;
public function getItem(): ?PersistableInterface;
public function getMaxAge(): ?int;
public function setMaxAge(?int $maxAge): self;
}
17 changes: 17 additions & 0 deletions lib/RoadizCoreBundle/src/Api/Model/WebResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ trait WebResponseTrait
#[Serializer\Groups(["web_response"])]
private bool $hidingBlocks = false;

/**
* @var int|null WebResponse item maximum age in seconds
*/
#[Serializer\Groups(["web_response"])]
private ?int $maxAge = null;

public function getMaxAge(): ?int
{
return $this->maxAge;
}

public function setMaxAge(?int $maxAge): self
{
$this->maxAge = $maxAge;
return $this;
}

public function setPath(?string $path): self
{
$this->path = $path;
Expand Down

0 comments on commit 1a020de

Please sign in to comment.