summaryrefslogtreecommitdiff
path: root/app/controllers/user_callouts_controller.rb
blob: 06f422b9d90ee590a1cb04cce6d66dee4d55b00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class UserCalloutsController < ApplicationController
  def create
    callout = ensure_callout

    if callout.persisted?
      callout.update(dismissed_at: Time.current)
      respond_to do |format|
        format.json { head :ok }
      end
    else
      respond_to do |format|
        format.json { head :bad_request }
      end
    end
  end

  private

  # rubocop: disable CodeReuse/ActiveRecord
  def ensure_callout
    current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name])
  end
  # rubocop: enable CodeReuse/ActiveRecord

  def feature_name
    params.require(:feature_name)
  end
end