REFACTOR: ensures consistent naming with discourse-post-event (#26)

REFACTOR: ensures consistent naming with discourse-post-event (#26)

diff --git a/app/controllers/discourse_calendar/invitees_controller.rb b/app/controllers/discourse_calendar/invitees_controller.rb
deleted file mode 100644
index e8b3c73..0000000
--- a/app/controllers/discourse_calendar/invitees_controller.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-# frozen_string_literal: true
-
-module DiscourseCalendar
-  class InviteesController < DiscourseCalendarController
-    def index
-      post_event = PostEvent.find(params['post-event-id'])
-
-      post_event_invitees = post_event.invitees
-
-      if params[:filter]
-        post_event_invitees = post_event_invitees
-          .joins(:user)
-          .where("LOWER(users.username) LIKE :filter", filter: "%#{params[:filter].downcase}%")
-      end
-
-      if post_event.is_expired?
-        post_event_invitees = post_event_invitees.where(status: Invitee.statuses[:going])
-      end
-
-      render json: ActiveModel::ArraySerializer.new(post_event_invitees.limit(10), each_serializer: InviteeSerializer).as_json
-    end
-
-    def update
-      invitee = Invitee.find(params[:id])
-      guardian.ensure_can_act_on_invitee!(invitee)
-      status = Invitee.statuses[invitee_params[:status].to_sym]
-      invitee.update_attendance(status: status)
-      invitee.post_event.publish_update!
-      render json: InviteeSerializer.new(invitee)
-    end
-
-    def create
-      status = Invitee.statuses[invitee_params[:status].to_sym]
-      post_event = PostEvent.find(invitee_params[:post_id])
-      guardian.ensure_can_act_on_post_event!(post_event)
-      invitee = Invitee.create!(
-        status: status,
-        post_id: invitee_params[:post_id],
-        user_id: current_user.id,
-      )
-      invitee.post_event.publish_update!
-      render json: InviteeSerializer.new(invitee)
-    end
-
-    private
-
-    def invitee_params
-      params.require(:invitee).permit(:status, :post_id)
-    end
-  end
-end
diff --git a/app/controllers/discourse_calendar/post_events_controller.rb b/app/controllers/discourse_calendar/post_events_controller.rb
deleted file mode 100644
index c88d9ba..0000000
--- a/app/controllers/discourse_calendar/post_events_controller.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-# frozen_string_literal: true
-
-module DiscourseCalendar
-  class PostEventsController < DiscourseCalendarController
-    def index
-      topics = Topic.listable_topics.secured(guardian)
-      pms = Topic.private_messages_for_user(current_user)
-      post_events = PostEvent
-        .visible
-        .not_expired
-        .joins(post: :topic)
-        .merge(Post.secured(guardian))
-        .merge(topics.or(pms).distinct)
-        .order(starts_at: :asc)
-
-      render json: ActiveModel::ArraySerializer.new(
-        post_events,
-        each_serializer: PostEventSerializer,
-        scope: guardian).as_json
-    end
-
-    def invite
-      post_event = PostEvent.find(params[:id])
-      guardian.ensure_can_act_on_post_event!(post_event)
-      invites = Array(params.permit(invites: [])[:invites])
-      users = Invitee.extract_uniq_usernames(invites)
-
-      users.each do |user|
-        post_event.create_notification!(user, post_event.post)
-      end
-
-      render json: success_json
-    end
-
-    def show
-      post_event = DiscourseCalendar::PostEvent.find(params[:id])
-      guardian.ensure_can_see!(post_event.post)
-      serializer = PostEventSerializer.new(post_event, scope: guardian)
-      render_json_dump(serializer)
-    end
-
-    def destroy
-      post_event = DiscourseCalendar::PostEvent.find(params[:id])
-      guardian.ensure_can_act_on_post_event!(post_event)
-      post_event.publish_update!
-      post_event.destroy
-      render json: success_json
-    end
-
-    def update
-      DistributedMutex.synchronize("discourse-calendar[post-event-invitee-update]") do
-        post_event = DiscourseCalendar::PostEvent.find(params[:id])
-        guardian.ensure_can_edit!(post_event.post)
-        guardian.ensure_can_act_on_post_event!(post_event)
-        post_event.enforce_utc!(post_event_params)
-
-        case post_event_params[:status].to_i
-        when PostEvent.statuses[:private]
-          raw_invitees = Array(post_event_params[:raw_invitees])
-          post_event.update!(post_event_params.merge(raw_invitees: raw_invitees))
-          post_event.enforce_raw_invitees!
-        when PostEvent.statuses[:public]
-          post_event.update!(post_event_params.merge(raw_invitees: []))
-        when PostEvent.statuses[:standalone]
-          post_event.update!(post_event_params.merge(raw_invitees: []))
-          post_event.invitees.destroy_all
-        end
-
-        post_event.publish_update!
-        serializer = PostEventSerializer.new(post_event, scope: guardian)
-        render_json_dump(serializer)
-      end
-    end
-
-    def create
-      post_event = DiscourseCalendar::PostEvent.new(post_event_params)
-      guardian.ensure_can_edit!(post_event.post)
-      guardian.ensure_can_create_post_event!(post_event)
-      post_event.enforce_utc!(post_event_params)
-
-      case post_event_params[:status].to_i
-      when PostEvent.statuses[:private]
-        raw_invitees = Array(post_event_params[:raw_invitees])
-        post_event.update!(raw_invitees: raw_invitees)
-        post_event.fill_invitees!
-        post_event.notify_invitees!
-      when PostEvent.statuses[:public], PostEvent.statuses[:standalone]
-        post_event.update!(post_event_params.merge(raw_invitees: []))
-      end
-
-      post_event.publish_update!
-      serializer = PostEventSerializer.new(post_event, scope: guardian)
-      render_json_dump(serializer)
-    end
-
-    private
-
-    def post_event_params
-      params
-        .require(:post_event)
-        .permit(
-          :id,
-          :name,
-          :starts_at,
-          :ends_at,
-          :status,
-          :display_invitees,
-          raw_invitees: []
-        )
-    end
-  end
-end
diff --git a/app/controllers/discourse_calendar/upcoming_events_controller.rb b/app/controllers/discourse_calendar/upcoming_events_controller.rb
deleted file mode 100644
index 34cf446..0000000
--- a/app/controllers/discourse_calendar/upcoming_events_controller.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-# frozen_string_literal: true
-
-module DiscourseCalendar
-  class UpcomingEventsController < DiscourseCalendarController
-    def index; end
-  end
-end
diff --git a/app/controllers/discourse_calendar_controller.rb b/app/controllers/discourse_calendar_controller.rb
deleted file mode 100644
index 094c45c..0000000
--- a/app/controllers/discourse_calendar_controller.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-module DiscourseCalendar
-  class DiscourseCalendarController < ::ApplicationController
-    before_action :ensure_logged_in
-
-    before_action :ensure_post_event_enabled
-    def ensure_post_event_enabled
-      if !SiteSetting.post_event_enabled
-        raise Discourse::NotFound
-      end
-    end
-  end
-end
diff --git a/app/controllers/discourse_post_event/events_controller.rb b/app/controllers/discourse_post_event/events_controller.rb
new file mode 100644
index 0000000..9924625
--- /dev/null
+++ b/app/controllers/discourse_post_event/events_controller.rb
@@ -0,0 +1,112 @@
+# frozen_string_literal: true
+
+module DiscoursePostEvent
+  class EventsController < DiscoursePostEventController
+    def index
+      topics = Topic.listable_topics.secured(guardian)
+      pms = Topic.private_messages_for_user(current_user)
+      events = Event
+        .visible
+        .not_expired
+        .joins(post: :topic)
+        .merge(Post.secured(guardian))
+        .merge(topics.or(pms).distinct)
+        .order(starts_at: :asc)
+
+      render json: ActiveModel::ArraySerializer.new(
+        events,
+        each_serializer: EventSerializer,
+        scope: guardian).as_json
+    end
+
+    def invite
+      event = Event.find(params[:id])
+      guardian.ensure_can_act_on_event!(event)

[... diff too long, it was truncated ...]

GitHub sha: 5665832f

This commit appears in #26 which was merged by jjaffeux.