Class: Api::V5::PointsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::PointsController
- Includes:
- Concerns::Authorization, Netcore::Payload
- Defined in:
- app/controllers/api/v5/points_controller.rb
Overview
This class should be renamed to RewardsController, so it will have same name with the existing model /api/v5/users/points
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
- #adjusted_limits ⇒ Object
- #expiry ⇒ Object
-
#history ⇒ Object
GET /history get redeemed history.
- #redeem_as_voucher ⇒ Object
-
#total ⇒ Object
GET /total.
Methods included from Netcore::Payload
#fav_payload, #reservation_data_payload, #reward_data_payload, #user_loyalty_payload, #user_properties, #user_properties_for_client
Methods included from CountryIdMemoization
#malaysia_id, #singapore_id, #thailand_id
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#adjusted_limits ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/api/v5/points_controller.rb', line 59 def adjusted_limits total_amount = params[:total_amount] if total_amount.blank? = 'total_amount is required.' end country_code = params[:country_code] if country_code.present? && ApiV5::Constants::COUNTRY_CODES.exclude?(country_code.to_s.upcase) = "country_code must be one of: #{ApiV5::Constants::COUNTRY_CODES.join(', ')}" end user_adjusted_points = ReservationService::UserAdjustedPoints.new( current_user, total_amount, country_code ).calculate if render json: { success: !, message: , data: nil }, status: :unprocessable_entity else render json: { data: { user_adjusted_points: user_adjusted_points, }, message: nil, success: true, } end end |
#expiry ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/api/v5/points_controller.rb', line 88 def expiry set_status_header(true) usr_loyalty = user_loyalty(current_user).loyalty_level data = { total_points: total_points, user_loyalty: usr_loyalty.as_json(only: [:id, :name]), expiry_date: Reward.points_expiry_date(current_user), } render json: { data: data, success: true, message: nil, } end |
#history ⇒ Object
GET /history get redeemed history
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/api/v5/points_controller.rb', line 17 def history set_status_header(true) = { meta: { total_points: total_points, }, } page = params.fetch(:page, {}) filter = Api::V5::RewardsFilter.new current_user.rewards.order('id DESC') filter.page_number(page.fetch(:number, 1)). per_page(page.fetch(:size, 10)) render json: filter.as_json(serialization_context, minor_version_param, ).merge(success: true, message: nil) end |
#redeem_as_voucher ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/api/v5/points_controller.rb', line 34 def redeem_as_voucher payload = { user: current_user, redeemed_points: params.require(:redeem_amount).to_i, points_country_code: params[:points_country_code], } redeem_operation = Redemption::RedeemAsVoucher.new(payload) if redeem_operation.execute render json: { success: true, message: I18n.t('actions.redemption.redeemed') } else render json: { message: redeem_operation., success: false } end end |
#total ⇒ Object
GET /total
50 51 52 53 54 55 56 57 |
# File 'app/controllers/api/v5/points_controller.rb', line 50 def total set_status_header(true) render json: { data: total_points, success: true, message: nil, } end |