Skip to content

Commit

Permalink
api: use uriTemplate feature for Camp -> CampCollaborations relation
Browse files Browse the repository at this point in the history
To omit the additional join to campCollaborations.
This does not seem to have an effect.
  • Loading branch information
BacLuc committed Oct 10, 2023
1 parent 8dc493c commit e14bf89
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 36 deletions.
1 change: 1 addition & 0 deletions api/src/Entity/Camp.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototy
];

#[AssertContainsAtLeastOneManager(groups: ['update'])]
#[ApiProperty(uriTemplate: CampCollaboration::CAMP_FILTER_URI_TEMPLATE)]
#[SerializedName('campCollaborations')]
#[Groups(['read'])]
#[ORM\OneToMany(targetEntity: CampCollaboration::class, mappedBy: 'camp', orphanRemoval: true)]
Expand Down
12 changes: 12 additions & 0 deletions api/src/Entity/CampCollaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\InputFilter;
Expand Down Expand Up @@ -57,6 +58,14 @@
security: 'is_fully_authenticated()',
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT
),
new GetCollection(
uriTemplate: self::CAMP_FILTER_URI_TEMPLATE,
uriVariables: [
'campIri' => new Link(toProperty: 'camp', fromClass: Camp::class),
],
security: 'is_fully_authenticated()',
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT
),
new Post(
processor: CampCollaborationCreateProcessor::class,
denormalizationContext: ['groups' => ['write', 'create']],
Expand Down Expand Up @@ -89,6 +98,9 @@ class CampCollaboration extends BaseEntity implements BelongsToCampInterface {
'groups' => ['read', 'CampCollaboration:Camp', 'CampCollaboration:User'],
'swagger_definition_name' => 'read',
];

public const CAMP_FILTER_URI_TEMPLATE = '/camp_collaborations?camp={campIri}';

public const RESEND_INVITATION = 'resend_invitation';

public const ROLE_GUEST = 'guest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2045,10 +2045,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -2416,10 +2415,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -2603,10 +2601,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -3032,10 +3029,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -3412,10 +3408,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -3599,10 +3594,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -3949,10 +3943,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -4343,10 +4336,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -4530,10 +4522,9 @@ components:
- 'null'
- string
campCollaborations:
items:
format: iri-reference
type: string
type: array
format: iri-reference
readOnly: true
type: string
categories:
description: 'Types of programme, such as sports activities or meal times.'
example: '["/categories/1a2b3c4d"]'
Expand Down Expand Up @@ -19119,6 +19110,120 @@ paths:
summary: 'Send the invitation email for this CampCollaboration again. Only possible, if the status is already invited.'
tags:
- CampCollaboration
'/camp_collaborations?camp={campIri}':
get:
deprecated: false
description: 'Retrieves the collection of CampCollaboration resources.'
operationId: 'api_camp_collaborations?camp=_campIri_get_collection'
parameters:
-
allowEmptyValue: false
allowReserved: false
deprecated: false
description: 'Camp identifier'
explode: false
in: path
name: campIri
required: true
schema:
type: string
style: simple
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: false
in: query
name: activityResponsibles.activity
required: false
schema:
type: string
style: form
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: false
in: query
name: camp
required: false
schema:
type: string
style: form
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: true
in: query
name: 'activityResponsibles.activity[]'
required: false
schema:
items:
type: string
type: array
style: form
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: true
in: query
name: 'camp[]'
required: false
schema:
items:
type: string
type: array
style: form
responses:
200:
content:
application/hal+json:
schema:
properties:
_embedded: { items: { $ref: '#/components/schemas/CampCollaboration.jsonhal-read_CampCollaboration.Camp_CampCollaboration.User' }, type: array }
_links: { properties: { first: { properties: { href: { format: iri-reference, type: string } }, type: object }, last: { properties: { href: { format: iri-reference, type: string } }, type: object }, next: { properties: { href: { format: iri-reference, type: string } }, type: object }, previous: { properties: { href: { format: iri-reference, type: string } }, type: object }, self: { properties: { href: { format: iri-reference, type: string } }, type: object } }, type: object }
itemsPerPage: { minimum: 0, type: integer }
totalItems: { minimum: 0, type: integer }
required:
- _embedded
- _links
type: object
application/json:
schema:
items:
$ref: '#/components/schemas/CampCollaboration-read_CampCollaboration.Camp_CampCollaboration.User'
type: array
application/ld+json:
schema:
properties:
'hydra:member': { items: { $ref: '#/components/schemas/CampCollaboration.jsonld-read_CampCollaboration.Camp_CampCollaboration.User' }, type: array }
'hydra:search': { properties: { '@type': { type: string }, 'hydra:mapping': { items: { properties: { '@type': { type: string }, property: { type: ['null', string] }, required: { type: boolean }, variable: { type: string } }, type: object }, type: array }, 'hydra:template': { type: string }, 'hydra:variableRepresentation': { type: string } }, type: object }
'hydra:totalItems': { minimum: 0, type: integer }
'hydra:view': { example: { '@id': string, 'hydra:first': string, 'hydra:last': string, 'hydra:next': string, 'hydra:previous': string, type: string }, properties: { '@id': { format: iri-reference, type: string }, '@type': { type: string }, 'hydra:first': { format: iri-reference, type: string }, 'hydra:last': { format: iri-reference, type: string }, 'hydra:next': { format: iri-reference, type: string }, 'hydra:previous': { format: iri-reference, type: string } }, type: object }
required:
- 'hydra:member'
type: object
application/vnd.api+json:
schema:
items:
$ref: '#/components/schemas/CampCollaboration-read_CampCollaboration.Camp_CampCollaboration.User'
type: array
text/html:
schema:
items:
$ref: '#/components/schemas/CampCollaboration-read_CampCollaboration.Camp_CampCollaboration.User'
type: array
description: 'CampCollaboration collection'
summary: 'Retrieves the collection of CampCollaboration resources.'
tags:
- CampCollaboration
parameters: []
/camps:
get:
deprecated: false
Expand Down

0 comments on commit e14bf89

Please sign in to comment.