Skip to content

Commit

Permalink
Merge pull request #2 from itk-dev/feature/419-tags-filter
Browse files Browse the repository at this point in the history
#419: Tags filter
  • Loading branch information
cableman authored Jan 11, 2024
2 parents f47b7ed + 1c97a8a commit b9df9df
Show file tree
Hide file tree
Showing 15 changed files with 617 additions and 54 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,49 @@ jobs:
- name: markdownlint
run: yarn run coding-standards-check

changelog:
apispec:
runs-on: ubuntu-latest
name: Changelog should be updated
name: API Specification validation
strategy:
fail-fast: false
matrix:
php: [ '8.2' ]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php}}
extensions: ctype, iconv, imagick, json, redis, soap, xmlreader, zip
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

- name: Export specifications
run: bin/console api:openapi:export --yaml --output=public/spec.yaml --no-interaction

- name: Check for changes in specifications
run: git diff --diff-filter=ACMRT --exit-code public/spec.yaml

changelog:
runs-on: ubuntu-latest
name: Changelog should be updated
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See [keep a changelog] for information about writing changes to this log.
- Added fixture data loader service and command to load fixtures.
- Added basic index service.
- Basic events DTO added.
- Added tags filter

[keep a changelog]: https://keepachangelog.com/en/1.1.0/
[unreleased]: https://github.com/itk-dev/event-database-imports/compare/main...develop
14 changes: 9 additions & 5 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.16.0@2897ba636551a8cb61601cc26f6ccfbba6c36591">
<file src="src/Api/State/AbstractProvider.php">
<InternalMethod>
<code>getFilters</code>
</InternalMethod>
</file>
<file src="src/Api/State/EventRepresentationProvider.php">
<InvalidReturnStatement>
<code><![CDATA[$this->index->getAll(IndexNames::Events->value, $filters, $from, self::PAGE_SIZE)]]></code>
</InvalidReturnStatement>
<MissingTemplateParam>
<code>ProviderInterface</code>
</MissingTemplateParam>
</file>
<file src="src/Api/State/OrganizationRepresentationProvider.php">
<InvalidReturnStatement>
<code><![CDATA[$this->index->getAll(IndexNames::Organization->value, $filters, $from, self::PAGE_SIZE)]]></code>
<code><![CDATA[[$this->index->get(IndexNames::Organization->value, $uriVariables['id'])['_source']]]]></code>
</InvalidReturnStatement>
<MissingTemplateParam>
Expand Down Expand Up @@ -44,13 +53,8 @@
</file>
<file src="src/Service/ElasticSearchIndex.php">
<InvalidArgument>
<code>$params</code>
<code>$params</code>
<code><![CDATA[['name' => $indexName]]]></code>
</InvalidArgument>
<PossiblyInvalidArgument>
<code>$response</code>
<code>$response</code>
</PossiblyInvalidArgument>
</file>
</files>
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"post-update-cmd": [
"@auto-scripts"
],
"api-spec-export": [
"bin/console api:openapi:export --yaml --output public/spec.yaml"
],
"coding-standards-apply": [
"PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix"
],
Expand Down
14 changes: 13 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones


App\Api\State\AbstractProvider:
arguments:
$filterLocator: '@api_platform.filter_locator'

App\Api\State\EventRepresentationProvider:
arguments:
$filterLocator: '@api_platform.filter_locator'

App\Api\State\OrganizationRepresentationProvider:
arguments:
$filterLocator: '@api_platform.filter_locator'

App\Command\FixturesLoadCommand:
arguments:
$appEnv: '%env(string:APP_ENV)%'


