Improved API responses

This commit is contained in:
rr- 2015-08-03 18:54:10 +02:00
parent 5a537ba168
commit b3def7fc21
49 changed files with 75 additions and 76 deletions

View file

@ -387,7 +387,7 @@ App.Controls.TagInput = function($underlyingInput) {
return promise.make(function(resolve, reject) { return promise.make(function(resolve, reject) {
promise.wait(api.get('/tags/' + tagName + '/siblings')) promise.wait(api.get('/tags/' + tagName + '/siblings'))
.then(function(response) { .then(function(response) {
resolve(response.json.data); resolve(response.json.tags);
}).fail(function() { }).fail(function() {
reject(); reject();
}); });

View file

@ -71,10 +71,7 @@ App.Pager = function(
var totalRecords = response.json.totalRecords; var totalRecords = response.json.totalRecords;
totalPages = Math.ceil(totalRecords / pageSize); totalPages = Math.ceil(totalRecords / pageSize);
resolve({ resolve(response);
entities: response.json.data,
totalRecords: totalRecords,
totalPages: totalPages});
}).fail(function(response) { }).fail(function(response) {
reject(response); reject(response);

View file

@ -53,7 +53,7 @@ App.Presenters.CommentListPresenter = function(
if (comments.length === 0) { if (comments.length === 0) {
promise.wait(api.get('/comments/' + params.post.id)) promise.wait(api.get('/comments/' + params.post.id))
.then(function(response) { .then(function(response) {
comments = response.json.data; comments = response.json.comments;
render(); render();
}).fail(function() { }).fail(function() {
console.log(arguments); console.log(arguments);
@ -176,7 +176,7 @@ App.Presenters.CommentListPresenter = function(
p.then(function(response) { p.then(function(response) {
$textarea.val(''); $textarea.val('');
var comment = response.json; var comment = response.json.comment;
if (commentToEdit) { if (commentToEdit) {
$form.slideUp(function() { $form.slideUp(function() {

View file

@ -38,8 +38,8 @@ App.Presenters.GlobalCommentListPresenter = function(
baseUri: '#/comments', baseUri: '#/comments',
backendUri: '/comments', backendUri: '/comments',
$target: $el.find('.pagination-target'), $target: $el.find('.pagination-target'),
updateCallback: function($page, data) { updateCallback: function($page, response) {
renderComments($page, data.entities); renderComments($page, response.json.comments);
}, },
}, },
function() { function() {
@ -65,12 +65,11 @@ App.Presenters.GlobalCommentListPresenter = function(
$el.html(templates.list()); $el.html(templates.list());
} }
function renderComments($page, data) { function renderComments($page, postComments) {
var $target = $page.find('.posts'); var $target = $page.find('.posts');
_.each(data, function(data) { _.each(postComments, function(postComments) {
var post = data.post; var post = postComments.post;
var comments = data.comments; var comments = postComments.comments;
var $post = jQuery('<li>' + templates.listItem({ var $post = jQuery('<li>' + templates.listItem({
util: util, util: util,
post: post, post: post,

View file

@ -31,8 +31,8 @@ App.Presenters.HistoryPresenter = function(
baseUri: '#/history', baseUri: '#/history',
backendUri: '/history', backendUri: '/history',
$target: $el.find('.pagination-target'), $target: $el.find('.pagination-target'),
updateCallback: function($page, data) { updateCallback: function($page, response) {
renderHistory($page, data.entities); renderHistory($page, response.json.history);
}, },
}, },
function() { function() {

View file

@ -114,7 +114,14 @@ App.Presenters.PagerPresenter = function(
updateCallback($page, response); updateCallback($page, response);
refreshPageList(); refreshPageList();
if (!response.entities.length) {
var entities =
response.json.posts ||
response.json.users ||
response.json.comments ||
response.json.tags;
if (!entities.length) {
messagePresenter.showInfo($messages, 'No data to show'); messagePresenter.showInfo($messages, 'No data to show');
if (pager.getVisiblePages().length === 1) { if (pager.getVisiblePages().length === 1) {
hidePageList(); hidePageList();
@ -125,7 +132,7 @@ App.Presenters.PagerPresenter = function(
showPageList(); showPageList();
} }
if (pager.getPage() < response.totalPages) { if (pager.getPage() < pager.getTotalPages()) {
attachNextPageLoader(); attachNextPageLoader();
} }

View file

@ -151,8 +151,9 @@ App.Presenters.PostEditPresenter = function(
promise.wait(api.post('/posts/' + post.id, formData)) promise.wait(api.post('/posts/' + post.id, formData))
.then(function(response) { .then(function(response) {
tagList.refreshTags(); tagList.refreshTags();
post = response.json.post;
if (typeof(updateCallback) !== 'undefined') { if (typeof(updateCallback) !== 'undefined') {
updateCallback(post = response.json); updateCallback(post);
} }
}).fail(function(response) { }).fail(function(response) {
showEditError(response); showEditError(response);

View file

@ -45,8 +45,8 @@ App.Presenters.PostListPresenter = function(
baseUri: '#/posts', baseUri: '#/posts',
backendUri: '/posts', backendUri: '/posts',
$target: $el.find('.pagination-target'), $target: $el.find('.pagination-target'),
updateCallback: function($page, data) { updateCallback: function($page, response) {
renderPosts($page, data.entities); renderPosts($page, response.json.posts);
}, },
}, },
function() { function() {
@ -221,7 +221,7 @@ App.Presenters.PostListPresenter = function(
formData.tags = tags.join(' '); formData.tags = tags.join(' ');
promise.wait(api.post('/posts/' + post.id, formData)) promise.wait(api.post('/posts/' + post.id, formData))
.then(function(response) { .then(function(response) {
post = response.json; post = response.json.post;
$post.data('post', post); $post.data('post', post);
softRenderPost($post); softRenderPost($post);
}).fail(function(response) { }).fail(function(response) {

View file

@ -120,7 +120,7 @@ App.Presenters.PostPresenter = function(
return promise.make(function(resolve, reject) { return promise.make(function(resolve, reject) {
promise.wait(api.get('/posts/' + postNameOrId)) promise.wait(api.get('/posts/' + postNameOrId))
.then(function(postResponse) { .then(function(postResponse) {
post = postResponse.json; post = postResponse.json.post;
resolve(); resolve();
}).fail(function(response) { }).fail(function(response) {
showGenericError(response); showGenericError(response);

View file

@ -60,7 +60,7 @@ App.Presenters.RegistrationPresenter = function(
function registrationSuccess(apiResponse) { function registrationSuccess(apiResponse) {
$el.find('form').slideUp(function() { $el.find('form').slideUp(function() {
var message = 'Registration complete! '; var message = 'Registration complete! ';
if (!apiResponse.json.confirmed) { if (!apiResponse.json.user.confirmed) {
message += '<br/>Check your inbox for activation e-mail.<br/>If e-mail doesn\'t show up, check your spam folder.'; message += '<br/>Check your inbox for activation e-mail.<br/>If e-mail doesn\'t show up, check your spam folder.';
} else { } else {
message += '<a href="#/login">Click here</a> to login.'; message += '<a href="#/login">Click here</a> to login.';

View file

@ -36,8 +36,8 @@ App.Presenters.TagListPresenter = function(
baseUri: '#/tags', baseUri: '#/tags',
backendUri: '/tags', backendUri: '/tags',
$target: $el.find('.pagination-target'), $target: $el.find('.pagination-target'),
updateCallback: function($page, data) { updateCallback: function($page, response) {
renderTags($page, data.entities); renderTags($page, response.json.tags);
}, },
}, },
function() { function() {

View file

@ -66,9 +66,9 @@ App.Presenters.TagPresenter = function(
api.get('tags/' + tagName + '/siblings'), api.get('tags/' + tagName + '/siblings'),
api.get('posts', {query: tagName})) api.get('posts', {query: tagName}))
.then(function(tagResponse, siblingsResponse, postsResponse) { .then(function(tagResponse, siblingsResponse, postsResponse) {
tag = tagResponse.json; tag = tagResponse.json.tag;
siblings = siblingsResponse.json.data; siblings = siblingsResponse.json.tags;
posts = postsResponse.json.data; posts = postsResponse.json.posts;
posts = posts.slice(0, 8); posts = posts.slice(0, 8);
render(); render();

View file

@ -133,7 +133,7 @@ App.Presenters.UserAccountSettingsPresenter = function(
function editSuccess(apiResponse) { function editSuccess(apiResponse) {
var wasLoggedIn = auth.isLoggedIn(user.name); var wasLoggedIn = auth.isLoggedIn(user.name);
user = apiResponse.json; user = apiResponse.json.user;
if (wasLoggedIn) { if (wasLoggedIn) {
auth.updateCurrentUser(user); auth.updateCurrentUser(user);
} }
@ -142,7 +142,7 @@ App.Presenters.UserAccountSettingsPresenter = function(
var $messages = jQuery(target).find('.messages'); var $messages = jQuery(target).find('.messages');
var message = 'Account settings updated!'; var message = 'Account settings updated!';
if (!apiResponse.json.confirmed) { if (!apiResponse.json.user.confirmed) {
message += '<br/>Check your inbox for activation e-mail.<br/>If e-mail doesn\'t show up, check your spam folder.'; message += '<br/>Check your inbox for activation e-mail.<br/>If e-mail doesn\'t show up, check your spam folder.';
} }
messagePresenter.showInfo($messages, message); messagePresenter.showInfo($messages, message);

View file

@ -35,8 +35,8 @@ App.Presenters.UserListPresenter = function(
baseUri: '#/users', baseUri: '#/users',
backendUri: '/users', backendUri: '/users',
$target: $el.find('.pagination-target'), $target: $el.find('.pagination-target'),
updateCallback: function($page, data) { updateCallback: function($page, response) {
renderUsers($page, data.entities); renderUsers($page, response.json.users);
}, },
}, },
function() { function() {

View file

@ -41,7 +41,7 @@ App.Presenters.UserPresenter = function(
promise.wait(api.get('/users/' + userName)) promise.wait(api.get('/users/' + userName))
.then(function(response) { .then(function(response) {
user = response.json; user = response.json.user;
var extendedContext = _.extend(params, {user: user}); var extendedContext = _.extend(params, {user: user});
presenterManager.initPresenters([ presenterManager.initPresenters([

View file

@ -15,7 +15,7 @@ App.Services.PostsAroundCalculator = function(_, promise, util, pager) {
pager.setPage(query.page); pager.setPage(query.page);
promise.wait(pager.retrieveCached()) promise.wait(pager.retrieveCached())
.then(function(response) { .then(function(response) {
var postIds = _.pluck(response.entities, 'id'); var postIds = _.pluck(response.json.posts, 'id');
var position = _.indexOf(postIds, postId); var position = _.indexOf(postIds, postId);
if (position === -1) { if (position === -1) {
@ -51,10 +51,10 @@ App.Services.PostsAroundCalculator = function(_, promise, util, pager) {
pager.setPage(page + direction); pager.setPage(page + direction);
promise.wait(pager.retrieveCached()) promise.wait(pager.retrieveCached())
.then(function(response) { .then(function(response) {
if (response.entities.length) { if (response.json.posts.length) {
var post = direction === - 1 ? var post = direction === - 1 ?
_.last(response.entities) : _.last(response.json.posts) :
_.first(response.entities); _.first(response.json.posts);
var url = util.appendComplexRouteParam( var url = util.appendComplexRouteParam(
'#/post/' + post.id, '#/post/' + post.id,

View file

@ -49,6 +49,6 @@ class AddComment extends AbstractCommentRoute
$post = $this->postService->getByNameOrId($args['postNameOrId']); $post = $this->postService->getByNameOrId($args['postNameOrId']);
$comment = $this->commentService->createComment($post, $this->inputReader->text); $comment = $this->commentService->createComment($post, $this->inputReader->text);
return $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig()); return ['comment' => $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig())];
} }
} }

View file

@ -52,6 +52,6 @@ class DeleteComment extends AbstractCommentRoute
? Privilege::DELETE_OWN_COMMENTS ? Privilege::DELETE_OWN_COMMENTS
: Privilege::DELETE_ALL_COMMENTS); : Privilege::DELETE_ALL_COMMENTS);
return $this->commentService->deleteComment($comment); $this->commentService->deleteComment($comment);
} }
} }

View file

@ -53,6 +53,6 @@ class EditComment extends AbstractCommentRoute
: Privilege::EDIT_ALL_COMMENTS); : Privilege::EDIT_ALL_COMMENTS);
$comment = $this->commentService->updateComment($comment, $this->inputReader->text); $comment = $this->commentService->updateComment($comment, $this->inputReader->text);
return $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig()); return ['comment' => $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig())];
} }
} }

View file

@ -80,7 +80,7 @@ class GetComments extends AbstractCommentRoute
} }
return [ return [
'data' => $data, 'comments' => $data,
'pageSize' => $result->getPageSize(), 'pageSize' => $result->getPageSize(),
'totalRecords' => $result->getTotalRecords()]; 'totalRecords' => $result->getTotalRecords()];
} }

View file

@ -63,6 +63,6 @@ class GetPostComments extends AbstractCommentRoute
$result = $this->commentService->getFiltered($filter); $result = $this->commentService->getFiltered($filter);
$entities = $this->commentViewProxy->fromArray($result->getEntities(), $this->getCommentsFetchConfig()); $entities = $this->commentViewProxy->fromArray($result->getEntities(), $this->getCommentsFetchConfig());
return ['data' => $entities]; return ['comments' => $entities];
} }
} }

View file

@ -47,6 +47,6 @@ class AddToFavorites extends AbstractRoute
$this->favoritesService->addFavorite($user, $post); $this->favoritesService->addFavorite($user, $post);
$users = $this->favoritesService->getFavoriteUsers($post); $users = $this->favoritesService->getFavoriteUsers($post);
return ['data' => $this->userViewProxy->fromArray($users)]; return ['users' => $this->userViewProxy->fromArray($users)];
} }
} }

View file

@ -43,6 +43,6 @@ class GetFavoriteUsers extends AbstractRoute
{ {
$post = $this->postService->getByNameOrId($args['postNameOrId']); $post = $this->postService->getByNameOrId($args['postNameOrId']);
$users = $this->favoritesService->getFavoriteUsers($post); $users = $this->favoritesService->getFavoriteUsers($post);
return ['data' => $this->userViewProxy->fromArray($users)]; return ['users' => $this->userViewProxy->fromArray($users)];
} }
} }

View file

@ -47,6 +47,6 @@ class RemoveFromFavorites extends AbstractRoute
$this->favoritesService->deleteFavorite($user, $post); $this->favoritesService->deleteFavorite($user, $post);
$users = $this->favoritesService->getFavoriteUsers($post); $users = $this->favoritesService->getFavoriteUsers($post);
return ['data' => $this->userViewProxy->fromArray($users)]; return ['users' => $this->userViewProxy->fromArray($users)];
} }
} }

View file

@ -49,7 +49,7 @@ class GetHistory extends AbstractRoute
$result = $this->historyService->getFiltered($filter); $result = $this->historyService->getFiltered($filter);
$entities = $this->snapshotViewProxy->fromArray($result->getEntities()); $entities = $this->snapshotViewProxy->fromArray($result->getEntities());
return [ return [
'data' => $entities, 'history' => $entities,
'pageSize' => $result->getPageSize(), 'pageSize' => $result->getPageSize(),
'totalRecords' => $result->getTotalRecords()]; 'totalRecords' => $result->getTotalRecords()];
} }

View file

@ -78,8 +78,7 @@ class Login extends AbstractRoute
$user = $this->authService->getLoggedInUser(); $user = $this->authService->getLoggedInUser();
} }
return return [
[
'token' => $this->tokenViewProxy->fromEntity($this->authService->getLoginToken()), 'token' => $this->tokenViewProxy->fromEntity($this->authService->getLoginToken()),
'user' => $this->userViewProxy->fromEntity($user), 'user' => $this->userViewProxy->fromEntity($user),
'privileges' => $this->privilegeService->getCurrentPrivileges(), 'privileges' => $this->privilegeService->getCurrentPrivileges(),

View file

@ -47,6 +47,6 @@ class CreatePost extends AbstractPostRoute
$this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS_ANONYMOUSLY); $this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS_ANONYMOUSLY);
$post = $this->postService->createPost($formData); $post = $this->postService->createPost($formData);
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); return ['post' => $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig())];
} }
} }

View file

@ -36,7 +36,6 @@ class GetFeaturedPost extends AbstractPostRoute
$user = $this->postFeatureService->getFeaturedPostUser(); $user = $this->postFeatureService->getFeaturedPostUser();
return [ return [
'user' => $this->userViewProxy->fromEntity($user), 'user' => $this->userViewProxy->fromEntity($user),
'post' => $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()), 'post' => $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig())];
];
} }
} }

View file

@ -36,6 +36,6 @@ class GetPost extends AbstractPostRoute
$this->privilegeService->assertPrivilege(Privilege::VIEW_POSTS); $this->privilegeService->assertPrivilege(Privilege::VIEW_POSTS);
$post = $this->postService->getByNameOrId($args['postNameOrId']); $post = $this->postService->getByNameOrId($args['postNameOrId']);
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); return ['post' => $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig())];
} }
} }

View file

@ -54,7 +54,7 @@ class GetPosts extends AbstractPostRoute
$result = $this->postService->getFiltered($filter); $result = $this->postService->getFiltered($filter);
$entities = $this->postViewProxy->fromArray($result->getEntities(), $this->getLightFetchConfig()); $entities = $this->postViewProxy->fromArray($result->getEntities(), $this->getLightFetchConfig());
return [ return [
'data' => $entities, 'posts' => $entities,
'pageSize' => $result->getPageSize(), 'pageSize' => $result->getPageSize(),
'totalRecords' => $result->getTotalRecords()]; 'totalRecords' => $result->getTotalRecords()];
} }

View file

@ -49,6 +49,6 @@ class AddPostNote extends AbstractPostRoute
$formData = new PostNoteFormData($this->inputReader); $formData = new PostNoteFormData($this->inputReader);
$postNote = $this->postNotesService->createPostNote($post, $formData); $postNote = $this->postNotesService->createPostNote($post, $formData);
return $this->postNoteViewProxy->fromEntity($postNote); return ['note' => $this->postNoteViewProxy->fromEntity($postNote)];
} }
} }

View file

@ -32,6 +32,6 @@ class DeletePostNote extends AbstractPostRoute
{ {
$postNote = $this->postNotesService->getById($args['postNoteId']); $postNote = $this->postNotesService->getById($args['postNoteId']);
$this->privilegeService->assertPrivilege(Privilege::DELETE_POST_NOTES); $this->privilegeService->assertPrivilege(Privilege::DELETE_POST_NOTES);
return $this->postNotesService->deletePostNote($postNote); $this->postNotesService->deletePostNote($postNote);
} }
} }

View file

@ -44,6 +44,6 @@ class GetPostNotes extends AbstractPostRoute
{ {
$post = $this->postService->getByNameOrId($args['postNameOrId']); $post = $this->postService->getByNameOrId($args['postNameOrId']);
$postNotes = $this->postNotesService->getByPost($post); $postNotes = $this->postNotesService->getByPost($post);
return $this->postNoteViewProxy->fromArray($postNotes); return ['notes' => $this->postNoteViewProxy->fromArray($postNotes)];
} }
} }

View file

@ -45,6 +45,6 @@ class UpdatePostNote extends AbstractPostRoute
$formData = new PostNoteFormData($this->inputReader); $formData = new PostNoteFormData($this->inputReader);
$postNote = $this->postNotesService->updatePostNote($postNote, $formData); $postNote = $this->postNotesService->updatePostNote($postNote, $formData);
return $this->postNoteViewProxy->fromEntity($postNote); return ['note' => $this->postNoteViewProxy->fromEntity($postNote)];
} }
} }

View file

@ -59,6 +59,6 @@ class UpdatePost extends AbstractPostRoute
$this->postService->updatePost($post, $formData); $this->postService->updatePost($post, $formData);
$post = $this->postService->getByNameOrId($postNameOrId); $post = $this->postService->getByNameOrId($postNameOrId);
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); return ['post' => $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig())];
} }
} }

View file

@ -42,7 +42,6 @@ abstract class AbstractScoreRoute extends AbstractRoute
$result = $this->scoreService->setUserScore($user, $entity, $score); $result = $this->scoreService->setUserScore($user, $entity, $score);
return [ return [
'score' => $this->scoreService->getScoreValue($entity), 'score' => $this->scoreService->getScoreValue($entity),
'ownScore' => $result->getScore(), 'ownScore' => $result->getScore()];
];
} }
} }

View file

@ -31,6 +31,6 @@ class DeleteTag extends AbstractTagRoute
{ {
$tag = $this->tagService->getByName($args['tagName']); $tag = $this->tagService->getByName($args['tagName']);
$this->privilegeService->assertPrivilege(Privilege::DELETE_TAGS); $this->privilegeService->assertPrivilege(Privilege::DELETE_TAGS);
return $this->tagService->deleteTag($tag); $this->tagService->deleteTag($tag);
} }
} }

View file

@ -36,6 +36,6 @@ class GetTag extends AbstractTagRoute
$this->privilegeService->assertPrivilege(Privilege::LIST_TAGS); $this->privilegeService->assertPrivilege(Privilege::LIST_TAGS);
$tag = $this->tagService->getByName($args['tagName']); $tag = $this->tagService->getByName($args['tagName']);
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig()); return ['tag' => $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig())];
} }
} }

View file

@ -38,8 +38,6 @@ class GetTagSiblings extends AbstractTagRoute
$tag = $this->tagService->getByName($tagName); $tag = $this->tagService->getByName($tagName);
$result = $this->tagService->getSiblings($tagName); $result = $this->tagService->getSiblings($tagName);
$entities = $this->tagViewProxy->fromArray($result); $entities = $this->tagViewProxy->fromArray($result);
return [ return ['tags' => $entities];
'data' => $entities,
];
} }
} }

View file

@ -49,7 +49,7 @@ class GetTags extends AbstractTagRoute
$result = $this->tagService->getFiltered($filter); $result = $this->tagService->getFiltered($filter);
$entities = $this->tagViewProxy->fromArray($result->getEntities(), $this->getFullFetchConfig()); $entities = $this->tagViewProxy->fromArray($result->getEntities(), $this->getFullFetchConfig());
return [ return [
'data' => $entities, 'tags' => $entities,
'pageSize' => $result->getPageSize(), 'pageSize' => $result->getPageSize(),
'totalRecords' => $result->getTotalRecords()]; 'totalRecords' => $result->getTotalRecords()];
} }

View file

@ -38,6 +38,6 @@ class MergeTags extends AbstractTagRoute
$sourceTag = $this->tagService->getByName($tagName); $sourceTag = $this->tagService->getByName($tagName);
$targetTag = $this->tagService->getByName($targetTagName); $targetTag = $this->tagService->getByName($targetTagName);
$this->privilegeService->assertPrivilege(Privilege::MERGE_TAGS); $this->privilegeService->assertPrivilege(Privilege::MERGE_TAGS);
return $this->tagService->mergeTag($sourceTag, $targetTag); $this->tagService->mergeTag($sourceTag, $targetTag);
} }
} }

View file

@ -57,6 +57,6 @@ class UpdateTag extends AbstractTagRoute
$this->privilegeService->assertPrivilege(Privilege::CHANGE_TAG_SUGGESTIONS); $this->privilegeService->assertPrivilege(Privilege::CHANGE_TAG_SUGGESTIONS);
$tag = $this->tagService->updateTag($tag, $formData); $tag = $this->tagService->updateTag($tag, $formData);
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig()); return ['tag' => $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig())];
} }
} }

