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

[Prototype] EZP-26309: Prototype the usage of REST Embedding in PlatformUI #79

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 19 additions & 4 deletions src/services/ContentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,21 @@ define(["structures/ContentCreateStruct", "structures/ContentUpdateStruct", "str
*
* @method loadUserDrafts
* @param userId {String} target user identifier (e.g. "/api/ezp/v2/user/users/14")
* @parma [headers] {Object} additional headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should specify it acts as callback if callback is not set for bc, same below :)

Copy link
Contributor Author

@dpobel dpobel Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the [ and ] around headers means the parameter is not mandatory so that's kind of implied but to be honest, the documentation was not really my main purpose here :-)
That said, this is a good point because we could also do the same thing by keeping 2 parameters on the method and allowing the first one to be an option object:

/**
  * bla bla
  *
  * @param {String|Object} options the userId or an object containing the userId and others options
  * @param {String} options.userId
  * @param {Object} options.headers additional headers
  * @param {Function} callback
  */
ContentService.prototype.loadUserDrafts = function (options, callback) {
    var userId = options, headers = {};

    if ( typeof options === "object" ) {
        userId = options.userId;
        headers = options.headers || headers;
    }
    // ...
};

and I'm not really sure which approach is the best

* @param callback {Function} callback executed after performing the request (see
* {{#crossLink "ContentService"}} Note on the callbacks usage{{/crossLink}} for more info)
*/
ContentService.prototype.loadUserDrafts = function (userId, callback) {
ContentService.prototype.loadUserDrafts = function (userId, headers, callback) {
if ( !callback ) {
callback = headers;
headers = {};
}
headers.Accept = "application/vnd.ez.api.VersionList+json";
this._connectionManager.request(
"GET",
userId + "/drafts",
"",
{"Accept": "application/vnd.ez.api.VersionList+json"},
headers,
callback
);
};
Expand Down Expand Up @@ -668,12 +674,20 @@ define(["structures/ContentCreateStruct", "structures/ContentUpdateStruct", "str
*
* @method loadVersions
* @param contentId {String} target content identifier (e.g. "/api/ezp/v2/content/objects/108")
* @param [headers] {Object}
* @param callback {Function} callback executed after performing the request (see
* {{#crossLink "ContentService"}}Note on the callbacks usage{{/crossLink}} for more info)
*/
ContentService.prototype.loadVersions = function (contentId, callback) {
ContentService.prototype.loadVersions = function (contentId, headers, callback) {
var that = this;

if ( !callback ) {
callback = headers;
headers = {};
}

// TODO instead of loading the content info and then the corresponding
// versions we could maybe use REST embedding here as well.
this.loadContentInfo(
contentId,
function (error, contentResponse) {
Expand All @@ -684,11 +698,12 @@ define(["structures/ContentCreateStruct", "structures/ContentUpdateStruct", "str

var contentVersions = contentResponse.document.Content.Versions;

headers.Accept = contentVersions["_media-type"];
that._connectionManager.request(
"GET",
contentVersions._href,
"",
{"Accept": contentVersions["_media-type"]},
headers,
callback
);
}
Expand Down