Skip to content

Week7#6

Open
Zvrbsky wants to merge 12 commits into
masterfrom
week7
Open

Week7#6
Zvrbsky wants to merge 12 commits into
masterfrom
week7

Conversation

@Zvrbsky
Copy link
Copy Markdown
Owner

@Zvrbsky Zvrbsky commented Dec 10, 2018

No description provided.

end

def do_attachment
if Event.decrease_ticket_number(@order)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trochę pachnie mi to programowaniem strukturalnym opakowanym w modele. Tzn. klasa Event musi wiedzieć wszystko o tym jak działają zamówienia, żeby móc zrealizować tę metodę. Zostawię tu propozycję tego jak ja bym to zrobił, ale nie trzeba się do tego stosować. Głównie chodzi o to, że metody mają tylko jedną odpowiedzialność i nie wiedzą za dużo o całym procesie.

class Order

def items_available?
  order_item.all? { |item| item.available? } # przydatna metoda https://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-all-3F
end

def decrease_tickets_amount!
  order_item.each do |item|
    item.decrease_amount!
end
class OrderItem

def available?
  (event.amount - amount) >= 0
end

def decrease_amount!
  event.decrease_amount_by!(amount)
end
class Event

def decrease_amount_by!(number)
  update!(amount: amount - number)
end
def do_attachment
  if @order.items_available?
    @order.decrease_tickets_amount!
    @order.update owner: current_user
  else
     # ta część tak smao jak u Pana

end

def filter_events(cat)
@results = if cat.nil?
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if cat.blank? obsłuży zarówno cat == '' jak i cat.nil?

cart = current_guest.cart
cart.update status: Order::PENDING_STATUS

cart.confirm
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread app/models/order_item.rb

def confirm
update price: event.price
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fajne, obiektowe programowanie. Każdy obiekt ma określoną odpowiedzialność.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants