Skip to content

Commit

Permalink
feat: opponent team + cloudinary storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Annastacia-dev committed Apr 8, 2024
1 parent 6305cc4 commit e61d179
Show file tree
Hide file tree
Showing 47 changed files with 630 additions and 15 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ gem 'font-awesome-sass', '~> 6.4.0'
gem 'devise', '~> 4.9', '>= 4.9.2'

gem 'cancancan'
gem 'cloudinary', '~> 1.29.0'

gem 'faker', '~> 3.2'
gem 'motor-admin'
Expand Down
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ GEM
audited (5.4.3)
activerecord (>= 5.0, < 7.2)
request_store (~> 1.2)
aws_cf_signer (0.1.3)
bcrypt (3.1.20)
bindex (0.8.1)
bootsnap (1.18.3)
Expand All @@ -89,6 +90,9 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cloudinary (1.29.0)
aws_cf_signer
rest-client (>= 2.0.0)
concurrent-ruby (1.2.3)
crass (1.0.6)
date (3.3.4)
Expand All @@ -101,6 +105,7 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
domain_name (0.6.20240107)
erubi (1.12.0)
et-orbi (1.2.9)
tzinfo
Expand All @@ -118,6 +123,9 @@ GEM
rails (>= 6.0.0)
stimulus-rails
turbo-rails
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
Expand All @@ -144,6 +152,9 @@ GEM
marcel (1.0.4)
matrix (0.4.2)
method_source (1.0.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0305)
mini_mime (1.1.5)
minitest (5.22.3)
motor-admin (0.4.26)
Expand All @@ -162,6 +173,7 @@ GEM
timeout
net-smtp (0.4.0.1)
net-protocol
netrc (0.11.0)
nio4r (2.7.0)
nokogiri (1.16.3-aarch64-linux)
racc (~> 1.4)
Expand Down Expand Up @@ -232,6 +244,11 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.6)
rubocop (1.62.1)
json (~> 2.3)
Expand Down Expand Up @@ -318,6 +335,7 @@ DEPENDENCIES
bootsnap
cancancan
capybara
cloudinary (~> 1.29.0)
debug
devise (~> 4.9, >= 4.9.2)
faker (~> 3.2)
Expand Down
70 changes: 70 additions & 0 deletions app/controllers/hall_of_fames_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class HallOfFamesController < ApplicationController
before_action :set_hall_of_fame, only: %i[ show edit update destroy ]

# GET /hall_of_fames or /hall_of_fames.json
def index
@hall_of_fames = HallOfFame.all
end

# GET /hall_of_fames/1 or /hall_of_fames/1.json
def show
end

# GET /hall_of_fames/new
def new
@hall_of_fame = HallOfFame.new
end

# GET /hall_of_fames/1/edit
def edit
end

# POST /hall_of_fames or /hall_of_fames.json
def create
@hall_of_fame = HallOfFame.new(hall_of_fame_params)

respond_to do |format|
if @hall_of_fame.save
format.html { redirect_to hall_of_fame_url(@hall_of_fame), notice: "Hall of fame was successfully created." }
format.json { render :show, status: :created, location: @hall_of_fame }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @hall_of_fame.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /hall_of_fames/1 or /hall_of_fames/1.json
def update
respond_to do |format|
if @hall_of_fame.update(hall_of_fame_params)
format.html { redirect_to hall_of_fame_url(@hall_of_fame), notice: "Hall of fame was successfully updated." }
format.json { render :show, status: :ok, location: @hall_of_fame }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @hall_of_fame.errors, status: :unprocessable_entity }
end
end
end

# DELETE /hall_of_fames/1 or /hall_of_fames/1.json
def destroy
@hall_of_fame.destroy

