solve code reviews, resolve rebase conflicts

This commit is contained in:
Rishabh Saxena 2016-07-14 19:10:33 +05:30
parent 9b704e483e
commit ae44abc7e6
10 changed files with 32 additions and 45 deletions

View file

@ -29,8 +29,9 @@ class ConferenceRegistrationsController < ApplicationController
def show
@total_price = Ticket.total_price(@conference, current_user, paid: true)
@tickets = current_user.ticket_purchases.where(conference_id: @conference.id, paid: true)
@ticket_payments = @tickets.group_by(&:payment_id)
@tickets = current_user.ticket_purchases.by_conference(@conference).paid
@ticket_payments = @tickets.group_by(&:ticket_id)
@total_quantity = @tickets.group(:ticket_id).sum(:quantity)
end
def edit; end

View file

@ -16,9 +16,9 @@ class PaymentsController < ApplicationController
@payment = Payment.new(payment_params)
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
if @payment.valid? && @payment.purchase(current_user, @conference, price_in_cents) && @payment.save
update_paid_ticket_purchases(@conference, current_user, @payment)
redirect_to conference_conference_registrations_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
if @payment.purchase(current_user, @conference, price_in_cents) && @payment.save
update_purchased_ticket_purchases(@conference, current_user, @payment)
redirect_to conference_conference_registration_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
else
render 'new'
end
@ -30,10 +30,8 @@ class PaymentsController < ApplicationController
(@payment.amount * 100).round
end
def update_paid_ticket_purchases(conference, user, payment)
paid_ticket_purchases = TicketPurchase.where(conference_id: conference.id,
user_id: user.id,
paid: false)
def update_purchased_ticket_purchases(conference, user, payment)
paid_ticket_purchases = current_user.ticket_purchases.by_conference(conference).unpaid
paid_ticket_purchases.each do |ticket|
ticket.paid = true
ticket.payment_id = payment.id

View file

@ -7,7 +7,7 @@ class TicketPurchasesController < ApplicationController
TicketPurchase.destroy_all(user_id: current_user.id, conference_id: @conference.id, paid: false)
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
if message.blank?
if current_user.ticket_purchases.unpaid.any?
if current_user.ticket_purchases.by_conference(@conference).unpaid.any?
redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.'
else
redirect_to conference_conference_registration_path(@conference.short_title)