View file

@ -24,6 +24,6 @@ class ActivateAccount extends AbstractUserRoute
public function work($args) public function work($args)
{ {
$user = $this->userService->getByNameOrEmail($args['userNameOrEmail'], true); $user = $this->userService->getByNameOrEmail($args['userNameOrEmail'], true);
return $this->userService->sendActivationEmail($user); $this->userService->sendActivationEmail($user);
} }
} }

View file

@ -41,6 +41,6 @@ class CreateUser extends AbstractUserRoute
$this->privilegeService->assertPrivilege(Privilege::REGISTER); $this->privilegeService->assertPrivilege(Privilege::REGISTER);
$formData = new RegistrationFormData($this->inputReader); $formData = new RegistrationFormData($this->inputReader);
$user = $this->userService->createUser($formData); $user = $this->userService->createUser($formData);
return $this->userViewProxy->fromEntity($user); return ['user' => $this->userViewProxy->fromEntity($user)];
} }
} }

View file

@ -38,6 +38,6 @@ class DeleteUser extends AbstractUserRoute
: Privilege::DELETE_ALL_ACCOUNTS); : Privilege::DELETE_ALL_ACCOUNTS);
$user = $this->userService->getByNameOrEmail($userNameOrEmail); $user = $this->userService->getByNameOrEmail($userNameOrEmail);
return $this->userService->deleteUser($user); $this->userService->deleteUser($user);
} }
} }

