Class: Api::V5::SubscribeEmailsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::SubscribeEmailsController
- Defined in:
- app/controllers/api/v5/subscribe_emails_controller.rb
Overview
typed: ignore frozen_string_literal: true
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#create ⇒ Object
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 |
# File 'app/controllers/api/v5/subscribe_emails_controller.rb', line 5 def create email = params.require(:email).to_s.downcase user = User.find_by(email: email) if user.blank? render json: { success: false, message: 'User not found', data: nil }, status: :not_found return end unless user.subscribe_marketing_email? user.update!(subscribe_marketing_email: true) end render json: { success: true, message: 'Email subscribed successfully', data: { email: email }, }, status: :ok rescue StandardError => e APMErrorHandler.report("Failed to sync user data for email subscription: #{email}", error: e) render json: { success: false, message: 'Sorry, something went wrong', data: nil, }, status: :internal_server_error end |