Class: BranchListService
- Inherits:
-
Object
- Object
- BranchListService
- Includes:
- ElasticAPM::SpanHelpers
- Defined in:
- app/services/branch_list_service.rb
Overview
Service class to handle branch listing logic, extracting complex logic from controller Provides pagination, filtering, and caching capabilities for branch data
Instance Method Summary collapse
-
#cache_key ⇒ String
Generate cache key for caching the response.
-
#call ⇒ Hash
Execute the branch listing logic.
-
#initialize(params) ⇒ BranchListService
constructor
A new instance of BranchListService.
Constructor Details
#initialize(params) ⇒ BranchListService
Returns a new instance of BranchListService.
6 7 8 |
# File 'app/services/branch_list_service.rb', line 6 def initialize(params) @params = params end |
Instance Method Details
#cache_key ⇒ String
Generate cache key for caching the response
12 13 14 15 16 17 18 19 20 |
# File 'app/services/branch_list_service.rb', line 12 def cache_key [ self.class.to_s, CityHash.hash32(@params), 'branches', I18n.locale, "updated_at:#{Branch.maximum(:updated_at).to_i}", ].join('|') end |
#call ⇒ Hash
Execute the branch listing logic
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/branch_list_service.rb', line 24 def call ElasticAPM.with_span('BranchListService#call', 'app') do branches = filter_active_branches branches = (branches) branches = apply_name_filter(branches) if @params[:name_like].present? paginated_result = paginate_branches(branches) branches_data = format_branches_data(paginated_result[:branches]) build_response(branches_data, paginated_result[:pagination]) rescue StandardError => e HH_LOGGER.error('Error in BranchListService#call', { error: e., params: @params }) APMErrorHandler.report(e, context: { params: @params }) { success: false, message: 'Failed to fetch branches' } end end |