Fix code style

This commit is contained in:
Frank Rousseau 2018-07-06 14:02:26 +02:00
parent 758c673f68
commit a56d998499
6 changed files with 27 additions and 17 deletions

View file

@ -10,29 +10,29 @@ module Api
rescue_from Exception do |e| rescue_from Exception do |e|
logger.error e.message logger.error e.message
logger.error e.backtrace.join("\n") logger.error e.backtrace.join("\n")
render json: error_body(500, e.message), status: 500 render json: error_body(500, e.message), status: :internal_server_error
end end
rescue_from Rack::OAuth2::Server::Resource::Forbidden do |e| rescue_from Rack::OAuth2::Server::Resource::Forbidden do |e|
logger.error e.message logger.error e.message
render json: error_body(403, e.message), status: 403 render json: error_body(403, e.message), status: :forbidden
end end
rescue_from ActiveRecord::RecordNotFound do |e| rescue_from ActiveRecord::RecordNotFound do |e|
logger.error e.message logger.error e.message
message = I18n.t("api.error.not_found") message = I18n.t("api.error.not_found")
render json: error_body(404, message), status: 404 render json: error_body(404, message), status: :not_found
end end
rescue_from ActiveRecord::RecordInvalid do |e| rescue_from ActiveRecord::RecordInvalid do |e|
logger.error e.message logger.error e.message
render json: error_body(422, e.to_s), status: 422 render json: error_body(422, e.to_s), status: :unprocessable_entity
end end
rescue_from ActionController::ParameterMissing do |e| rescue_from ActionController::ParameterMissing do |e|
logger.error e.message logger.error e.message
message = I18n.t("api.error.wrong_parameters") + ": " + e.message message = I18n.t("api.error.wrong_parameters") + ": " + e.message
render json: error_body(422, message), status: 422 render json: error_body(422, message), status: :unprocessable_entity
end end
def error_body(code, message) def error_body(code, message)

View file

@ -14,7 +14,7 @@ module Api
def create def create
@comment = comment_service.create(params[:post_id], params[:body]) @comment = comment_service.create(params[:post_id], params[:body])
comment = comment_as_json(@comment) comment = comment_as_json(@comment)
render json: comment, status: 201 render json: comment, status: :created
end end
def index def index
@ -39,7 +39,10 @@ module Api
if report.save if report.save
head :no_content head :no_content
else else
render json: {error: I18n.t("report.status.failed")}, status: 500 render(
json: {error: I18n.t("report.status.failed")},
status: :internal_server_error
)
end end
end end

View file

@ -14,7 +14,10 @@ module Api
end end
rescue_from ActiveRecord::RecordNotFound do rescue_from ActiveRecord::RecordNotFound do
render json: {error: I18n.t("conversations.not_found")}, status: 404 render(
json: {error: I18n.t("conversations.not_found")},
status: :not_found
)
end end
def index def index
@ -44,7 +47,7 @@ module Api
render json: { render json: {
conversation: conversation_as_json(conversation) conversation: conversation_as_json(conversation)
}, status: 201 }, status: :created
end end
def destroy def destroy

View file

@ -8,11 +8,11 @@ module Api
end end
rescue_from ActiveRecord::RecordNotFound do rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("likes.not_found"), status: 404 render json: I18n.t("likes.not_found"), status: :not_found
end end
rescue_from ActiveRecord::RecordInvalid do rescue_from ActiveRecord::RecordInvalid do
render json: I18n.t("likes.create.fail"), status: 404 render json: I18n.t("likes.create.fail"), status: :not_found
end end
def create def create

View file

@ -12,7 +12,10 @@ module Api
end end
rescue_from ActiveRecord::RecordNotFound do rescue_from ActiveRecord::RecordNotFound do
render json: {error: I18n.t("conversations.not_found")}, status: 404 render(
json: {error: I18n.t("conversations.not_found")},
status: :not_found
)
end end
def create def create
@ -21,13 +24,16 @@ module Api
message = current_user.build_message(conversation, text: opts[:body]) message = current_user.build_message(conversation, text: opts[:body])
message.save! message.save!
Diaspora::Federation::Dispatcher.defer_dispatch(current_user, message) Diaspora::Federation::Dispatcher.defer_dispatch(current_user, message)
render json: message_json(message), status: 201 render json: message_json(message), status: :created
end end
def index def index
conversation = conversation_service.find!(params[:conversation_id]) conversation = conversation_service.find!(params[:conversation_id])
conversation.set_read(current_user) conversation.set_read(current_user)
render json: conversation.messages.map {|x| message_json(x) }, status: 201 render(
json: conversation.messages.map {|x| message_json(x) },
status: :created
)
end end
def conversation_service def conversation_service

View file

@ -40,9 +40,7 @@ module Api
private private
def stream_responder(stream_klass=nil) def stream_responder(stream_klass=nil)
if stream_klass.present? @stream = stream_klass.present? ? stream_klass.new(current_user, max_time: max_time) : @stream
@stream ||= stream_klass.new(current_user, max_time: max_time)
end
render json: @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) } render json: @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) }
end end