Skip to content
Open
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
8bac5b0
minor fixes
techiealiraza Jun 2, 2023
9685bc3
Merge branch 'develop' of https://github.com/techiealiraza/rock-pappe…
techiealiraza Jun 2, 2023
c63eb8b
refactored
progammer743 Jun 4, 2023
eab445d
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 4, 2023
f4578e3
leaderBoard query optimized
progammer743 Jun 5, 2023
b8703d4
session find_by_email
techiealiraza Jun 5, 2023
f443726
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
30a66ca
enum roles defined
progammer743 Jun 5, 2023
0a4d12c
find removed from tournament_index_view
progammer743 Jun 5, 2023
c1be315
session controller fixed
techiealiraza Jun 5, 2023
a906740
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
503a783
session controller
techiealiraza Jun 5, 2023
b15f867
matches index
techiealiraza Jun 5, 2023
ce66ae2
offset issue resolved
progammer743 Jun 5, 2023
17b17d3
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 5, 2023
1e770b0
undefined winner name fixed
progammer743 Jun 5, 2023
d419bcb
brackets and spacings
techiealiraza Jun 5, 2023
0f93138
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
ee7e900
rename column name match_time to time & message to content
progammer743 Jun 5, 2023
0bb6c22
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 5, 2023
03e7102
selection name in selections to choice
progammer743 Jun 5, 2023
34544af
renamed column from match_winner_id to winner_id
progammer743 Jun 5, 2023
26f80da
rename column tournament_winner_id to winner_id
progammer743 Jun 5, 2023
6e93ee0
session fixes
techiealiraza Jun 5, 2023
fb05e39
Session Fixes
techiealiraza Jun 5, 2023
6f011a7
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
0c55f34
session fixed
techiealiraza Jun 5, 2023
5f7824b
removed unused params method from matches_controller
progammer743 Jun 5, 2023
ae05494
removed winner
progammer743 Jun 5, 2023
6bf4edf
added params to matcehs
progammer743 Jun 5, 2023
2c5342f
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 5, 2023
058b238
removed params & aincludes winner
progammer743 Jun 5, 2023
37efbda
includes user in selections
progammer743 Jun 5, 2023
9f9d99c
choices updated in match model
progammer743 Jun 5, 2023
a8106b7
validation
techiealiraza Jun 5, 2023
3b8b882
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
b7c4da4
controller load_and_authorize fixed
techiealiraza Jun 6, 2023
432274d
comments resolved
progammer743 Jun 6, 2023
6eed13c
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 6, 2023
ff31f54
removed un-used code & refactored
progammer743 Jun 6, 2023
83f6818
removed unused scopes
progammer743 Jun 7, 2023
6206f9a
space removed
techiealiraza Jun 7, 2023
dd56a25
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 7, 2023
0293f8a
replaced ' with " for consistency
techiealiraza Jun 7, 2023
483fc73
' ' to "" changed
techiealiraza Jun 7, 2023
0c33b29
renamed partial of choice_image
progammer743 Jun 7, 2023
01f5de8
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 7, 2023
014230d
selection ability updated
progammer743 Jun 7, 2023
6c6f70e
deleted unnecessary files
techiealiraza Jun 7, 2023
dc3db55
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 7, 2023
8984936
removed comment from load_controller.js
progammer743 Jun 7, 2023
2496747
text size responsiveness in choice_timer
progammer743 Jun 7, 2023
d174db3
added scopes in tournament model
progammer743 Jun 7, 2023
f241a91
resolved commits
progammer743 Jun 7, 2023
ba5eec0
match controller + views updated
progammer743 Jun 7, 2023
b719e16
message controller
techiealiraza Jun 8, 2023
0371c6b
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 8, 2023
1290b14
added match done/un_done scopes in match model
progammer743 Jun 8, 2023
e2d3948
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 8, 2023
585f57c
respond_to fixed
techiealiraza Jun 8, 2023
15612e2
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 8, 2023
4f3dfe8
comments resolved
progammer743 Jun 8, 2023
91d0fd9
renamed tournamentMatchCreator & removed un-used methods from tournam…
progammer743 Jun 8, 2023
c6a32e8
refactored and added js views for create action of msg and selection
progammer743 Jun 9, 2023
88f3d63
image validation added
techiealiraza Jun 9, 2023
ecf5719
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 9, 2023
08bc5e4
Image Validations
techiealiraza Jun 9, 2023
3e8540e
refactored code
progammer743 Jun 9, 2023
52f176e
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 9, 2023
a6a1c91
updated variables_names & refactored
progammer743 Jun 9, 2023
78a4d85
removed un-used includes
progammer743 Jun 9, 2023
b67c214
gem file
techiealiraza Jun 11, 2023
1b0599e
followed camelCase in js & moved model code from Delayed Job
progammer743 Jun 11, 2023
4f743c0
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 11, 2023
7e7f7f8
validation
techiealiraza Jun 12, 2023
b429d5a
image validation
techiealiraza Jun 12, 2023
d4b5ea9
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
ad41d0e
after perform of MAtch Play job is moved to Service
progammer743 Jun 12, 2023
9b2f84c
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 12, 2023
a670aa2
added callback to selection create & removed user_id hidden field mes…
progammer743 Jun 12, 2023
9db7725
rename un_done to undone
progammer743 Jun 12, 2023
f1deb15
DRY
techiealiraza Jun 12, 2023
8485ce0
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
372a718
removed unused method from the match model
progammer743 Jun 12, 2023
98d4da9
wrong route error handled
techiealiraza Jun 12, 2023
be4de17
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
994534e
rename play_match_channel to match_channel
progammer743 Jun 12, 2023
b920d12
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
68bd19a
gem file
techiealiraza Jun 12, 2023
310e49b
removed unused gems
progammer743 Jun 12, 2023
f2bfc57
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 12, 2023
ab8dc1e
gem
techiealiraza Jun 12, 2023
6a66a0c
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
4d1895a
session alert problem fixed
techiealiraza Jun 12, 2023
bdd4890
refactored and removed unused code
progammer743 Jun 12, 2023
ea00633
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 12, 2023
bef894f
refactored code
progammer743 Jun 13, 2023
2b94b97
removed unused code from match.rb
progammer743 Jun 13, 2023
6e79e22
routes fixed
techiealiraza Jun 13, 2023
c3a9139
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
2b1225a
updated routes
progammer743 Jun 13, 2023
7565948
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
0f8f132
un comment routing error
techiealiraza Jun 13, 2023
62f5f9e
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
45b855e
remove unused code
techiealiraza Jun 13, 2023
30e9daa
Session controller fixed
techiealiraza Jun 13, 2023
23a5259
nested selection under the matches
progammer743 Jun 13, 2023
13c8925
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
e6a7369
js files refactoring
techiealiraza Jun 13, 2023
f9f9869
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
1fee544
fixed typo in touranment's form
progammer743 Jun 13, 2023
ab8f4c7
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
9a0677d
removed unused code from tailwind.config.js
progammer743 Jun 13, 2023
ac69b3f
use assets instead of online images in edit file of registration
progammer743 Jun 13, 2023
d0fe754
added routes paths in new of registration and session files
progammer743 Jun 13, 2023
405a2f6
replace all Sign in to Log in
progammer743 Jun 13, 2023
fe6bb12
fixed typo
progammer743 Jun 13, 2023
23102af
added validation in selection
progammer743 Jun 13, 2023
0baa2e3
fixes view issues show matches/tournaments
progammer743 Jun 13, 2023
e74bf13
views fixed
techiealiraza Jun 13, 2023
f4b6b42
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
d369859
session controller invalid password msg updated
progammer743 Jun 13, 2023
6e124f0
tournaments path and render fixed
techiealiraza Jun 13, 2023
74551ce
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
6db77ce
gwm file lock fixed
techiealiraza Jun 13, 2023
f19dcd3
updated Gemfile.lock and renamed broadcaster to action_cable_broadcaster
progammer743 Jun 13, 2023
a4fffae
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
58d64af
match scores fix
techiealiraza Jun 14, 2023
db3f218
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'letter_opener', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
Expand All @@ -39,6 +33,8 @@ end

