Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.0.0 #12

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@ APP_SECRET=01324d73757787ffeba5f2f76cec1a28
APP_PATH_PREFIX=/api/v2

# Must be valid json, usernames and apikeys must be unique
# APP_API_KEYS='[{"username": "user1", "apikey": "api_key_1"}, {"username": "user2", "apikey": "api_key_2"}]'
# APP_API_KEYS='[{"username": "user_1", "apikey": "api_key_1"}, {"username": "user_2", "apikey": "api_key_2"}]'
APP_API_KEYS=[]
###< app ###

###> api-platform/core ###
PAGINATION_ITEMS_PER_PAGE=20
PAGINATION_MAXIMUM_ITEMS_PER_PAGE=50
###< api-platform/core ###

###> INDEX ###
INDEX_URL=http://elasticsearch:9200
INDEX_EVENTS_ALIAS=events
INDEX_ORGANIZATION_ALIAS=organization
###< INDEX ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=15&charset=utf8"
###< doctrine/doctrine-bundle ###

###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
CORS_ALLOW_ORIGIN='*'
###< nelmio/cors-bundle ###
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ See [keep a changelog] for information about writing changes to this log.

## [Unreleased]

## [1.0.0] - 2024-09-11

### Added

- Symfony core.
Expand Down
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^3.2",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^2.17",
"elasticsearch/elasticsearch": "^8.13",
"nelmio/cors-bundle": "^2.4",
"phpdocumentor/reflection-docblock": "^5.3",
Expand Down
8,237 changes: 3,922 additions & 4,315 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Expand Down
5 changes: 3 additions & 2 deletions config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ api_platform:
type: header

elasticsearch:
hosts: ['%env(INDEXING_URL)%']
hosts: ['%env(INDEX_URL)%']

defaults:
stateless: true
pagination_maximum_items_per_page: 20
pagination_items_per_page: '%env(int:PAGINATION_ITEMS_PER_PAGE)%'
pagination_maximum_items_per_page: '%env(int:PAGINATION_MAXIMUM_ITEMS_PER_PAGE)%'
cache_headers:
max_age: 3600
shared_max_age: 3600
Expand Down
49 changes: 0 additions & 49 deletions config/packages/doctrine.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions config/packages/doctrine_migrations.yaml

This file was deleted.

Empty file removed migrations/.gitignore
Empty file.
7 changes: 5 additions & 2 deletions src/Api/Filter/ElasticSearch/IdFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ final class IdFilter extends AbstractFilter
public function apply(array $clauseBody, string $resourceClass, ?Operation $operation = null, array $context = []): array
{
$properties = $this->getProperties($resourceClass);
$terms = [];
$result = [];

/** @var string $property */
foreach ($properties as $property) {
if (empty($context['filters'][$property])) {
// If no value or empty value is set, skip it.
continue;
}
$terms = [];
$terms[$property] = explode(',', $context['filters'][$property]);
$terms['boost'] = 1.0;
$result[]['terms'] = $terms;
}

return empty($terms) ? $terms : ['terms' => $terms + ['boost' => 1.0]];
return $result;
}

