Skip to content

Commit

Permalink
added profile controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Hasjanov authored and Oleg Hasjanov committed Jan 31, 2024
1 parent dfa2281 commit 2b4179a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 19 deletions.
6 changes: 5 additions & 1 deletion app/broadcasts/auctions/update_list_broadcast_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def call

private

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def post_call
auction_json = {
domain_name: auction.domain_name,
Expand All @@ -25,7 +27,9 @@ def post_call
highest_bid: auction.currently_winning_offer&.price.to_f,
highest_bidder: auction.currently_winning_offer&.username,
min_bids_step: auction.min_bids_step,
auction_type: auction&.platform
auction_type: auction&.platform,
enable_deposit: auction.enable_deposit,
requirement_deposit_in_cents: auction.requirement_deposit_in_cents
}

ActionCable.server.broadcast('auctions_api', { auction: auction_json })
Expand Down
32 changes: 32 additions & 0 deletions app/controllers/api/v1/profiles/passwords_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Api
module V1
module Profiles
class PasswordsController < ApplicationController
before_action :authenticate_user!
respond_to :json

skip_before_action :verify_authenticity_token

def update
puts params_for_update

if current_user.valid_password?(params[:user][:current_password])
if current_user.update(params_for_update)
bypass_sign_in(current_user)
render json: current_user, status: :ok
else
Rails.logger.info current_user.errors.inspect
render json: current_user.errors, status: :unprocessable_entity
end
else
render json: { errors: [t('.incorrect_password')] }, status: :unprocessable_entity
end
end

def params_for_update
params.require(:user).permit(:password, :password_confirmation)
end
end
end
end
end
23 changes: 23 additions & 0 deletions app/controllers/api/v1/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Api
module V1
class ProfilesController < ApplicationController
before_action :authenticate_user!
respond_to :json

skip_before_action :verify_authenticity_token

def update
if current_user.update(params_for_update)
render json: current_user, status: :ok
else
Rails.logger.info @user.errors.inspect
render json: current_user.errors, status: :unprocessable_entity
end
end

def params_for_update
params.require(:user).permit(:email, :country_code, :given_names, :surname, :mobile_phone)
end
end
end
end
18 changes: 0 additions & 18 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,9 @@ def self.search(params = {})

case params[:sort]
when 'channel'
# invoices_array = query.to_a

# if sort_direction == 'asc'
# invoices_array.sort_by do |invoice|
# invoice.paid_with_payment_order&.channel || ''
# end
# else
# invoices_array.sort_by do |invoice|
# invoice.paid_with_payment_order&.channel || ''
# end.reverse
# end

query.left_outer_joins(:paid_with_payment_order)
.select("invoices.*, REPLACE(payment_orders.type, 'PaymentOrders::', '') AS payment_order_channel")
.order(Arel.sql("payment_order_channel #{sort_direction} NULLS LAST"))

# query.left_outer_joins(:paid_with_payment_order)
# .select("invoices.*, COALESCE(REPLACE(paid_with_payment_orders.type, 'PaymentOrders::', ''), '') AS payment_order_channel")
# .order(Arel.sql("payment_order_channel #{sort_direction} NULLS LAST"))


when 'billing_profile_name'
query.left_outer_joins(:billing_profile).order("billing_profiles.name #{sort_direction}")
when 'total'
Expand Down
2 changes: 2 additions & 0 deletions app/views/auctions/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ json.array! @auctions_list do |auction|
json.highest_bidder auction.currently_winning_offer&.username
json.min_bids_step auction.min_bids_step.to_f
json.auction_type auction&.platform
json.enable_deposit auction.enable_deposit
json.requirement_deposit_in_cents auction.requirement_deposit_in_cents
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
resource :offers, only: :create
resource :autobiders, only: :create
resource :auctions, only: :show
resource :profiles, only: :update do
scope module: :profiles do
resource :passwords, only: :update
end
end
resources :invoices, only: :index
end
end
Expand Down

0 comments on commit 2b4179a

Please sign in to comment.