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 Oct 5, 2021
1 parent 8857c9f commit 889e235
Show file tree
Hide file tree
Showing 16 changed files with 1,033 additions and 20 deletions.
61 changes: 61 additions & 0 deletions Domain/Exception/ArticleNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Sulu\Bundle\ArticleBundle\Domain\Exception;

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

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

/**
* @param array<string, mixed> $filters
*/
private $filters;

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

$criteriaMessages = [];
foreach ($filters as $key => $value) {
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 getFilters(): 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;
}
103 changes: 103 additions & 0 deletions Domain/Repository/ArticleRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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{
* article_admin?: bool,
* article_website?: bool,
* with-article-content?: bool|array<string, mixed>,
* }|array<string, mixed> $selects
*
* @throws ArticleNotFoundException
*/
public function getOneBy(array $filters, array $selects = []): ArticleInterface;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* } $filters
*
* @param array{
* article_admin?: bool,
* article_website?: bool,
* with-article-content?: bool|array<string, mixed>,
* }|array<string, mixed> $selects
*/
public function findOneBy(array $filters, array $selects = []): ?ArticleInterface;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* categoryIds?: int[],
* categoryKeys?: string[],
* 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
*
* @param array{
* article_admin?: bool,
* article_website?: bool,
* with-article-content?: bool|array<string, mixed>,
* }|array<string, mixed> $selects
*
* @return iterable<ArticleInterface>
*/
public function findBy(array $filters = [], array $sortBy = [], array $selects = []): iterable;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* categoryIds?: int[],
* categoryKeys?: string[],
* 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 889e235

Please sign in to comment.