Class: ReviewService::SecondStep

Inherits:
ApplicationService show all
Defined in:
app/services/review_service/second_step.rb

Instance Attribute Summary collapse

Attributes inherited from ApplicationService

#object

Instance Method Summary collapse

Methods inherited from ApplicationService

#execute

Constructor Details

#initialize(review_id, params) ⇒ SecondStep

Returns a new instance of SecondStep.



10
11
12
13
# File 'app/services/review_service/second_step.rb', line 10

def initialize(review_id, params)
  self.object = Review.find(review_id)
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'app/services/review_service/second_step.rb', line 8

def params
  @params
end

Instance Method Details

#error_message_simpleObject



36
37
38
# File 'app/services/review_service/second_step.rb', line 36

def error_message_simple
  object.errors&.full_messages&.to_sentence
end

#execute!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/review_service/second_step.rb', line 15

def execute!
  success = false
  ActiveRecord::Base.transaction do
    update_review
    assign_ratings
    assign_review_recommended_fors
    assign_review_photos
    object.save!

    if object.reservation.restaurant.eligible_for_rewards?
      GiveReservationRewardWorker.perform_async(object.reservation_id)
    end

    success = true
  end

  raise unless success

  ServiceResult.new data: object
end

#next_step_pathObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/services/review_service/second_step.rb', line 40

def next_step_path
  if user.present?
    url_helper.booking_review_landing_page_path(locale: MyLocaleManager.normalize_locale,
                                                customer: :member,
                                                booking_id: booking_id,
                                                review_id: object.encrypted_id)
  elsif opt_in_to_be_member?
    url_helper.(locale: MyLocaleManager.normalize_locale,
                                               booking_id: booking_id,
                                               review_id: object.encrypted_id)
  else
    url_helper.booking_review_landing_page_path(locale: MyLocaleManager.normalize_locale,
                                                customer: :guest,
                                                booking_id: booking_id,
                                                review_id: object.encrypted_id)
  end
end