respond_to do |format|
format.html { redirect_to hall_of_fames_url, notice: "Hall of fame was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_hall_of_fame
@hall_of_fame = HallOfFame.find(params[:id])
end

# Only allow a list of trusted parameters through.
def hall_of_fame_params
params.require(:hall_of_fame).permit(:team_id)
end
end
2 changes: 1 addition & 1 deletion app/controllers/opponent_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def update
private

def opponent_params
params.require(:opponent).permit(:match_date, :match_time, :venue, :tournament, :score_one, :score_two, :user_id)
params.require(:opponent).permit(:match_date, :match_time, :venue, :tournament, :score_one, :score_two, :user_id, :opponent_team_id)
end
end
70 changes: 70 additions & 0 deletions app/controllers/opponent_teams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class OpponentTeamsController < ApplicationController
before_action :set_opponent_team, only: %i[ show edit update destroy ]

# GET /opponent_teams or /opponent_teams.json
def index
@opponent_teams = OpponentTeam.all
end

# GET /opponent_teams/1 or /opponent_teams/1.json
def show
end

# GET /opponent_teams/new
def new
@opponent_team = OpponentTeam.new
end

# GET /opponent_teams/1/edit
def edit
end

# POST /opponent_teams or /opponent_teams.json
def create
@opponent_team = OpponentTeam.new(opponent_team_params)

respond_to do |format|
if @opponent_team.save
format.html { redirect_to opponent_team_url(@opponent_team), notice: "Opponent team was successfully created." }
format.json { render :show, status: :created, location: @opponent_team }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @opponent_team.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /opponent_teams/1 or /opponent_teams/1.json
def update
respond_to do |format|
if @opponent_team.update(opponent_team_params)
format.html { redirect_to opponent_team_url(@opponent_team), notice: "Opponent team was successfully updated." }
format.json { render :show, status: :ok, location: @opponent_team }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @opponent_team.errors, status: :unprocessable_entity }
end
end
end

# DELETE /opponent_teams/1 or /opponent_teams/1.json
def destroy
@opponent_team.destroy

