Skip to content

Commit

Permalink
Log post and put actions for dois and events
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 1, 2020
1 parent ebc775e commit c58f1b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def create
affiliation: params[:affiliation]
}

logger.warn "Created DOI #{@doi.doi}"
render json: DoiSerializer.new(@doi, options).serialized_json, status: :created, location: @doi
else
logger.error @doi.errors.inspect
Expand Down Expand Up @@ -405,6 +406,7 @@ def update
affiliation: params[:affiliation],
}

logger.warn exists ? "Updated DOI #{@doi.doi}" : "Created DOI #{@doi.doi}"
render json: DoiSerializer.new(@doi, options).serialized_json, status: exists ? :ok : :created
else
logger.error @doi.errors.messages
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def create
if @event.update_attributes(safe_params)
options = {}
options[:is_collection] = false

logger.warn "Created event #{@event.uuid} with source_id #{@event.source_id}"
render json: EventSerializer.new(@event, options).serialized_json, status: exists ? :ok : :created
else
logger.error @event.errors.inspect
errors = @event.errors.full_messages.map { |message| { status: 422, title: message } }
render json: { errors: errors }, status: :unprocessable_entity
end
Expand All @@ -47,8 +48,10 @@ def update
options = {}
options[:is_collection] = false

logger.warn "Updated event #{@event.uuid} with source_id #{@event.source_id}"
render json: EventSerializer.new(@event, options).serialized_json, status: exists ? :ok : :created
else
logger.error @event.errors.inspect
errors = @event.errors.full_messages.map { |message| { status: 422, title: message } }
render json: { errors: errors }, status: :unprocessable_entity
end
Expand Down

0 comments on commit c58f1b5

Please sign in to comment.