Skip to content

Commit

Permalink
updating by following the formAction
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianconcept committed Feb 18, 2024
1 parent bd52aea commit 716c4d5
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions Ride/RidePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Class {
'subpresenters',
'renderer'
],
#classInstVars : [
'restfulActions'
],
#category : #'Ride-Presenters'
}

Expand Down Expand Up @@ -104,6 +107,17 @@ RidePresenter class >> getSnakeCasedModelName [
^ self getModelName asSnakeCase
]

{ #category : #initializing }
RidePresenter class >> intializeResfulActions [

^ restfulActions := SmallDictionary new
at: #POST put: #create;
at: #PUT put: #update;
at: #PATCH put: #update;
at: #DELETE put: #destroy;
yourself
]

Check warning on line 119 in Ride/RidePresenter.class.st

View check run for this annotation

Codecov / codecov/patch

Ride/RidePresenter.class.st#L111-L119

Added lines #L111 - L119 were not covered by tests

{ #category : #accessing }
RidePresenter class >> layoutName [

Expand Down Expand Up @@ -134,6 +148,18 @@ RidePresenter class >> partialYieldTargetName [
^ #yield
]

{ #category : #actions }
RidePresenter class >> reset [

Check warning on line 152 in Ride/RidePresenter.class.st

View check run for this annotation

Codecov / codecov/patch

Ride/RidePresenter.class.st#L152

Added line #L152 was not covered by tests

restfulActions := nil

Check warning on line 154 in Ride/RidePresenter.class.st

View check run for this annotation

Codecov / codecov/patch

Ride/RidePresenter.class.st#L154

Added line #L154 was not covered by tests
]

{ #category : #accessing }
RidePresenter class >> restfulActions [

Check warning on line 158 in Ride/RidePresenter.class.st

View check run for this annotation

Codecov / codecov/patch

Ride/RidePresenter.class.st#L158

Added line #L158 was not covered by tests

^ restfulActions ifNil: [ self intializeResfulActions ]
]

Check warning on line 161 in Ride/RidePresenter.class.st

View check run for this annotation

Codecov / codecov/patch

Ride/RidePresenter.class.st#L160-L161

Added lines #L160 - L161 were not covered by tests

{ #category : #adding }
RidePresenter >> addNoticeSuccess: aString [

Expand Down Expand Up @@ -177,14 +203,22 @@ RidePresenter >> currentSession [

{ #category : #actions }
RidePresenter >> formAction [
"Makes the receiver perform the action corresponding to a RESTful convention
and defined by the expected hidden field in its _method value.
Signals an exception if no value is found for _method
or when is found but it doesn't follow the REST convention."

| req restfulAction |
| req restfulAction selector |
req := self currentRequest.
restfulAction := req entity
at: #_method
ifAbsent: [
RideError signal: 'Missing form action' ].
self halt
selector := self class restfulActions at: restfulAction ifAbsent: [
RideError signal:
('Unsupported form action: {1}' format:
{ restfulAction asString }) ].
^ self perform: selector
]

Check warning on line 222 in Ride/RidePresenter.class.st

View check run for this annotation

Codecov / codecov/patch

Ride/RidePresenter.class.st#L205-L222

Added lines #L205 - L222 were not covered by tests

{ #category : #accessing }
Expand Down Expand Up @@ -348,9 +382,9 @@ RidePresenter >> onBeforeAction [

{ #category : #actions }
RidePresenter >> redirectFor: aRideModel [
"Signal a redirect poiting to what will show the given RideModel."

| response destinationURL |
response := self currentResponse.
| destinationURL |
destinationURL := self getShowUrlFor: aRideModel.

RideRedirect signalFor: destinationURL
Expand Down

0 comments on commit 716c4d5

Please sign in to comment.