Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added logs for offer actions #1312

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions app/controllers/english_offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ def create
broadcast_update_auction_offer(@auction)
send_outbided_notification(auction: @auction, offer: @offer, flash:)
update_auction_values(@auction, t('english_offers.create.created'))
Rails.logger.info("User #{current_user.id} created offer #{@offer.id} for auction #{@auction.id}")
else
flash[:alert] = if @offer.errors.full_messages_for(:cents).present?
@offer.errors.full_messages_for(:cents).join
else
@offer.errors.full_messages.join('; ')
end

errors = if @offer.errors.full_messages_for(:cents).present?
@offer.errors.full_messages_for(:cents).join
else
@offer.errors.full_messages.join('; ')
end
flash[:alert] = errors
Rails.logger.error("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{errors}")
redirect_to root_path and return
end
end
Expand All @@ -67,13 +69,16 @@ def update
broadcast_update_auction_offer(@auction)
send_outbided_notification(auction: @auction, offer: @offer, flash:)
update_auction_values(@auction, t('english_offers.edit.bid_updated'))
Rails.logger.info("User #{current_user.id} updated offer #{@offer.id} for auction #{@auction.id}")
else
flash[:alert] = if @offer.errors.full_messages_for(:cents).present?
@offer.errors.full_messages_for(:cents).join
else
@offer.errors.full_messages.join('; ')
end

errors = if @offer.errors.full_messages_for(:cents).present?
@offer.errors.full_messages_for(:cents).join
else
@offer.errors.full_messages.join('; ')
end

flash[:alert] = errors
Rails.logger.error("User #{current_user.id} tried to update offer for auction #{offer.auction.id} but it failed. Errors: #{errors}")
redirect_to root_path
end
end
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ def create
redirect_to root_path, notice: t('offers.already_exists')
end
elsif create_predicate
Rails.logger.info("User #{current_user.id} created offer #{@offer.id} for auction #{@auction.id}")
format.html { redirect_to root_path, notice: t('.created') }
format.json { render :show, status: :created, location: @offer }
else
flash[:alert] = @offer.errors.full_messages.join('; ')
error_msg = @offer.errors.full_messages.join('; ')
flash[:alert] = error_msg
Rails.logger.error("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{error_msg}")
format.html { redirect_to root_path, status: :see_other }
format.json { render json: @offer.errors, status: :unprocessable_entity }
end
Expand Down Expand Up @@ -63,10 +66,13 @@ def update
redirect_to root_path and return if update_not_allowed(@offer.auction)

if update_predicate
Rails.logger.info("User #{current_user.id} updated offer #{@offer.id} for auction #{@offer.auction.id}")
format.html { redirect_to root_path, notice: t(:updated), status: :see_other }
format.json { render :show, status: :ok, location: @offer }
else
flash[:alert] = @offer.errors.full_messages.join('; ')
errors = @offer.errors.full_messages.join('; ')
flash[:alert] = errors
Rails.logger.error("User #{current_user.id} tried to update offer for auction #{offer.auction.id} but it failed. Errors: #{errors}")
format.html { redirect_to root_path, status: :see_other }
format.json { render json: @offer.errors, status: :unprocessable_entity }
end
Expand Down
Loading