From f7816c9fd7276be2cd98e03d24881a3425f1e70d Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Tue, 11 Jun 2024 18:30:00 -0300 Subject: [PATCH] Use proper abstraction for hypermedia controls instead of an association --- ...rmediaDrivenRESTfulRequestHandler.class.st | 21 +++++++++---------- .../MediaControlsBuilder.class.st | 4 ++-- ...ntrollerPaginateCollectionsPolicy.class.st | 6 +----- .../NeoJSONObjectMapping.extension.st | 10 ++++++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/source/Stargate-Model/HypermediaDrivenRESTfulRequestHandler.class.st b/source/Stargate-Model/HypermediaDrivenRESTfulRequestHandler.class.st index 2545b9d..da20fb0 100644 --- a/source/Stargate-Model/HypermediaDrivenRESTfulRequestHandler.class.st +++ b/source/Stargate-Model/HypermediaDrivenRESTfulRequestHandler.class.st @@ -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' } diff --git a/source/Stargate-Model/MediaControlsBuilder.class.st b/source/Stargate-Model/MediaControlsBuilder.class.st index c290778..ce7dcea 100644 --- a/source/Stargate-Model/MediaControlsBuilder.class.st +++ b/source/Stargate-Model/MediaControlsBuilder.class.st @@ -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' } diff --git a/source/Stargate-Model/RESTfulControllerPaginateCollectionsPolicy.class.st b/source/Stargate-Model/RESTfulControllerPaginateCollectionsPolicy.class.st index 32ba8f9..c134779 100644 --- a/source/Stargate-Model/RESTfulControllerPaginateCollectionsPolicy.class.st +++ b/source/Stargate-Model/RESTfulControllerPaginateCollectionsPolicy.class.st @@ -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' } diff --git a/source/Stargate-NeoJSON-Extensions/NeoJSONObjectMapping.extension.st b/source/Stargate-NeoJSON-Extensions/NeoJSONObjectMapping.extension.st index d872c29..c070e36 100644 --- a/source/Stargate-NeoJSON-Extensions/NeoJSONObjectMapping.extension.st +++ b/source/Stargate-NeoJSON-Extensions/NeoJSONObjectMapping.extension.st @@ -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' }