From e14bf89fffc6231017414c3b498ea72c16f147d7 Mon Sep 17 00:00:00 2001 From: BacLuc Date: Tue, 10 Oct 2023 16:45:17 +0200 Subject: [PATCH] api: use uriTemplate feature for Camp -> CampCollaborations relation To omit the additional join to campCollaborations. This does not seem to have an effect. --- api/src/Entity/Camp.php | 1 + api/src/Entity/CampCollaboration.php | 12 ++ ...est__testOpenApiSpecMatchesSnapshot__1.yml | 177 ++++++++++++++---- 3 files changed, 154 insertions(+), 36 deletions(-) diff --git a/api/src/Entity/Camp.php b/api/src/Entity/Camp.php index 96fdbd36ae..d5c2a3007f 100644 --- a/api/src/Entity/Camp.php +++ b/api/src/Entity/Camp.php @@ -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)] diff --git a/api/src/Entity/CampCollaboration.php b/api/src/Entity/CampCollaboration.php index 1ba6065544..5a96a76dbb 100644 --- a/api/src/Entity/CampCollaboration.php +++ b/api/src/Entity/CampCollaboration.php @@ -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; @@ -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']], @@ -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'; diff --git a/api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testOpenApiSpecMatchesSnapshot__1.yml b/api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testOpenApiSpecMatchesSnapshot__1.yml index 530d400764..f5d081b3da 100644 --- a/api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testOpenApiSpecMatchesSnapshot__1.yml +++ b/api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testOpenApiSpecMatchesSnapshot__1.yml @@ -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"]' @@ -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"]' @@ -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"]' @@ -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"]' @@ -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"]' @@ -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"]' @@ -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"]' @@ -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"]' @@ -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"]' @@ -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