Skip to content

Commit

Permalink
api: offer activity_progress_labels as subresource of camp
Browse files Browse the repository at this point in the history
That it can be cached.
  • Loading branch information
BacLuc committed Feb 8, 2025
1 parent bfc8b52 commit 4811724
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
13 changes: 13 additions & 0 deletions api/src/Entity/ActivityProgressLabel.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 @@ -43,6 +44,17 @@
new GetCollection(
security: 'is_authenticated()'
),
new GetCollection(
uriTemplate: self::CAMP_SUBRESOURCE_URI_TEMPLATE,
uriVariables: [
'campId' => new Link(
toProperty: 'camp',
fromClass: Camp::class,
security: 'is_granted("CAMP_COLLABORATOR", camp) or is_granted("CAMP_IS_PROTOTYPE", camp)'
),
],
security: 'is_fully_authenticated()',
),
new Post(
validationContext: ['groups' => ['Default', 'create']],
denormalizationContext: ['groups' => ['write', 'create']],
Expand All @@ -58,6 +70,7 @@
#[ORM\Entity(repositoryClass: ActivityProgressLabelRepository::class)]
#[ORM\UniqueConstraint(name: 'activity_progress_label_unique', columns: ['campid', 'position'])]
class ActivityProgressLabel extends BaseEntity implements BelongsToCampInterface, CopyFromPrototypeInterface {
public const CAMP_SUBRESOURCE_URI_TEMPLATE = '/camps/{campId}/activity_progress_labels{._format}';
public const ITEM_NORMALIZATION_CONTEXT = [
'groups' => [
'read',
Expand Down
6 changes: 5 additions & 1 deletion api/src/Entity/Camp.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototy
/**
* All the progress labels within this camp.
*/
#[ApiProperty(writable: false, example: '["/progress_labels/1a2b3c4d"]')]
#[ApiProperty(
writable: false,
uriTemplate: ActivityProgressLabel::CAMP_SUBRESOURCE_URI_TEMPLATE,
example: '"/camps/1a2b3c4d/activity_progress_labels"'
)]
#[Groups(['read'])]
#[ORM\OneToMany(targetEntity: ActivityProgressLabel::class, mappedBy: 'camp', orphanRemoval: true, cascade: ['persist'])]
public Collection $progressLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24431,6 +24431,95 @@ paths:
summary: 'Creates a Camp resource.'
tags:
- Camp
'/camps/{campId}/activity_progress_labels':
get:
deprecated: false
description: 'Retrieves the collection of ActivityProgressLabel resources.'
operationId: api_camps_campIdactivity_progress_labels_get_collection
parameters:
-
allowEmptyValue: false
allowReserved: false
deprecated: false
description: ''
explode: false
in: query
name: camp
required: false
schema:
type: string
style: form
-
allowEmptyValue: false
allowReserved: false
deprecated: false
description: ''
explode: true
in: query
name: 'camp[]'
required: false
schema:
items:
type: string
type: array
style: form
-
allowEmptyValue: false
allowReserved: false
deprecated: false
description: 'ActivityProgressLabel identifier'
explode: false
in: path
name: campId
required: true
schema:
type: string
style: simple
responses:
200:
content:
application/hal+json:
schema:
properties:
_embedded: { anyOf: [{ properties: { item: { items: { $ref: '#/components/schemas/ActivityProgressLabel.jsonhal-read' }, type: array } }, type: object }, { type: object }] }
_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/ActivityProgressLabel-read'
type: array
application/ld+json:
schema:
properties:
'hydra:member': { items: { $ref: '#/components/schemas/ActivityProgressLabel.jsonld-read' }, 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/ActivityProgressLabel.jsonapi'
type: array
text/html:
schema:
items:
$ref: '#/components/schemas/ActivityProgressLabel-read'
type: array
description: 'ActivityProgressLabel collection'
403:
description: Forbidden
summary: 'Retrieves the collection of ActivityProgressLabel resources.'
tags:
- ActivityProgressLabel
'/camps/{campId}/categories':
get:
deprecated: false
Expand Down

0 comments on commit 4811724

Please sign in to comment.