group :development do
gem 'bullet', '~> 7.0'
gem 'delayed_job_web', '~> 1.4.4', require: 'delayed_job_active_record'
gem 'letter_opener'

# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
Expand Down Expand Up @@ -70,9 +66,6 @@ gem 'tailwindcss-rails', '~> 2.0'

gem 'devise-two-factor', '~> 4.0'

gem 'dotenv-rails'
gem 'rqrcode', '~> 2.1'

gem 'stimulus-rails'

gem 'hotwire-rails', '~> 0.1.3'
Expand All @@ -88,7 +81,6 @@ gem 'attr_encrypted', '~> 3.1'

gem 'daemons'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ali -> Code Understanding

gem 'delayed_job_active_record'
gem 'delayed_job_web', '~> 1.4.4', require: 'delayed_job_active_record'

gem 'twilio-ruby', '~> 5.77'

Expand Down
8 changes: 8 additions & 0 deletions app/channels/match_channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# channel for timer and selection
class MatchChannel < ApplicationCable::Channel
def subscribed
stream_from "match_channel_#{params[:match_id]}"
end
end
8 changes: 0 additions & 8 deletions app/channels/timer_channel.rb

This file was deleted.

12 changes: 11 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
rescue_from CanCan::AccessDenied, with: :access_denied
rescue_from ActionController::RoutingError, with: :render_not_found

