Sha256: 3ee031865b39e8877436e0b7697192445ca98124903fae45153eaef20a1411d9

Contents?: true

Size: 1.47 KB

Versions: 104

Compression:

Stored size: 1.47 KB

Contents

module Comee
  module Core
    class NotificationsController < ApplicationController
      before_action :set_notification, only: %i[mark_as_read mark_as_unread]

      def index
        data = Notification.messages(current_user.notifications.newest_first)
        render_content(data)
      end

      def read
        data = Notification.messages(current_user.notifications.read.newest_first)
        render_content(data)
      end

      def unread
        data = Notification.messages(current_user.notifications.unread.newest_first)
        render_content(data)
      end

      def mark_as_read
        @notification.mark_as_read!
        render json: {success: true, data: @notification.message}
      end

      def mark_as_unread
        @notification.mark_as_unread!
        render json: {success: true, data: @notification.message}
      end

      def notify
        NotificationMailer.with(
          user: current_user,
          recipients: notify_params[:recipients],
          subject: notify_params[:subject],
          email_body: notify_params[:body],
          files: notify_params[:files]
        ).notify.deliver_now
        render json: {success: true}
      rescue StandardError => e
        render_error(e)
      end

      private

      def set_notification
        @notification = Notification.find(params[:id])
      end

      def notify_params
        params.require(:payload).permit(:subject, :body, recipients: [], files: {filename: :file})
      end
    end
  end
end

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
comee_core-0.3.62 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.61 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.60 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.59 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.58 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.57 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.56 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.55 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.54 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.53 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.51 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.50 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.49 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.48 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.47 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.46 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.45 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.44 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.43 app/controllers/comee/core/notifications_controller.rb
comee_core-0.3.42 app/controllers/comee/core/notifications_controller.rb