Skip to content

Commit 441a36b

Browse files
author
guylabs
committed
Extract the call to the backend to a method to allow future refactorings.
1 parent ad69392 commit 441a36b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/angular-spring-data-rest.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@
144144
}
145145
}
146146

147-
return $injector.get("$resource")(extractUrl(this, resourceObject.name), parameters, actions, options);
147+
return callBackend(extractUrl(this, resourceObject.name), parameters, actions, options);
148148

149149
} else if (resourceObject in this[config.links.key]) {
150-
// get the url out of the resource name, remove the template parameters and return the Angular $resource method
151-
return $injector.get("$resource")(extractUrl(this, resourceObject), paramDefaults, actions, options);
150+
// get the url out of the resource name and return the backend function
151+
return callBackend(extractUrl(this, resourceObject), paramDefaults, actions, options);
152152
}
153153

154154
// return the available resources if the resource object is not set
@@ -160,6 +160,19 @@
160160

161161
};
162162

163+
/**
164+
* Returns the Angular $resource method which is configured with the given parameters.
165+
*
166+
* @param {string} url the url at which the resource is available
167+
* @param {object} paramDefaults optional $resource method parameter defaults
168+
* @param {object} actions optional $resource method actions
169+
* @param {object} options additional $resource method options
170+
* @returns {*}
171+
*/
172+
function callBackend(url, paramDefaults, actions, options) {
173+
return $injector.get("$resource")(url, paramDefaults, actions, options);
174+
}
175+
163176
/**
164177
* Removes the template parameters of the given url. e.g. from this url
165178
* 'http://localhost:8080/categories{?page,size,sort}' it will remove the curly braces

0 commit comments

Comments
 (0)