Skip to content

Commit

Permalink
Merge pull request #1 from scalableinternetservices/pagination
Browse files Browse the repository at this point in the history
Pagination
  • Loading branch information
keigoomura authored Dec 15, 2024
2 parents 7b4f924 + 4803f75 commit c2162c5
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 178 deletions.
8 changes: 1 addition & 7 deletions .ebextensions/01_install_dependencies.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ commands:
install_yarn:
command: |
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
yum install -y yarn

container_commands:
seed_database:
command: |
sudo su webapp -s /bin/bash -c "cd /var/app/staging && bundle exec rails db:seed RAILS_ENV=production"
leader_only: true
yum install -y yarn
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.2.2
3.2.2
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ gem 'jwt'
gem 'rails-controller-testing'

gem 'faker'

gem 'kaminari'
152 changes: 83 additions & 69 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (7.1.5)
actionpack (= 7.1.5)
activesupport (= 7.1.5)
actioncable (7.1.5.1)
actionpack (= 7.1.5.1)
activesupport (= 7.1.5.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.1.5)
actionpack (= 7.1.5)
activejob (= 7.1.5)
activerecord (= 7.1.5)
activestorage (= 7.1.5)
activesupport (= 7.1.5)
actionmailbox (7.1.5.1)
actionpack (= 7.1.5.1)
activejob (= 7.1.5.1)
activerecord (= 7.1.5.1)
activestorage (= 7.1.5.1)
activesupport (= 7.1.5.1)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.1.5)
actionpack (= 7.1.5)
actionview (= 7.1.5)
activejob (= 7.1.5)
activesupport (= 7.1.5)
actionmailer (7.1.5.1)
actionpack (= 7.1.5.1)
actionview (= 7.1.5.1)
activejob (= 7.1.5.1)
activesupport (= 7.1.5.1)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.2)
actionpack (7.1.5)
actionview (= 7.1.5)
activesupport (= 7.1.5)
actionpack (7.1.5.1)
actionview (= 7.1.5.1)
activesupport (= 7.1.5.1)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.5)
actionpack (= 7.1.5)
activerecord (= 7.1.5)
activestorage (= 7.1.5)
activesupport (= 7.1.5)
actiontext (7.1.5.1)
actionpack (= 7.1.5.1)
activerecord (= 7.1.5.1)
activestorage (= 7.1.5.1)
activesupport (= 7.1.5.1)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.5)
activesupport (= 7.1.5)
actionview (7.1.5.1)
activesupport (= 7.1.5.1)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.5)
activesupport (= 7.1.5)
activejob (7.1.5.1)
activesupport (= 7.1.5.1)
globalid (>= 0.3.6)
activemodel (7.1.5)
activesupport (= 7.1.5)
activerecord (7.1.5)
activemodel (= 7.1.5)
activesupport (= 7.1.5)
activemodel (7.1.5.1)
activesupport (= 7.1.5.1)
activerecord (7.1.5.1)
activemodel (= 7.1.5.1)
activesupport (= 7.1.5.1)
timeout (>= 0.4.0)
activestorage (7.1.5)
actionpack (= 7.1.5)
activejob (= 7.1.5)
activerecord (= 7.1.5)
activesupport (= 7.1.5)
activestorage (7.1.5.1)
actionpack (= 7.1.5.1)
activejob (= 7.1.5.1)
activerecord (= 7.1.5.1)
activesupport (= 7.1.5.1)
marcel (~> 1.0)
activesupport (7.1.5)
activesupport (7.1.5.1)
base64
benchmark (>= 0.3)
bigdecimal
Expand All @@ -89,7 +89,7 @@ GEM
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
date (3.4.0)
date (3.4.1)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
Expand All @@ -105,13 +105,25 @@ GEM
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
io-console (0.8.0)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jwt (2.9.3)
base64
logger (1.6.1)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
logger (1.6.2)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -122,9 +134,9 @@ GEM
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.25.1)
minitest (5.25.4)
msgpack (1.7.5)
mutex_m (0.2.0)
mutex_m (0.3.0)
net-imap (0.5.1)
date
net-protocol
Expand All @@ -135,39 +147,40 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.4)
nokogiri (1.16.7-aarch64-linux)
nokogiri (1.17.1-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
nokogiri (1.17.1-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.17.1-x86_64-linux)
racc (~> 1.4)
pg (1.5.9)
psych (5.2.0)
psych (5.2.1)
date
stringio
puma (6.4.3)
puma (6.5.0)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.8)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rackup (2.2.0)
rackup (2.2.1)
rack (>= 3)
rails (7.1.5)
actioncable (= 7.1.5)
actionmailbox (= 7.1.5)
actionmailer (= 7.1.5)
actionpack (= 7.1.5)
actiontext (= 7.1.5)
actionview (= 7.1.5)
activejob (= 7.1.5)
activemodel (= 7.1.5)
activerecord (= 7.1.5)
activestorage (= 7.1.5)
activesupport (= 7.1.5)
rails (7.1.5.1)
actioncable (= 7.1.5.1)
actionmailbox (= 7.1.5.1)
actionmailer (= 7.1.5.1)
actionpack (= 7.1.5.1)
actiontext (= 7.1.5.1)
actionview (= 7.1.5.1)
activejob (= 7.1.5.1)
activemodel (= 7.1.5.1)
activerecord (= 7.1.5.1)
activestorage (= 7.1.5.1)
activesupport (= 7.1.5.1)
bundler (>= 1.15.0)
railties (= 7.1.5)
railties (= 7.1.5.1)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
Expand All @@ -176,23 +189,23 @@ GEM
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
rails-html-sanitizer (1.6.1)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.5)
actionpack (= 7.1.5)
activesupport (= 7.1.5)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
railties (7.1.5.1)
actionpack (= 7.1.5.1)
activesupport (= 7.1.5.1)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.2.1)
rdoc (6.7.0)
rdoc (6.8.1)
psych (>= 4.0.0)
reline (0.5.11)
reline (0.5.12)
io-console (~> 0.5)
securerandom (0.3.2)
securerandom (0.4.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -232,6 +245,7 @@ DEPENDENCIES
faker
importmap-rails
jwt
kaminari
pg (~> 1.5)
puma (>= 5.0)
rails (~> 7.1.2)
Expand Down
27 changes: 26 additions & 1 deletion app/assets/stylesheets/listings.css
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,29 @@
margin: 20px 0;
font-weight: 500;
text-align: center;
}
}

