Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper abstraction for hypermedia controls instead of an association #193

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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