Skip to content

Commit

Permalink
added offers endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Sep 30, 2024
1 parent ae066de commit a587936
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions app/controllers/api/v1/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ class OffersController < ApplicationController

skip_before_action :verify_authenticity_token

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 '----'

# price with tax
render json: offers.as_json(include: [:auction, :billing_profile])
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def create
Rails.logger.info('----')
Rails.logger.info(params)
Rails.logger.info('----')

#{"bid"=>{"price"=>320.0, "auction_id"=>"2a893210-f1f1-4be8-9d78-b793f1fa0ec6", "billing_profile_id"=>"23"},
#"controller"=>"api/v1/offers", "action"=>"create", "offer"=>{}}

auction = Auction.find_by(uuid: params[:bid][:auction_id])
return if auction.nil?

billing_profile = current_user.billing_profiles.find_by(id: params[:bid][:billing_profile_id])

offer = auction.offer_from_user(current_user.id)

Rails.logger.info('----')
Rails.logger.info(current_user.inspect)
Rails.logger.info(billing_profile.inspect)
Rails.logger.info(offer.inspect)
Rails.logger.info('----')

if offer.nil?
offer = Offer.new(
auction:,
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace :api do
namespace :v1 do
resource :stream_name, only: :show
resource :offers, only: :create
resources :offers, only: [:create, :index]
resource :autobiders, only: :create
resource :tara_auth_session, only: :create
resource :auctions, only: :show
Expand Down

0 comments on commit a587936

Please sign in to comment.