Skip to content

Commit

Permalink
Merge pull request #11 from itk-dev/feature/1339_API_multi_value_filt…
Browse files Browse the repository at this point in the history
…ering

1339: Added multi-value filtering for Lactions and Organizations
  • Loading branch information
turegjorup authored May 8, 2024
2 parents 25464d8 + 0ebe6b9 commit 346b16d
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ See [keep a changelog] for information about writing changes to this log.
- Update composer dependencies
- Added api-key auth
- Added PethPrefix scope to traefik rules to allow co-hosting with legacy eventdb
- Added multi-value filtering for Lactions and Organizations

[keep a changelog]: https://keepachangelog.com/en/1.1.0/
[unreleased]: https://github.com/itk-dev/event-database-imports/compare/main...develop
84 changes: 42 additions & 42 deletions public/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ paths:
explode: false
allowReserved: false
-
name: event.organizer.entityId
name: event.location.name
in: query
description: 'Search field based on value given'
required: false
Expand All @@ -95,27 +95,31 @@ paths:
explode: false
allowReserved: false
-
name: event.location.name
name: event.organizer.entityId
in: query
description: 'Search field based on value given'
description: 'Filter based on given entity ids'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: string
style: form
type: array
items:
type: string
style: deepObject
explode: false
allowReserved: false
-
name: event.location.entityId
in: query
description: 'Search field based on value given'
description: 'Filter based on given entity ids'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: string
style: form
type: array
items:
type: string
style: deepObject
explode: false
allowReserved: false
-
Expand Down Expand Up @@ -147,7 +151,7 @@ paths:
-
name: start
in: query
description: 'Filter base on date (greater then or equal to)'
description: 'Filter base on ISO 8601 datetime (yyyy-MM-dd''T''HH:mm:ssz), e.g. "2004-02-12T15:19:21+00:00" (greater then or equal to)'
required: false
deprecated: false
allowEmptyValue: true
Expand All @@ -159,7 +163,7 @@ paths:
-
name: end
in: query
description: 'Filter base on date (less then or equal to)'
description: 'Filter base on ISO 8601 datetime (yyyy-MM-dd''T''HH:mm:ssz), e.g. "2004-02-12T15:19:21+00:00" (less then or equal to)'
required: false
deprecated: false
allowEmptyValue: true
Expand Down Expand Up @@ -272,7 +276,7 @@ paths:
explode: false
allowReserved: false
-
name: organizer.entityId
name: location.name
in: query
description: 'Search field based on value given'
required: false
Expand All @@ -284,27 +288,31 @@ paths:
explode: false
allowReserved: false
-
name: location.name
name: organizer.entityId
in: query
description: 'Search field based on value given'
description: 'Filter based on given entity ids'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: string
style: form
type: array
items:
type: string
style: deepObject
explode: false
allowReserved: false
-
name: location.entityId
in: query
description: 'Search field based on value given'
description: 'Filter based on given entity ids'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: string
style: form
type: array
items:
type: string
style: deepObject
explode: false
allowReserved: false
-
Expand Down Expand Up @@ -336,7 +344,7 @@ paths:
-
name: occurrences.start
in: query
description: 'Filter base on date (greater then or equal to)'
description: 'Filter base on ISO 8601 datetime (yyyy-MM-dd''T''HH:mm:ssz), e.g. "2004-02-12T15:19:21+00:00" (greater then or equal to)'
required: false
deprecated: false
allowEmptyValue: true
Expand All @@ -348,7 +356,7 @@ paths:
-
name: occurrences.end
in: query
description: 'Filter base on date (less then or equal to)'
description: 'Filter base on ISO 8601 datetime (yyyy-MM-dd''T''HH:mm:ssz), e.g. "2004-02-12T15:19:21+00:00" (less then or equal to)'
required: false
deprecated: false
allowEmptyValue: true
Expand Down Expand Up @@ -563,18 +571,6 @@ paths:
style: form
explode: false
allowReserved: false
-
name: event.organizer.entityId
in: query
description: 'Search field based on value given'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: string
style: form
explode: false
allowReserved: false
-
name: event.location.name
in: query
Expand All @@ -588,27 +584,31 @@ paths:
explode: false
allowReserved: false
-
name: event.location.entityId
name: event.organizer.entityId
in: query
description: 'Search field based on value given'
description: 'Filter based on given entity ids'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: string
style: form
type: array
items:
type: string
style: deepObject
explode: false
allowReserved: false
-
name: event.publicAccess
name: event.location.entityId
in: query
description: 'Is this a public event'
description: 'Filter based on given entity ids'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: boolean
style: form
type: array
items:
type: string
style: deepObject
explode: false
allowReserved: false
-
Expand All @@ -628,7 +628,7 @@ paths:
-
name: start
in: query
description: 'Filter base on date (greater then or equal to)'
description: 'Filter base on ISO 8601 datetime (yyyy-MM-dd''T''HH:mm:ssz), e.g. "2004-02-12T15:19:21+00:00" (greater then or equal to)'
required: false
deprecated: false
allowEmptyValue: true
Expand All @@ -640,7 +640,7 @@ paths:
-
name: end
in: query
description: 'Filter base on date (less then or equal to)'
description: 'Filter base on ISO 8601 datetime (yyyy-MM-dd''T''HH:mm:ssz), e.g. "2004-02-12T15:19:21+00:00" (less then or equal to)'
required: false
deprecated: false
allowEmptyValue: true
Expand Down
11 changes: 8 additions & 3 deletions src/Api/Dto/DailyOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
use ApiPlatform\OpenApi\Model\Response;
use App\Api\Filter\ElasticSearch\BooleanFilter;
use App\Api\Filter\ElasticSearch\DateFilter;
use App\Api\Filter\ElasticSearch\EventTagFilter;
use App\Api\Filter\ElasticSearch\IdFilter;
use App\Api\Filter\ElasticSearch\MatchFilter;
use App\Api\Filter\ElasticSearch\TagFilter;
use App\Api\State\DailyOccurrenceRepresentationProvider;
use App\Model\DateLimits;