View file

@ -41,6 +41,6 @@ class GetUser extends AbstractUserRoute
if (!$this->privilegeService->isLoggedIn($userNameOrEmail)) if (!$this->privilegeService->isLoggedIn($userNameOrEmail))
$this->privilegeService->assertPrivilege(Privilege::VIEW_USERS); $this->privilegeService->assertPrivilege(Privilege::VIEW_USERS);
$user = $this->userService->getByNameOrEmail($userNameOrEmail); $user = $this->userService->getByNameOrEmail($userNameOrEmail);
return $this->userViewProxy->fromEntity($user); return ['user' => $this->userViewProxy->fromEntity($user)];
} }
} }

View file

@ -52,7 +52,7 @@ class GetUsers extends AbstractUserRoute
$result = $this->userService->getFiltered($filter); $result = $this->userService->getFiltered($filter);
$entities = $this->userViewProxy->fromArray($result->getEntities()); $entities = $this->userViewProxy->fromArray($result->getEntities());
return [ return [
'data' => $entities, 'users' => $entities,
'pageSize' => $result->getPageSize(), 'pageSize' => $result->getPageSize(),
'totalRecords' => $result->getTotalRecords()]; 'totalRecords' => $result->getTotalRecords()];
} }

View file

@ -22,6 +22,6 @@ class PasswordReset extends AbstractUserRoute
public function work($args) public function work($args)
{ {
$user = $this->userService->getByNameOrEmail($args['userNameOrEmail']); $user = $this->userService->getByNameOrEmail($args['userNameOrEmail']);
return $this->userService->sendPasswordResetEmail($user); $this->userService->sendPasswordResetEmail($user);
} }
} }

View file

@ -91,6 +91,6 @@ class UpdateUser extends AbstractUserRoute
} }
$user = $this->userService->updateUser($user, $formData); $user = $this->userService->updateUser($user, $formData);
return $this->userViewProxy->fromEntity($user); return ['user' => $this->userViewProxy->fromEntity($user)];
} }
} }