Elastic\Elasticsearch\Client:
factory: [ '@Elastic\Elasticsearch\ClientBuilder', fromConfig ]
arguments:
Expand Down
214 changes: 214 additions & 0 deletions public/spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
openapi: 3.1.0
info:
title: 'Event database API'
description: ''
version: 2.0.0
servers:
-
url: /
description: ''
paths:
/api/v2/events:
get:
operationId: api_events_get_collection
tags:
- Event
responses:
200:
description: 'Event collection'
content:
application/ld+json:
schema:
type: object
properties:
'hydra:member': { type: array, items: { $ref: '#/components/schemas/Event.EventRepresentationProvider.jsonld' } }
'hydra:totalItems': { type: integer, minimum: 0 }
'hydra:view': { type: object, properties: { '@id': { type: string, format: iri-reference }, '@type': { type: string }, 'hydra:first': { type: string, format: iri-reference }, 'hydra:last': { type: string, format: iri-reference }, 'hydra:previous': { type: string, format: iri-reference }, 'hydra:next': { type: string, format: iri-reference } }, example: { '@id': string, type: string, 'hydra:first': string, 'hydra:last': string, 'hydra:previous': string, 'hydra:next': string } }
'hydra:search': { type: object, properties: { '@type': { type: string }, 'hydra:template': { type: string }, 'hydra:variableRepresentation': { type: string }, 'hydra:mapping': { type: array, items: { type: object, properties: { '@type': { type: string }, variable: { type: string }, property: { type: [string, 'null'] }, required: { type: boolean } } } } } }
required:
- 'hydra:member'
summary: 'Retrieves the collection of Event resources.'
description: 'Retrieves the collection of Event resources.'
parameters:
-
name: page
in: query
description: 'The collection page number'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: integer
default: 1
style: form
explode: false
allowReserved: false
-
name: tags
in: query
description: 'Filter base on values given'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: array
items:
type: string
style: deepObject
explode: false
allowReserved: false
deprecated: false
parameters: []
'/api/v2/events/{id}':
get:
operationId: api_events_id_get
tags:
- Event
responses:
200:
description: 'Single event'
summary: 'Retrieves a Event resource.'
description: 'Retrieves a Event resource.'
parameters:
-
name: id
in: path
description: ''
required: true
deprecated: false
allowEmptyValue: false
schema:
type: integer
style: simple
explode: false
allowReserved: false
deprecated: false
parameters: []
/api/v2/organizations:
get:
operationId: api_organizations_get_collection
tags:
- Organization
responses:
200:
description: 'Organization collection'
content:
application/ld+json:
schema:
type: object
properties:
'hydra:member': { type: array, items: { $ref: '#/components/schemas/Organization.OrganizationRepresentationProvider.jsonld' } }
'hydra:totalItems': { type: integer, minimum: 0 }
'hydra:view': { type: object, properties: { '@id': { type: string, format: iri-reference }, '@type': { type: string }, 'hydra:first': { type: string, format: iri-reference }, 'hydra:last': { type: string, format: iri-reference }, 'hydra:previous': { type: string, format: iri-reference }, 'hydra:next': { type: string, format: iri-reference } }, example: { '@id': string, type: string, 'hydra:first': string, 'hydra:last': string, 'hydra:previous': string, 'hydra:next': string } }
'hydra:search': { type: object, properties: { '@type': { type: string }, 'hydra:template': { type: string }, 'hydra:variableRepresentation': { type: string }, 'hydra:mapping': { type: array, items: { type: object, properties: { '@type': { type: string }, variable: { type: string }, property: { type: [string, 'null'] }, required: { type: boolean } } } } } }
required:
- 'hydra:member'
summary: 'Retrieves the collection of Organization resources.'
description: 'Retrieves the collection of Organization resources.'
parameters:
-
name: page
in: query
description: 'The collection page number'
required: false
deprecated: false
allowEmptyValue: true
schema:
type: integer
default: 1
style: form
explode: false
allowReserved: false
deprecated: false
parameters: []
'/api/v2/organizations/{id}':
get:
operationId: api_organizations_id_get
tags:
- Organization
responses:
200:
description: 'Single organization'
summary: 'Get single organization base on identifier'
description: 'Retrieves a Organization resource.'
parameters:
-
name: id
in: path
description: ''
required: true
deprecated: false
allowEmptyValue: false
schema:
type: integer
style: simple
explode: false
allowReserved: false
deprecated: false
parameters: []
components:
schemas:
Event.EventRepresentationProvider.jsonld:
type: object
description: ''
deprecated: false
properties:
'@id':
readOnly: true
type: string
'@type':
readOnly: true
type: string
'@context':
readOnly: true
oneOf:
-
type: string
-
type: object
properties:
'@vocab':
type: string
hydra:
type: string
enum: ['http://www.w3.org/ns/hydra/core#']
required:
- '@vocab'
- hydra
additionalProperties: true
Organization.OrganizationRepresentationProvider.jsonld:
type: object
description: ''
deprecated: false
properties:
'@id':
readOnly: true
type: string
'@type':
readOnly: true
type: string
'@context':
readOnly: true
oneOf:
-
type: string
-
type: object
properties:
'@vocab':
type: string
hydra:
type: string
enum: ['http://www.w3.org/ns/hydra/core#']
required:
- '@vocab'
- hydra
additionalProperties: true
responses: { }
parameters: { }
examples: { }
requestBodies: { }
headers: { }
securitySchemes: { }
security: []
tags: []
6 changes: 6 additions & 0 deletions src/Api/Dto/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace App\Api\Dto;

use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Api\Filter\EventTagFilter;
use App\Api\State\EventRepresentationProvider;

#[ApiResource(operations: [
Expand Down Expand Up @@ -35,6 +37,10 @@
provider: EventRepresentationProvider::class,
),
])]
#[ApiFilter(
EventTagFilter::class,
properties: ['tags']
)]
class Event
{
#[ApiProperty(
Expand Down
Loading

0 comments on commit b9df9df

Please sign in to comment.