Skip to content

Commit d3997ee

Browse files
committed
Added Code comment
1 parent 8c61e18 commit d3997ee

File tree

6 files changed

+3207
-4
lines changed

6 files changed

+3207
-4
lines changed

app/controllers/listings_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ class ListingsController < ApplicationController
44
before_action :set_listing, only: [:show, :favourite]
55

66
def index()
7-
#Set search condition to only listings that HAVE NOT been purchased
8-
@search = Listing.where(purchased: false).search(params[:q])
7+
#Set search condition and display all listings to only listings that HAVE NOT been purchased.
98

10-
#Show listings that HAVE NOT been purchased
9+
@search = Listing.where(purchased: false).search(params[:q])
1110
@listings = @search.result.paginate(page: params[:page], per_page: 16).order("id DESC")
1211
end
1312

@@ -90,6 +89,7 @@ def destroy()
9089
end
9190

9291
def favourite()
92+
# Add or remove the current user's favourite listing. The listing is either INSERTED or REMOVED from the favourites table.
9393
type = params[:type]
9494
if type == "favourite"
9595
current_user.favourites << @listing

app/controllers/pages_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class PagesController < ApplicationController
22
def home()
3+
#Only show the latest listings that have not been purchased.
34
@listings = Listing.where(purchased: false).last(4)
45
end
56

app/controllers/payments_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class PaymentsController < ApplicationController
22
skip_before_action :verify_authenticity_token, only: [:webhook]
33

44
def success()
5+
#Return the user's latest purchase.
56
@purchase = current_user.purchases.last
67
@listing = current_user.purchases.last.listing
78
end
@@ -14,6 +15,7 @@ def webhook()
1415

1516
@listing = Listing.find_by_id(listing_id).update(purchased: :true)
1617

18+
#Create a new record in the Purchase table when payment has been made.
1719
Purchase.create(
1820
user_id: user_id,
1921
listing_id: listing_id,

app/controllers/users_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ def favourites()
1111
end
1212

1313
def purchases()
14+
# Show user purchases sorted in DESCENDING order.
1415
@purchases = current_user.purchases.order("id DESC")
1516
end
1617

1718
def listings()
19+
# Show user listings sorted in DESCENDING order.
1820
@listings = current_user.listings.order("id DESC")
1921
end
2022

app/views/listings/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<%= form.submit "Search", class: " btn btn-primary" %>
1212
</div>
1313
</div>
14-
1514
<% end %>
15+
1616
<div class="sort-links-container">
1717
<div class="sort-links">
1818
<%= sort_link @search, :title, "Title" %>

0 commit comments

Comments
 (0)