Skip to content

Commit

Permalink
Merge pull request #495 from datacite/log_post_put
Browse files Browse the repository at this point in the history
Log post and put actions for dois and events
  • Loading branch information
Martin Fenner authored May 1, 2020
2 parents ebc775e + c58f1b5 commit 7aa74d7
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 7aa74d7

Please sign in to comment.