Skip to content

Commit

Permalink
Add ArticleRepository and ArticleController getAction
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jun 22, 2021
1 parent 8857c9f commit b832467
Show file tree
Hide file tree
Showing 16 changed files with 987 additions and 19 deletions.
63 changes: 63 additions & 0 deletions Domain/Exception/ArticleNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Sulu\Bundle\ArticleBundle\Domain\Exception;

use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;

class ArticleNotFoundException extends \Exception
{
/**
* @var string
*/
private $model;

/**
* @var mixed[]
*/
private $filters;

/**
* @param mixed[] $filters
*/
public function __construct(array $filters, int $code = 0, \Throwable $previous = null)
{
$this->model = ArticleInterface::class;

$criteriaMessages = [];
foreach ($filters as $key => $value) {
$value = new \stdClass();

if (\is_object($value)) {
$value = \get_debug_type($value);
} else {
$value = \json_encode($value);
}

$criteriaMessages[] = \sprintf('"%s" %s', $key, $value);
}

$message = \sprintf(
'Model "%s" with %s not found',
$this->model,
\implode(' and ', $criteriaMessages)
);

parent::__construct($message, $code, $previous);

$this->filters = $filters;
}

public function getModel(): string
{
return $this->model;
}

/**
* @return mixed[]
*/
public function getCriteria(): array
{
return $this->filters;
}

}
13 changes: 9 additions & 4 deletions Domain/Model/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ class Article implements ArticleInterface
/**
* @var string
*/
protected $id;
protected $uuid;

public function __construct(
?string $id = null
?string $uuid = null
) {
$this->id = $id ?: Uuid::uuid4()->toString();
$this->uuid = $uuid ?: Uuid::uuid4()->toString();
}

public function getId(): string
{
return $this->id;
return $this->uuid;
}

public function getUuid(): string
{
return $this->uuid;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions Domain/Model/ArticleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@

/**
* @experimental
*
* @method ArticleDimensionContentInterface createDimensionContent() see also
*/
interface ArticleInterface extends AuditableInterface, ContentRichEntityInterface
{
public const TEMPLATE_TYPE = 'article';
public const RESOURCE_KEY = 'article';

/**
* @internal
*/
public function getId(): string;

public function getUuid(): string;
}
89 changes: 89 additions & 0 deletions Domain/Repository/ArticleRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Sulu\Bundle\ArticleBundle\Domain\Repository;

use Sulu\Bundle\ArticleBundle\Domain\Exception\ArticleNotFoundException;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;

/**
* Implementation can be found in the following class:
*
* @see Sulu\Bundle\ArticleBundle\Infrastructure\Doctrine\Repository\ArticleRepository
*/
interface ArticleRepositoryInterface
{
public function createNew(?string $uuid = null): ArticleInterface;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* } $filters
*
* @param array{
* context?: string,
* } $options
*
* @throws ArticleNotFoundException
*/
public function getOneBy(array $filters, array $options = []): ArticleInterface;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* } $filters
*/
public function findOneBy(array $filters): ?ArticleInterface;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* categoryIds?: int[],
* categoryKeys?: int[],
* categoryOperator?: 'AND'|'OR',
* tagIds?: int[],
* tagNames?: string[],
* tagOperator?: 'AND'|'OR',
* templateKeys?: string[],
* page?: int,
* limit?: int,
* } $filters
*
* @param array{
* id?: 'asc'|'desc',
* title?: 'asc'|'desc',
* } $sortBy
*
* @return iterable<ArticleInterface>
*/
public function findBy(array $filters = [], array $sortBy = []): iterable;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* categoryIds?: int[],
* categoryKeys?: int[],
* categoryOperator?: 'AND'|'OR',
* tagIds?: int[],
* tagNames?: string[],
* tagOperator?: 'AND'|'OR',
* templateKeys?: string[],
* } $filters
*/
public function countBy(array $filters = []): int;

public function add(ArticleInterface $article): void;

public function remove(ArticleInterface $article): void;
}
Loading

0 comments on commit b832467

Please sign in to comment.