39. def buy
@product = Product.find params[:id]
if @product.pro or
not @product.user.is_a? Shop or
current_user.email.split('.')[-1] == 'com'
flash[:alert] = "You can't buy this product"
else
photos = RestClient.get 'http://jsonplaceholder.typicode.com/photos/'
photo = JSON.parse(photos).sample
thumbnail = photo['thumbnailUrl']
url = photo['url']
thumbnail_color = thumbnail.split('/')[-1].to_i 16
url_color = url.split('/')[-1].to_i 16
if thumbnail_color > url_color
flash[:alert] = 'An error happened'
BuyMailer.admins_buy_fail(current_user).deliver_now!
else
flash[:notice] = 'Success'
BuyMailer.user_buy_success(current_user, url).deliver_now!
todos = RestClient.post 'http://jsonplaceholder.typicode.com/todos', {}
todo_id = JSON.parse(todos)['id']
BuyMailer.admins_buy_success(todo_id).deliver_now!
end
end
redirect_to :back
end
40. def buy
@product = Product.find(params[:id])
if current_user.can_buy?
if @product.sell_able?
photo_url = get_photo
if photo_url.nil?
flash[:alert] = "Sorry, _you_ can't buy this product. Try again later"
AdministratorMailer.buy_error(current_user.email).deliver_later
redirect_to :back
else
post = HTTParty.post("http://jsonplaceholder.typicode.com/todos")
post_id = post['id']
AdministratorMailer.successfull_buy(post_id).deliver_later
UserMailer.successfull_buy(current_user, photo_url).deliver_later
redirect_to(:back)
end
else
flash[:alert] = "Sorry, we can't sell _this_ product"
redirect_to :back
end
else
flash[:alert] = "Sorry, _you_ cant buy _anything_"
redirect_to(:back)
end
end
41. Common mistakes:
1. Ignoring levels of abstraction
2. Gemification
3. Nowbody knows about service objects
4. Put business logic in random places
5. Bad naming
42. Next steps:
1. Group hangout codereview
2. Lecture about patterns
3. Refactoring
4. Cross code review
70. → routine tasks
→ research tasks
→ nice to have features
→ low priority features
→ missing features in their
favorite open source
project
→ side project ideas
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84. If I do it again:
→ more "tests"
→ call for mentors
→ turn mentor's experience into their
"tests"
→ reject newbies