Skip to content

Commit

Permalink
Use proper abstraction for hypermedia controls instead of an association
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Jun 11, 2024
1 parent c0fbea3 commit f7816c9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ HypermediaDrivenRESTfulRequestHandler >> encodeResource: resource as: mediaType
{ #category : 'private' }
HypermediaDrivenRESTfulRequestHandler >> encodeResourceCollection: resourceCollection basedOn: httpRequest within: requestContext [

requestContext
holdAsHypermediaControls:
( self paginationPolicy
addPaginationControlsTo: ( Array with: 'self' -> httpRequest absoluteUrl )
within: requestContext )
for: resourceCollection.
resourceCollection do: [ :resource | self holdResource: resource controlsWithin: requestContext ].
^ super
encodeResourceCollection: ( ResourceCollection wrapping: resourceCollection )
basedOn: httpRequest
within: requestContext
requestContext
holdAsHypermediaControls: ( self paginationPolicy
addPaginationControlsTo: { httpRequest absoluteUrl asWebLink toMyself }
within: requestContext )
for: resourceCollection.
resourceCollection do: [ :resource | self holdResource: resource controlsWithin: requestContext ].
^ super
encodeResourceCollection: ( ResourceCollection wrapping: resourceCollection )
basedOn: httpRequest
within: requestContext
]

{ #category : 'private' }
Expand Down
4 changes: 2 additions & 2 deletions source/Stargate-Model/MediaControlsBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ MediaControlsBuilder >> addAsSelfLink: aUrl [
{ #category : 'adding' }
MediaControlsBuilder >> addLink: aUrl relatedTo: aRelationType [

mediaControls add: aRelationType -> aUrl
mediaControls add: ( aUrl asWebLink relationType: aRelationType )
]

{ #category : 'adding' }
MediaControlsBuilder >> addRelativeLink: aRelativeUrl relatedTo: aRelationType [

mediaControls add: aRelationType -> ( resourceLocatorBinding content baseUrl / aRelativeUrl )
self addLink: resourceLocatorBinding content baseUrl / aRelativeUrl relatedTo: aRelationType
]

{ #category : 'building' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ RESTfulControllerPaginateCollectionsPolicy >> addPaginationControlsTo: mediaCont
{ #category : 'applying' }
RESTfulControllerPaginateCollectionsPolicy >> affect: response within: requestContext [

requestContext paginationControls do: [ :assoc |
response addLink: ( ( WebLink to: assoc value )
relationType: assoc key;
yourself )
]
requestContext paginationControls do: [ :link | response addLink: link ]
]

{ #category : 'applying' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Extension { #name : 'NeoJSONObjectMapping' }
{ #category : '*Stargate-NeoJSON-Extensions' }
NeoJSONObjectMapping >> mapAsHypermediaControls: aBlock [

self
mapProperty: #links
getter: [ :object | ( ( aBlock cull: object ) collect: [ :assoc | assoc key -> assoc value printString ] ) asDictionary ]
self mapProperty: #links getter: [ :object |
| controls |
controls := OrderedDictionary new.
( aBlock cull: object ) do: [ :webLink |
controls at: webLink relationType put: webLink url printString ].
controls
]
]

{ #category : '*Stargate-NeoJSON-Extensions' }
Expand Down

0 comments on commit f7816c9

Please sign in to comment.