Expand Down Expand Up @@ -51,14 +52,18 @@
)]
#[ApiFilter(
MatchFilter::class,
properties: ['event.title', 'event.organizer.name', 'event.organizer.entityId', 'event.location.name', 'event.location.entityId']
properties: ['event.title', 'event.organizer.name', 'event.location.name']
)]
#[ApiFilter(
IdFilter::class,
properties: ['event.organizer.entityId', 'event.location.entityId']
)]
#[ApiFilter(
BooleanFilter::class,
properties: ['event.publicAccess']
)]
#[ApiFilter(
EventTagFilter::class,
TagFilter::class,
properties: ['event.tags']
)]
#[ApiFilter(
Expand Down
11 changes: 8 additions & 3 deletions src/Api/Dto/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
use ApiPlatform\OpenApi\Model\Response;
use App\Api\Filter\ElasticSearch\BooleanFilter;
use App\Api\Filter\ElasticSearch\DateFilter;
use App\Api\Filter\ElasticSearch\EventTagFilter;
use App\Api\Filter\ElasticSearch\IdFilter;
use App\Api\Filter\ElasticSearch\MatchFilter;
use App\Api\Filter\ElasticSearch\TagFilter;
use App\Api\State\EventRepresentationProvider;
use App\Model\DateLimits;

Expand Down Expand Up @@ -51,14 +52,18 @@
)]
#[ApiFilter(
MatchFilter::class,
properties: ['title', 'organizer.name', 'organizer.entityId', 'location.name', 'location.entityId']
properties: ['title', 'organizer.name', 'location.name']
)]
#[ApiFilter(
IdFilter::class,
properties: ['organizer.entityId', 'location.entityId']
)]
#[ApiFilter(
BooleanFilter::class,
properties: ['publicAccess']
)]
#[ApiFilter(
EventTagFilter::class,
TagFilter::class,
properties: ['tags']
)]
#[ApiFilter(
Expand Down
12 changes: 6 additions & 6 deletions src/Api/Dto/Occurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\OpenApi\Model\Parameter;
use ApiPlatform\OpenApi\Model\Response;
use App\Api\Filter\ElasticSearch\BooleanFilter;
use App\Api\Filter\ElasticSearch\DateFilter;
use App\Api\Filter\ElasticSearch\EventTagFilter;
use App\Api\Filter\ElasticSearch\IdFilter;
use App\Api\Filter\ElasticSearch\MatchFilter;
use App\Api\Filter\ElasticSearch\TagFilter;
use App\Api\State\OccurrenceRepresentationProvider;
use App\Model\DateLimits;

Expand Down Expand Up @@ -52,14 +52,14 @@
)]
#[ApiFilter(
MatchFilter::class,
properties: ['event.title', 'event.organizer.name', 'event.organizer.entityId', 'event.location.name', 'event.location.entityId']
properties: ['event.title', 'event.organizer.name', 'event.location.name']
)]
#[ApiFilter(
BooleanFilter::class,
properties: ['event.publicAccess']
IdFilter::class,
properties: ['event.organizer.entityId', 'event.location.entityId']
)]
#[ApiFilter(
EventTagFilter::class,
TagFilter::class,
properties: ['event.tags']
)]
#[ApiFilter(
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Filter/ElasticSearch/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getDescription(string $resourceClass): array
'property' => $filterParameterName,
'type' => Type::BUILTIN_TYPE_STRING,
'required' => false,
'description' => 'Filter base on date ('.$this->config[$value]->limit->value.')',
'description' => 'Filter base on ISO 8601 datetime (yyyy-MM-dd\'T\'HH:mm:ssz), e.g. "2004-02-12T15:19:21+00:00" ('.$this->config[$value]->limit->value.')',
'openapi' => [
'allowReserved' => false,
'allowEmptyValue' => true,
Expand Down
52 changes: 52 additions & 0 deletions src/Api/Filter/ElasticSearch/IdFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Api\Filter\ElasticSearch;

use ApiPlatform\Elasticsearch\Filter\AbstractFilter;
use ApiPlatform\Metadata\Operation;
use Symfony\Component\PropertyInfo\Type;

final class IdFilter extends AbstractFilter
{
public function apply(array $clauseBody, string $resourceClass, ?Operation $operation = null, array $context = []): array
{
$properties = $this->getProperties($resourceClass);
$terms = [];

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

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

public function getDescription(string $resourceClass): array
{
if (!$this->properties) {
return [];
}

$description = [];
foreach ($this->properties as $filterParameterName => $value) {
$description[$filterParameterName] = [
'property' => $filterParameterName,
'type' => Type::BUILTIN_TYPE_ARRAY,
'required' => false,
'description' => 'Filter based on given entity ids',
'is_collection' => true,
'openapi' => [
'allowReserved' => false,
'allowEmptyValue' => true,
'explode' => false,
],
];
}

return $description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use ApiPlatform\Metadata\Operation;
use Symfony\Component\PropertyInfo\Type;

final class EventTagFilter extends AbstractFilter
final class TagFilter extends AbstractFilter
{
public function apply(array $clauseBody, string $resourceClass, ?Operation $operation = null, array $context = []): array
{
Expand Down

0 comments on commit 346b16d

Please sign in to comment.