respond_to do |format|
format.html { redirect_to opponent_teams_url, notice: "Opponent team was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_opponent_team
@opponent_team = OpponentTeam.find(params[:id])
end

# Only allow a list of trusted parameters through.
def opponent_team_params
params.require(:opponent_team).permit(:name, :team_url, :team_badge)
end
end
2 changes: 2 additions & 0 deletions app/helpers/hall_of_fames_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HallOfFamesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/opponent_teams_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module OpponentTeamsHelper
end
3 changes: 3 additions & 0 deletions app/models/hall_of_fame.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class HallOfFame < ApplicationRecord
belongs_to :team
end
1 change: 1 addition & 0 deletions app/models/opponent.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Opponent < ApplicationRecord
belongs_to :user
belongs_to :opponent_team
end
6 changes: 6 additions & 0 deletions app/models/opponent_team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class OpponentTeam < ApplicationRecord
has_one_attached :team_badge

validates :name, presence: true
validates :team_badge, presence: true
end
22 changes: 22 additions & 0 deletions app/views/hall_of_fames/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= form_with(model: hall_of_fame, class: "contents") do |form| %>
<% if hall_of_fame.errors.any? %>
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
<h2><%= pluralize(hall_of_fame.errors.count, "error") %> prohibited this hall_of_fame from being saved:</h2>

<ul>
<% hall_of_fame.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="my-5">
<%= form.label :team_id %>
<%= form.text_field :team_id, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>

<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
</div>
<% end %>
12 changes: 12 additions & 0 deletions app/views/hall_of_fames/_hall_of_fame.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="<%= dom_id hall_of_fame %>">
<p class="my-5">
<strong class="block font-medium mb-1">Team:</strong>
<%= hall_of_fame.team_id %>
</p>

<% if action_name != "show" %>
<%= link_to "Show this hall of fame", hall_of_fame, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to "Edit this hall of fame", edit_hall_of_fame_path(hall_of_fame), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
<hr class="mt-6">
<% end %>
</div>
2 changes: 2 additions & 0 deletions app/views/hall_of_fames/_hall_of_fame.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! hall_of_fame, :id, :team_id, :created_at, :updated_at
json.url hall_of_fame_url(hall_of_fame, format: :json)
8 changes: 8 additions & 0 deletions app/views/hall_of_fames/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">Editing hall of fame</h1>

<%= render "form", hall_of_fame: @hall_of_fame %>
<%= link_to "Show this hall of fame", @hall_of_fame, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to "Back to hall of fames", hall_of_fames_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>
14 changes: 14 additions & 0 deletions app/views/hall_of_fames/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="w-full">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>

<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl">Hall of fames</h1>
<%= link_to "New hall of fame", new_hall_of_fame_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div>

<div id="hall_of_fames" class="min-w-full">
<%= render @hall_of_fames %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/hall_of_fames/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @hall_of_fames, partial: "hall_of_fames/hall_of_fame", as: :hall_of_fame
7 changes: 7 additions & 0 deletions app/views/hall_of_fames/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">New hall of fame</h1>

<%= render "form", hall_of_fame: @hall_of_fame %>
<%= link_to "Back to hall of fames", hall_of_fames_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>
15 changes: 15 additions & 0 deletions app/views/hall_of_fames/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="mx-auto md:w-2/3 w-full flex">
<div class="mx-auto">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>
<%= render @hall_of_fame %>
<%= link_to "Edit this hall_of_fame", edit_hall_of_fame_path(@hall_of_fame), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<div class="inline-block ml-2">
<%= button_to "Destroy this hall_of_fame", hall_of_fame_path(@hall_of_fame), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
</div>
<%= link_to "Back to hall_of_fames", hall_of_fames_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/hall_of_fames/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "hall_of_fames/hall_of_fame", hall_of_fame: @hall_of_fame
4 changes: 2 additions & 2 deletions app/views/opponent/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</div>
<div class="flex flex-col justify-center mb-10 text-5xl ml-10">vs</div>
<div class="align-center hidden md:flex flex-col ml-10">
<%= image_tag "wazitologo", class: " w-40" %>
<p class="ml-10">Wazito FC</p>
<%= image_tag (opp.opponent_team.team_badge), class: " w-40" %>
<p class="ml-10"><%= opp.opponent_team.name %></p>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/opponent/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<%= f.text_field :venue, class: "h-[50px] flex items-center p-2 w-[45%] border-b bg-[#F7F3ED] border-black focus:outline-none" ,placeholder: "Venue" %>
<%= f.text_field :tournament, class: "h-[50px] flex items-center p-2 w-[45%] border-b bg-[#F7F3ED] border-black focus:outline-none" ,placeholder: "Tournament" %>
</div>
<div class="flex justify-between">
<%= f.text_field :opponent, class: "h-[50px] flex items-center p-2 w-[30%] border-b bg-[#F7F3ED] border-black focus:outline-none" ,placeholder: "Opponent" %>
<div class="flex justify-between gap-3">
<%= f.collection_select :opponent_team_id, OpponentTeam.all, :id, :name, {prompt: "Select Opponent Team"}, class: "h-[50px] flex items-center p-2 w-[45%] border-b bg-[#F7F3ED] border-black focus:outline-none" %>
<%= f.number_field :score_one, class: "h-[50px] flex items-center p-2 w-[30%] border-b bg-[#F7F3ED] border-black focus:outline-none" ,placeholder: "Home Team Score" %>
<%= f.number_field :score_two, class: "h-[50px] flex items-center p-2 w-[30%] border-b bg-[#F7F3ED] border-black focus:outline-none" ,placeholder: "Away Team Score" %>

Expand Down
32 changes: 32 additions & 0 deletions app/views/opponent_teams/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= form_with(model: opponent_team, class: "contents") do |form| %>
<% if opponent_team.errors.any? %>
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
<h2><%= pluralize(opponent_team.errors.count, "error") %> prohibited this opponent_team from being saved:</h2>

<ul>
<% opponent_team.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="my-5">
<%= form.label :name %>
<%= form.text_field :name, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>

<div class="my-5">
<%= form.label :team_url %>
<%= form.text_field :team_url, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>

<div class="my-5">
<%= form.label :team_badge %>
<%= form.file_field :team_badge, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>

<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
</div>
<% end %>
Loading

0 comments on commit e61d179

Please sign in to comment.