Class: V0::OnsiteNotificationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/v0/onsite_notifications_controller.rb

Constant Summary collapse

BEARER_PATTERN =
/^Bearer /

Constants inherited from ApplicationController

ApplicationController::VERSION_STATUS

Constants included from ExceptionHandling

ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES

Instance Method Summary collapse

Methods inherited from ApplicationController

#clear_saved_form, #cors_preflight, #routing_error

Methods included from Traceable

#set_trace_tags

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Methods included from SignIn::Authentication

#authenticate, #authenticate_service_account, #load_user

Methods included from Headers

#block_unknown_hosts, #set_app_info_headers

Methods included from AuthenticationAndSSOConcerns

#authenticate, #clear_session, #extend_session!, #load_user, #log_sso_info, #render_unauthorized, #reset_session, #set_api_cookie!, #set_session_expiration_header, #sso_logging_info, #validate_inbound_login_params, #validate_session

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 33

def create
  onsite_notification = OnsiteNotification.new(
    params.require(:onsite_notification).permit(:va_profile_id, :template_id)
  )

  raise Common::Exceptions::ValidationErrors, onsite_notification unless onsite_notification.save

  render(json: onsite_notification)
end

#indexObject



13
14
15
16
17
18
19
20
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 13

def index
  clean_pagination_params
  notifications = OnsiteNotification
                  .for_user(current_user, include_dismissed: params[:include_dismissed])
                  .paginate(**pagination_params)

  render(json: notifications, meta: pagination_meta(notifications))
end

#updateObject



22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 22

def update
  onsite_notification = OnsiteNotification.find_by(id: params[:id], va_profile_id: current_user.vet360_id)
  raise Common::Exceptions::RecordNotFound, params[:id] if onsite_notification.nil?

  unless onsite_notification.update(params.require(:onsite_notification).permit(:dismissed))
    raise Common::Exceptions::ValidationErrors, onsite_notification
  end

  render(json: onsite_notification)
end