Class: LsaTdxFeedback::FeedbackController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/lsa_tdx_feedback/feedback_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/lsa_tdx_feedback/feedback_controller.rb', line 6

def create
  ticket_client = TicketClient.new

  # Build the title and include the app name if available
  title = feedback_params[:title].presence || "User Feedback - #{feedback_params[:category]}"

  if defined?(@lsa_tdx_feedback_app_name) && @lsa_tdx_feedback_app_name.present?
    title = "[#{@lsa_tdx_feedback_app_name}]: #{title}"
  end

  feedback_data = {
    title: title,
    feedback: feedback_params[:feedback],
    category: feedback_params[:category],
    email: feedback_params[:email],
    url: feedback_params[:url],
    user_agent: feedback_params[:user_agent],
    additional_info: feedback_params[:additional_info],
    priority_id: priority_from_category(feedback_params[:category])
  }

  begin
    ticket_response = ticket_client.create_feedback_ticket(feedback_data)

    render json: {
      success: true,
      message: 'Thank you for your feedback! Your ticket has been created.',
      ticket_id: ticket_response['ID']
    }, status: :created
  rescue LsaTdxFeedback::Error => e
    Rails.logger.error "LsaTdxFeedback Error: #{e.message}"

    render json: {
      success: false,
      message: 'Sorry, there was an error submitting your feedback. Please try again later.'
    }, status: :unprocessable_entity
  rescue StandardError => e
    Rails.logger.error "Unexpected error in LsaTdxFeedback: #{e.message}\n#{e.backtrace.join("\n")}"

    render json: {
      success: false,
      message: 'Sorry, there was an unexpected error. Please try again later.'
    }, status: :internal_server_error
  end
end