From dfa22812b73571706fad492b186d6dd74e8e453d Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 25 Jan 2024 13:40:54 +0200 Subject: [PATCH] updated logs --- app/controllers/api/v1/auctions_controller.rb | 2 +- app/controllers/api/v1/offers_controller.rb | 37 ++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/v1/auctions_controller.rb b/app/controllers/api/v1/auctions_controller.rb index 7a0201c6a..c03d21651 100644 --- a/app/controllers/api/v1/auctions_controller.rb +++ b/app/controllers/api/v1/auctions_controller.rb @@ -7,7 +7,7 @@ class AuctionsController < ApplicationController skip_before_action :verify_authenticity_token def show - @auction = Auction.english.find_by!(uuid: params[:auction_id]) + @auction = Auction.find_by!(uuid: params[:auction_id]) offer = @auction.offer_from_user(current_user.id) autobider = current_user.autobiders.find_or_initialize_by(domain_name: @auction.domain_name) billing_profiles = BillingProfile.accessible_by(current_ability).where(user_id: current_user.id) diff --git a/app/controllers/api/v1/offers_controller.rb b/app/controllers/api/v1/offers_controller.rb index 065f66853..2bd069019 100644 --- a/app/controllers/api/v1/offers_controller.rb +++ b/app/controllers/api/v1/offers_controller.rb @@ -6,36 +6,53 @@ class OffersController < ApplicationController skip_before_action :verify_authenticity_token + # rubocop:disable Metrics/AbcSize + # rubocop:disable Metrics/MethodLength def create + Rails.logger.info('----') + Rails.logger.info(params) + Rails.logger.info('----') + auction = Auction.find_by(uuid: params[:bid][:auction_id]) return if auction.nil? - + offer = auction.offer_from_user(current_user.uuid) - billing_profile = current_user.billing_profiles.find_by(uuid: params[:bid][:billing_profile_id]) - + billing_profile = current_user.billing_profiles.find_by(id: params[:bid][:billing_profile_id]) + + Rails.logger.info('----') + Rails.logger.info(billing_profile.inspect) + Rails.logger.info('----') + if offer.nil? offer = Offer.new( - auction: auction, + auction:, user: current_user, cents: Money.from_amount(params[:bid][:price]).cents, - billing_profile: billing_profile, - username: Username::GenerateUsernameService.new.call + billing_profile:, + username: auction.english? ? Username::GenerateUsernameService.new.call : nil ) else offer.cents = Money.from_amount(params[:bid][:price]).cents end if offer.save - Auctions::UpdateListBroadcastService.call({ auction: auction }) + if auction.english? + Auctions::UpdateListBroadcastService.call({ auction: }) - auction.update_minimum_bid_step(params[:bid][:price].to_f) + auction.update_minimum_bid_step(params[:bid][:price].to_f) - AutobiderService.autobid(auction) - auction.update_ends_at(offer) + AutobiderService.autobid(auction) + auction.update_ends_at(offer) + end render json: { status: 'ok' }, status: :ok else + + Rails.logger.info('----') + Rails.logger.info(offer.errors.inspect) + Rails.logger.info('----') + render json: { status: 'error' }, status: :unprocessable_entity end end