Skip to content

Commit

Permalink
updated logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Hasjanov authored and Oleg Hasjanov committed Jan 17, 2024
1 parent f47a3de commit 09d10fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 6 additions & 6 deletions app/controllers/english_offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create
unless check_first_bid_for_english_auction(create_params, @auction)
formatted_starting_price = format('%.2f', @auction.starting_price)
flash[:alert] = t('english_offers.create.bid_must_be', minimum: formatted_starting_price)
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{auction.id} but it failed. Errors: #{offer.errors.full_messages}")
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{t('english_offers.create.bid_must_be', minimum: formatted_starting_price)}")

redirect_to new_auction_english_offer_path(auction_uuid: @auction.uuid) and return
end
Expand All @@ -45,21 +45,21 @@ def create
send_outbided_notification(auction: @auction, offer: @offer, flash: 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}")
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

Rails.logger.info("User #{current_user.id} tried to create offer for auction #{auction.id} but it failed. Errors: #{offer.errors.full_messages}")
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{@offer.errors.full_messages}")
redirect_to root_path
end
else
@show_checkbox_recaptcha = true unless @success
flash.now[:alert] = t('english_offers.form.captcha_verification')
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{auction.id} but it failed. Errors: #{offer.errors.full_messages}")
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{@offer.errors.full_messages}")

render :new, status: :unprocessable_entity
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def update_auction_values(auction, message_text)
auction.update_ends_at(@offer)

flash[:notice] = message_text
Rails.logger.info("User #{current_user.id} updated offer #{offer.id} for auction #{auction.id}")
Rails.logger.info("User #{current_user.id} updated offer #{@offer.id} for auction #{auction.id}")
redirect_to edit_english_offer_path(@offer.uuid)
end

Expand All @@ -144,7 +144,7 @@ def prevent_check_for_invalid_bid
flash[:alert] =
"#{t('english_offers.show.bid_failed', price: format('%.2f', auction.highest_price.to_f).tr('.', ','))}"

Rails.logger.info("User #{current_user.id} tried to update offer #{offer.id} for auction #{auction.id} but it failed. Errors: #{offer.errors.full_messages}")
Rails.logger.info("User #{current_user.id} tried to update offer #{@offer.id} for auction #{auction.id} but it failed. Errors: #{@offer.errors.full_messages}")
redirect_to edit_english_offer_path(auction.users_offer_uuid) and return
end

Expand Down
15 changes: 8 additions & 7 deletions app/controllers/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def create
if existing_offer
format.html do
redirect_to offer_path(existing_offer.uuid), notice: t('offers.already_exists')
Rails.loggfer.info("User #{current_user.id} tried to create offer for auction #{auction.id} but it already exists")
Rails.loggfer.info("User #{current_user.id} tried to create offer for auction #{@auction.id} but it already exists")
end
elsif create_predicate
format.html { redirect_to offer_path(@offer.uuid), notice: t('.created') }
format.json { render :show, status: :created, location: @offer }
Rails.logger.info("User #{current_user.id} created offer #{offer.id} for auction #{auction.id}")
Rails.logger.info("User #{current_user.id} created offer #{@offer.id} for auction #{@auction.id}")
else
@show_checkbox_recaptcha = true unless @success
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @offer.errors, status: :unprocessable_entity }
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{auction.id} but it failed. Errors: #{offer.errors.full_messages}")
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{@offer.errors.full_messages}")
end
end
end
Expand Down Expand Up @@ -74,12 +74,12 @@ def update
if update_predicate
format.html { redirect_to offer_path(@offer.uuid), notice: t(:updated) }
format.json { render :show, status: :ok, location: @offer }
Rails.logger.info("User #{current_user.id} updated offer #{offer.id} for auction #{auction.id}")
Rails.logger.info("User #{current_user.id} updated offer #{@offer.id} for auction #{auction.id}")
else
@show_checkbox_recaptcha = true unless @success
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @offer.errors, status: :unprocessable_entity }
Rails.logger.info("User #{current_user.id} tried to update offer #{offer.id} for auction #{auction.id} but it failed. Errors: #{offer.errors.full_messages}")
Rails.logger.info("User #{current_user.id} tried to update offer #{@offer.id} for auction #{auction.id} but it failed. Errors: #{@offer.errors.full_messages}")
end
end
end
Expand All @@ -92,7 +92,7 @@ def destroy
respond_to do |format|
format.html { redirect_to auction_path(@offer.auction.uuid), notice: t(:deleted) }
format.json { head :no_content }
Rails.logger.info("User #{current_user.id} deleted offer #{offer.id} for auction #{auction.id}")
Rails.logger.info("User #{current_user.id} deleted offer #{@offer.id} for auction #{@offer.auction.id}")
end
end

Expand All @@ -108,12 +108,13 @@ def update_not_allowed(auction)

def check_for_ban
if Ban.valid.where(user_id: current_user).where(domain_name: @auction.domain_name).any? || current_user.completely_banned?
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{I18n.t('.offers.create.ban')}")
redirect_to root_path, flash: { alert: I18n.t('.offers.create.ban') } and return
end
end

def create_predicate
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{auction.id} but recaptcha failed") unless recaptcha_valid
Rails.logger.info("User #{current_user.id} tried to create offer for auction #{@auction.id} but recaptcha failed") unless recaptcha_valid
recaptcha_valid && @offer.save && @offer.reload
end

Expand Down

0 comments on commit 09d10fe

Please sign in to comment.