/* for pagination */

.pagination {
display: flex;
justify-content: center; /* Center the buttons horizontally */
align-items: center; /* Center the buttons vertically */
margin: 20px 0; /* Add some margin for spacing */
}

.pagination-button {
margin: 0 5px; /* Space between buttons */
padding: 10px 15px;
border: 1px solid #3498db;
border-radius: 5px;
color: #3498db;
background-color: white;
text-decoration: none;
transition: background-color 0.2s, color 0.2s;
}

.pagination-button:hover {
background-color: #3498db;
color: white;
}
11 changes: 7 additions & 4 deletions app/controllers/item_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class ItemController < ApplicationController
def index
@items = Item.order(created_at: :desc)
@items = Item.includes(:user, :ratings)
.order(created_at: :desc)
.page(params[:page])
.per(25)
end

def create_listing_form
Expand All @@ -25,16 +28,16 @@ def handle_create_listing
end

def show_listing
@item = Item.find(params[:id])
@ratings = @item.ratings.includes(:user).order(created_at: :desc)
@item = Item.includes(:user, ratings: :user).find(params[:id])
@ratings = @item.ratings.order(created_at: :desc)
end

def create_order
unless session[:user]
redirect_to login_path and return
end

@item = Item.find(params[:id])
@item = Item.includes(:orders).find(params[:id])

if @item.sold_out?
redirect_to item_path(@item), alert: "Sorry, this item is sold out!" and return
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def handle_register
end

def show_profile
@orders = Order.includes(:item).where(user_id: session[:user]['id'])
@listed_items = Item.where(user_id: session[:user]['id']).order(created_at: :desc)
@orders = Order.includes(item: :user)
.where(user_id: session[:user]['id'])

@listed_items = Item.includes(:orders, orders: :user)
.where(user_id: session[:user]['id'])
.order(created_at: :desc)
end
end
Loading

0 comments on commit c2162c5

Please sign in to comment.