public function getDescription(string $resourceClass): array
Expand Down
13 changes: 9 additions & 4 deletions src/Api/State/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ApiPlatform\Elasticsearch\Filter\FilterInterface;
use ApiPlatform\Elasticsearch\Filter\SortFilterInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\Pagination\PaginationOptions;
use App\Model\FilterTypes;
use App\Model\IndexNames;
use App\Service\IndexInterface;
Expand All @@ -15,11 +16,12 @@
*/
abstract class AbstractProvider
{
protected const PAGE_SIZE_FALLBACK = 10;
protected const int MAX_PAGE_SIZE_FALLBACK = 20;

public function __construct(
protected readonly IndexInterface $index,
protected readonly ContainerInterface $filterLocator,
protected readonly PaginationOptions $paginationOptions,
) {
}

Expand Down Expand Up @@ -77,7 +79,7 @@ protected function getFilters(Operation $operation, array $context = []): array
*/
protected function calculatePageOffset(array $context): int
{
return (($context['filters']['page'] ?? 1) - 1) * $this->getImagesPerPage($context);
return (($context['filters']['page'] ?? 1) - 1) * $this->getItemsPerPage($context);
}

/**
Expand All @@ -89,9 +91,12 @@ protected function calculatePageOffset(array $context): int
* @return int
* The number of items per page as determined by the context
*/
protected function getImagesPerPage(array $context): int
protected function getItemsPerPage(array $context): int
{
return $context['filters']['itemsPerPage'] ?? self::PAGE_SIZE_FALLBACK;
$itemsPerPage = $context['filters']['itemsPerPage'] ?? $this->paginationOptions->getItemsPerPage();
$maxItemsPerPage = $this->paginationOptions->getMaximumItemsPerPage() ?? self::MAX_PAGE_SIZE_FALLBACK;

return min($itemsPerPage, $maxItemsPerPage);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Api/State/DailyOccurrenceRepresentationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if ($operation instanceof CollectionOperationInterface) {
$filters = $this->getFilters($operation, $context);
$offset = $this->calculatePageOffset($context);
$limit = $this->getImagesPerPage($context);
$limit = $this->getItemsPerPage($context);
$results = $this->index->getAll(IndexNames::DailyOccurrences->value, $filters, $offset, $limit);

return new ElasticSearchPaginator($results, $limit, $offset);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/State/EventRepresentationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if ($operation instanceof CollectionOperationInterface) {
$filters = $this->getFilters($operation, $context);
$offset = $this->calculatePageOffset($context);
$limit = $this->getImagesPerPage($context);
$limit = $this->getItemsPerPage($context);
$results = $this->index->getAll(IndexNames::Events->value, $filters, $offset, $limit);

return new ElasticSearchPaginator($results, $limit, $offset);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/State/LocationRepresentationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if ($operation instanceof CollectionOperationInterface) {
$filters = $this->getFilters($operation, $context);
$offset = $this->calculatePageOffset($context);
$limit = $this->getImagesPerPage($context);
$limit = $this->getItemsPerPage($context);
$results = $this->index->getAll(IndexNames::Locations->value, $filters, $offset, $limit);

return new ElasticSearchPaginator($results, $limit, $offset);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/State/OccurrenceRepresentationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if ($operation instanceof CollectionOperationInterface) {
$filters = $this->getFilters($operation, $context);
$offset = $this->calculatePageOffset($context);
$limit = $this->getImagesPerPage($context);
$limit = $this->getItemsPerPage($context);
$results = $this->index->getAll(IndexNames::Occurrences->value, $filters, $offset, $limit);

return new ElasticSearchPaginator($results, $limit, $offset);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/State/OrganizationRepresentationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if ($operation instanceof CollectionOperationInterface) {
$filters = $this->getFilters($operation, $context);
$offset = $this->calculatePageOffset($context);
$limit = $this->getImagesPerPage($context);
$limit = $this->getItemsPerPage($context);
$results = $this->index->getAll(IndexNames::Organizations->value, $filters, $offset, $limit);

return new ElasticSearchPaginator($results, $limit, $offset);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/State/TagRepresentationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if ($operation instanceof CollectionOperationInterface) {
$filters = $this->getFilters($operation, $context);
$offset = $this->calculatePageOffset($context);
$limit = $this->getImagesPerPage($context);
$limit = $this->getItemsPerPage($context);
$results = $this->index->getAll(IndexNames::Tags->value, $filters, $offset, $limit);

$tags = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Api/State/VocabularyRepresentationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if ($operation instanceof CollectionOperationInterface) {
$filters = $this->getFilters($operation, $context);
$offset = $this->calculatePageOffset($context);
$limit = $this->getImagesPerPage($context);
$limit = $this->getItemsPerPage($context);
$results = $this->index->getAll(IndexNames::Vocabularies->value, $filters, $offset, $limit);

$vocabularies = [];
Expand Down
Empty file removed src/Entity/.gitignore
Empty file.
Empty file removed src/Repository/.gitignore
Empty file.
8 changes: 4 additions & 4 deletions src/Service/ElasticSearch/ElasticSearchPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
/**
* Paginator for Elasticsearch.
*/
final class ElasticSearchPaginator implements \IteratorAggregate, PaginatorInterface
final readonly class ElasticSearchPaginator implements \IteratorAggregate, PaginatorInterface
{
public function __construct(
private readonly SearchResults $results,
private readonly int $limit,
private readonly int $offset,
private SearchResults $results,
private int $limit,
private int $offset,
) {
}

Expand Down
27 changes: 0 additions & 27 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,6 @@
"src/ApiResource/.gitignore"
]
},
"doctrine/doctrine-bundle": {
"version": "2.11",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.10",
"ref": "0db4b12b5df45f5122213b4ecd18733ab7fa7d53"
},
"files": [
"config/packages/doctrine.yaml",
"src/Entity/.gitignore",
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "3.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.1",
"ref": "1d01ec03c6ecbd67c3375c5478c9a423ae5d6a33"
},
"files": [
"config/packages/doctrine_migrations.yaml",
"migrations/.gitignore"
]
},
"friendsofphp/php-cs-fixer": {
"version": "3.40",
"recipe": {
Expand Down
Loading