Skip to content

Commit c4bd672

Browse files
committed
Move methods to AttendanceConcerns and refactor
Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
1 parent 3a3b6d8 commit c4bd672

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

app/controllers/chapter_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class ChapterController < ApplicationController
2+
include AttendanceConcerns
23
def show
34
@chapter = ChapterPresenter.new(Chapter.active.find_by!(slug: slug))
45

@@ -10,7 +11,7 @@ def show
1011
@latest_workshops = event_presenters_by_date(past_events)
1112

1213
@recent_sponsors = Sponsor.recent_for_chapter(@chapter)
13-
@attending_ids = MemberPresenter.new(current_user).attending_workshops
14+
@attending_ids = attending_workshops
1415
end
1516

1617
private
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module AttendanceConcerns
4+
extend ActiveSupport::Concern
5+
6+
def attending_workshops
7+
current_user.nil? ? Set.new : current_user.workshop_invitations.accepted.pluck(:id).to_set
8+
end
9+
10+
def attending_events
11+
current_user.nil? ? Set.new : current_user.invitations.accepted.pluck(:id).to_set
12+
end
13+
end

app/controllers/dashboard_controller.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class DashboardController < ApplicationController
2+
include AttendanceConcerns
23
before_action :is_logged_in?, only: %i[dashboard]
34
skip_before_action :accept_terms, except: %i[dashboard show]
45

@@ -8,12 +9,12 @@ class DashboardController < ApplicationController
89

910
def show
1011
@chapters = Chapter.active.all.order(:created_at)
11-
@user = MemberPresenter.new(current_user)
12+
@user = current_user ? MemberPresenter.new(current_user) : nil
1213
@upcoming_workshops = upcoming_events.map.inject({}) do |hash, (key, value)|
1314
hash[key] = EventPresenter.decorate_collection(value)
1415
hash
1516
end
16-
@attending_ids = @user.attending_workshops
17+
@attending_ids = attending_workshops
1718
@testimonials = Testimonial.order(Arel.sql('RANDOM()')).limit(5).includes(:member)
1819
end
1920

@@ -24,7 +25,7 @@ def dashboard
2425
hash
2526
end
2627
@announcements = current_user.announcements.active
27-
@attending_ids = MemberPresenter.new(current_user).attending_workshops
28+
@attending_ids = attending_workshops
2829
end
2930

3031
def code; end

app/controllers/events_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'services/ticket'
22

33
class EventsController < ApplicationController
4+
include AttendanceConcerns
45
before_action :is_logged_in?, only: %i[student coach]
56

67
RECENT_EVENTS_DISPLAY_LIMIT = 40
@@ -23,7 +24,7 @@ def index
2324
events << Event.upcoming.includes(:venue, :sponsors).all
2425
events = events.compact.flatten.sort_by(&:date_and_time).group_by(&:date)
2526
@events = events.map.inject({}) { |hash, (key, value)| hash[key] = EventPresenter.decorate_collection(value); hash }
26-
@attending_ids = MemberPresenter.new(current_user).attending_events
27+
@attending_ids = attending_events
2728
end
2829

2930
def show

app/presenters/member_presenter.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
class MemberPresenter < BasePresenter
22

3-
def initialize(current_user)
4-
@member = current_user
5-
super
6-
end
73
def organiser?
84
has_role? :organiser, :any
95
end
@@ -28,13 +24,7 @@ def pairing_details_array(role, tutorial, note)
2824
role.eql?('Coach') ? coach_pairing_details(note) : student_pairing_details(tutorial, note)
2925
end
3026

31-
def attending_workshops
32-
@member.nil? ? Set.new : workshop_invitations.accepted.pluck(:id).to_set
33-
end
3427

35-
def attending_events
36-
@member.nil? ? Set.new : invitations.accepted.pluck(:id).to_set
37-
end
3828

3929
private
4030

0 commit comments

Comments
 (0)