Fix pronto in Ruby

This commit is contained in:
flaburgan 2023-10-19 10:32:54 +02:00 committed by Benjamin Neff
parent 1b2f85c384
commit 5153534f4c
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
2 changed files with 36 additions and 36 deletions

View file

@ -17,26 +17,11 @@ class CommentsController < ApplicationController
authenticate_user! authenticate_user!
end end
def create def index
begin comments = comment_service.find_for_post(params[:post_id])
comment = comment_service.create(params[:post_id], params[:text]) respond_with do |format|
rescue ActiveRecord::RecordNotFound format.json { render json: CommentPresenter.as_collection(comments, :as_json, current_user), status: :ok }
render plain: I18n.t("comments.create.error"), status: 404 format.mobile { render layout: false, locals: {comments: comments} }
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
end end
end end
@ -46,11 +31,26 @@ class CommentsController < ApplicationController
end end
end end
def index def create
comments = comment_service.find_for_post(params[:post_id]) begin
respond_with do |format| comment = comment_service.create(params[:post_id], params[:text])
format.json { render json: CommentPresenter.as_collection(comments, :as_json, current_user), status: 200 } rescue ActiveRecord::RecordNotFound
format.mobile { render layout: false, locals: {comments: comments} } 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
end end

View file

@ -16,6 +16,17 @@ class LikesController < ApplicationController
authenticate_user! authenticate_user!
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
def create def create
like = if params[:post_id] like = if params[:post_id]
like_service.create_for_post(params[:post_id]) like_service.create_for_post(params[:post_id])
@ -40,17 +51,6 @@ class LikesController < ApplicationController
end end
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 private
def like_service def like_service