def access_denied
render file: "#{Rails.root}/public/403.html", formats: [:html], status: 403, layout: false
Expand All @@ -14,10 +15,19 @@ def record_not_found
render file: "#{Rails.root}/public/404.html", formats: [:html], status: 404, layout: false
end

def render_not_found
redirect_to root_path, alert: 'The page you requested was not found.'
end

def devise_controller?
is_a?(Devise::SessionsController)
end

def handle_not_found
# Handle the request and display an error message
render file: "#{Rails.root}/public/404.html", formats: [:html], status: 404, layout: false
end

protected

def after_resetting_password_path_for(user)
Expand All @@ -26,7 +36,7 @@ def after_resetting_password_path_for(user)

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: %i[name email password phone_number])
devise_parameter_sanitizer.permit(:account_update, keys: %i[name email password phone_number avatar])
devise_parameter_sanitizer.permit(:account_update, keys: %i[name email password phone_number image])
devise_parameter_sanitizer.permit(:sign_in, keys: [:otp_attempt])
end
end
29 changes: 8 additions & 21 deletions app/controllers/matches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# Matches_Controller

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

RESTFul Routes comments

index -> should have been a nested route tournaments/id/matches/

class MatchesController < ApplicationController
load_and_authorize_resource :tournament
load_and_authorize_resource through: :tournament
Expand All @@ -16,31 +15,19 @@ def all

def show; end

def new
@match = Match.new
end

def playmatch
@match = Match.includes([:users]).find(params[:match_id])
redirect_to result_tournament_match_path(match_id: @match) unless @match.match_winner_id.nil?
@players = @match.users
@remaining_tries = @match.remaining_tries(@players.first.id)
@done_tries = @match.selections.by_user(@players.first.id).size
@is_player = @match.users.include?(current_user)
@messages = @match.messages.includes([:user]).all.reverse
end
return if @match.done?

def result
@is_player = @match.users.include?(current_user)
@players = @match.users
@players_selections = @match.selections.order(:try_num).group_by(&:user_id)
@players_scores = @match.selections.group(:user_id).winner.count
@result_message = @match.result_message(current_user.id)
@players_data = @match.users.pluck(:id, :name).to_h
end

private
def result
return if @match.undone?

def match_params
params.require(:match).permit(:match_winner_id, :winner_score, :match_time, :tournament_id)
@players_data = @match.users.pluck(:id, :name).to_h
@players_selections = @match.selections.includes(:user).order(:try_num).group_by(&:user_id)
@players_scores = @match.selections.winner.group(:user_id).count
@result_message = @match.result_message(current_user.id)
end
end
18 changes: 6 additions & 12 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@

class MessagesController < ApplicationController
load_and_authorize_resource
def index; end

def new
@message = Message.new
end

def create
@message = Message.new(message_params)
respond_to do |format|
if @message.save
format.json { render json: { data: 'Saved' }, status: :ok }
else
format.json { render json: { errors: @message.errors.full_messages }, status: :unprocessable_entity }
end
@message.user_id = current_user.id
if @message.save
flash[:notice] = 'Message Sent'
else
flash[:error] = @message.errors.full_messages.join(', ')
end
end

private

def message_params
params.permit(:user_id, :match_id, :message)
params.permit(:match_id, :content)
end
end
19 changes: 7 additions & 12 deletions app/controllers/selection_controller.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# frozen_string_literal: true

class SelectionController < ApplicationController
load_and_authorize_resource
before_action :authenticate_user!

