diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 9f98dce2c..a6767e400 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -17,26 +17,11 @@ class CommentsController < ApplicationController authenticate_user! end - def create - begin - comment = comment_service.create(params[:post_id], params[:text]) - rescue ActiveRecord::RecordNotFound - render plain: I18n.t("comments.create.error"), status: 404 - return - end - - if comment - respond_create_success(comment) - else - render plain: I18n.t("comments.create.error"), status: 422 - end - end - - def destroy - if comment_service.destroy(params[:id]) - respond_destroy_success - else - respond_destroy_error + def index + comments = comment_service.find_for_post(params[:post_id]) + respond_with do |format| + format.json { render json: CommentPresenter.as_collection(comments, :as_json, current_user), status: :ok } + format.mobile { render layout: false, locals: {comments: comments} } end end @@ -46,11 +31,26 @@ class CommentsController < ApplicationController end end - def index - comments = comment_service.find_for_post(params[:post_id]) - respond_with do |format| - format.json { render json: CommentPresenter.as_collection(comments, :as_json, current_user), status: 200 } - format.mobile { render layout: false, locals: {comments: comments} } + def create + begin + comment = comment_service.create(params[:post_id], params[:text]) + rescue ActiveRecord::RecordNotFound + render plain: I18n.t("comments.create.error"), status: :not_found + return + end + + if comment + respond_create_success(comment) + else + render plain: I18n.t("comments.create.error"), status: :unprocessable_entity + end + end + + def destroy + if comment_service.destroy(params[:id]) + respond_destroy_success + else + respond_destroy_error end end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 57182ac20..112ef0c58 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -16,6 +16,17 @@ class LikesController < ApplicationController authenticate_user! end + def index + like = if params[:post_id] + like_service.find_for_post(params[:post_id]) + else + like_service.find_for_comment(params[:comment_id]) + end + render json: like + .includes(author: :profile) + .as_api_response(:backbone) + end + def create like = if params[:post_id] like_service.create_for_post(params[:post_id]) @@ -40,17 +51,6 @@ class LikesController < ApplicationController end end - def index - like = if params[:post_id] - like_service.find_for_post(params[:post_id]) - else - like_service.find_for_comment(params[:comment_id]) - end - render json: like - .includes(author: :profile) - .as_api_response(:backbone) - end - private def like_service