Skip to content

Commit

Permalink
added logs for offer actions
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 9934982 commit f47a3de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/english_offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ 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}")

redirect_to new_auction_english_offer_path(auction_uuid: @auction.uuid) and return
end

Expand All @@ -42,18 +44,23 @@ def create
broadcast_update_auction_offer(@auction)
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}")
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}")
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}")

render :new, status: :unprocessable_entity
end
end
Expand Down Expand Up @@ -113,6 +120,7 @@ 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?
redirect_to root_path, flash: { alert: I18n.t('.english_offers.create.ban') } and return
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

Expand All @@ -125,6 +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}")
redirect_to edit_english_offer_path(@offer.uuid)
end

Expand All @@ -134,6 +143,8 @@ 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}")
redirect_to edit_english_offer_path(auction.users_offer_uuid) and return
end

Expand Down
7 changes: 7 additions & 0 deletions app/controllers/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +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")
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}")
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}")
end
end
end
Expand Down Expand Up @@ -71,10 +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}")
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}")
end
end
end
Expand All @@ -87,6 +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}")
end
end

Expand All @@ -107,6 +113,7 @@ def check_for_ban
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
recaptcha_valid && @offer.save && @offer.reload
end

Expand Down

0 comments on commit f47a3de

Please sign in to comment.