def create
@selection = Selection.new(selection_params)
@selection.add_try_num
respond_to do |format|
if @selection.save
format.json { render json: { data: 'Saved' }, status: :ok }
else
format.json { render json: { errors: @selection.errors.full_messages }, status: :unprocessable_entity }
end
if @selection.save
flash[:notice] = 'Choice Saved'
else
flash[:error] = @selection.errors.full_messages.join(', ')
end
end

def new
@selection = Selection.new
end

private

def selection_params
params.require(:selection).permit(:match_id, :user_id, :selection)
params.require(:selection).permit(:match_id, :user_id, :choice)
end
end
65 changes: 30 additions & 35 deletions app/controllers/tournaments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,72 +1,67 @@
# Tournamnets Controller
# frozen_string_literal: true

class TournamentsController < ApplicationController
load_and_authorize_resource
before_action :authenticate_user!, except: [:index]

def index
@tournaments = Tournament.includes(:users).all
@tournaments = Tournament.includes(%i[users winner]).all
@tournaments = @tournaments.order(:registration_deadline).page(params[:page])
end

def show; end

def new
@tournament = Tournament.new
end
def new; end

def edit; end

def register
@tournaments_user = TournamentsUser.new(user: current_user, tournament: @tournament)
if @tournaments_user.save
redirect_to tournament_url(@tournament), notice: 'You have registered for the tournament!'
flash[:notice] = 'You have registered for the tournament!.'
else
redirect_to tournament_url(@tournament), notice: 'Already Registered'
flash[:errors] = @tournament.errors.full_messages.join(', ')
end
redirect_to tournament_url(@tournament)
end

def create_matches
registered_users = @tournament.users
length = registered_users.length
return unless (length - 8) != 0

begin

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MatchCreator.new(@tournament, registered_users).create_match
redirect_to tournament_path(@tournament), notice: 'Matches Generated'
TournamentMatchesCreator.new(@tournament, @tournament.users).call
flash[:notice] = 'Matches Generated.'
rescue StandardError => e
redirect_to tournament_path(@tournament), alert: "Error generating matches: #{e.message}"
flash[:alert] = "Error generating matches: #{e.message}"
end
redirect_to tournament_path(@tournament)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this line is repeating. You can DRY it ?

end

def create
@tournament = Tournament.new(tournament_params)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Load everything using cancancan, This is missing in some other places as well

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

respond_to do |format|
if @tournament.save
format.html { redirect_to tournament_url(@tournament), notice: 'Tournament was successfully created.' }
else
format.html { render :new, status: :unprocessable_entity }
end
if @tournament.save
flash[:notice] = 'Tournament was successfully created.'
redirect_to tournament_url(@tournament)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_path vs _url ?
Why url ?

else
flash[:errors] = @tournament.errors.full_messages.join(', ')
render :new
end
end

def update
respond_to do |format|
if @tournament.update(tournament_params)
format.html { redirect_to tournament_url(@tournament), notice: 'Tournament was successfully updated.' }
else
format.html { render :edit, status: :unprocessable_entity }
end
if @tournament.update(tournament_params)
flash[:notice] = 'Tournament was successfully updated.'
redirect_to tournament_url(@tournament)
else
flash[:errors] = @tournament.errors.full_messages.join(', ')
render :edit
end
end

def destroy
respond_to do |format|
if @tournament.destroy
format.html { redirect_to tournaments_url, notice: 'Tournament was successfully deleted.' }
else
format.html { render :edit, status: :unprocessable_entity }
end
if @tournament.destroy
flash[:notice] = 'Tournament was successfully deleted.'
redirect_to tournaments_url
else
flash[:errors] = @tournament.errors.full_messages.join(', ')
render :index

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

render -> index is wrong

end
end

Expand All @@ -77,7 +72,7 @@ def tournament_params
:description,
:start_date,
:end_date,
:tournament_winner_id,
:winner_id,
:image,
:registration_deadline)
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/users/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def show
end
end

# protected
protected

def after_confirmation_path_for(_resource_name, resource)
sign_in(resource)
root_path
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def after_sign_up_path_for(_resource)
end

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: %i[avatar name phone_number])
devise_parameter_sanitizer.permit(:account_update, keys: %i[avatar name phone_number])
devise_parameter_sanitizer.permit(:sign_up, keys: %i[image name phone_number])
devise_parameter_sanitizer.permit(:account_update, keys: %i[image name phone_number])
end
end
Loading