Skip to content

Commit

Permalink
remove uneccesary comments, updated json response for offers
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Sep 30, 2024
1 parent a587936 commit 04943fe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
15 changes: 7 additions & 8 deletions app/controllers/api/v1/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ class OffersController < ApplicationController

def index
offers = Offer.includes(:auction)
.includes(:result)
.where(user_id: current_user)
.order('auctions.ends_at DESC')

Rails.logger.info '---- offers ----'
Rails.logger.info(offers.inspect)
Rails.logger.info '----'
.includes(:result)
.where(user_id: current_user)
.order('auctions.ends_at DESC')

# price with tax
render json: offers.as_json(include: [:auction, :billing_profile])
render json: offers.as_json(
include: %i[auction billing_profile],
methods: %i[auction_status api_price api_total api_bidders]
)
end

# rubocop:disable Metrics/AbcSize
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/api/v1/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ def update
end

def create
puts '----'
puts params_for_create
puts '----'

user = User.new(params_for_create)

if user.save
Expand Down
41 changes: 36 additions & 5 deletions app/models/offer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,43 @@ def price=(value)
def total
return price * (DEFAULT_PRICE_VALUE + billing_profile.vat_rate) if billing_profile.present?

if user&.country_code == 'EE' || user&.country_code.nil?
default_vat = Setting.find_by(code: :estonian_vat_rate).retrieve
else
default_vat = Countries.vat_rate_from_alpha2_code(user.country_code)
default_vat = if user&.country_code == 'EE' || user&.country_code.nil?
Setting.find_by(code: :estonian_vat_rate).retrieve
else
Countries.vat_rate_from_alpha2_code(user.country_code)
end

price * (DEFAULT_PRICE_VALUE + (Invoice.find_by(result:)&.vat_rate || default_vat))
end

def auction_status
return 'you_won' if auction.finished? && result
return 'you_lost' if auction.finished? && auction.result && !result

if auction.english?
return 'you_are_winning' if auction.currently_winning_offer == self

return 'you_are_loosing'
end

price * (DEFAULT_PRICE_VALUE + (Invoice.find_by(result: result)&.vat_rate || default_vat))
'still_in_progress'
end

def api_total
total.to_d
end

def api_price
price.to_d
end

def api_bidders
auction.offers.map do |offer|
{
username: offer.username,
price: offer.price.to_d,
updated_at: offer.updated_at
}
end
end
end

0 comments on commit 04943fe

Please sign in to comment.