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!
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

View file

@ -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