Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use API rather than SOQL when no filters #665

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Api::V1
# Lease Up Applications controller for access via the API
class LeaseUpApplicationsRestApiController < ApiController
def index
prefs = custom_api_application_service.application_preferences(lease_up_apps_params[:listing_id])
render json: prefs
end

private

def custom_api_application_service
Force::CustomApi::ApplicationService.new(current_user)
end

def lease_up_apps_params
params.permit(
:listing_id,
)
end
end
end
17 changes: 17 additions & 0 deletions app/javascript/apiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ const fetchLeaseUpApplications = async (
pages: 0
}

// TODO: if no filters call API, else continue to call SOQL
// the API will return all prefs including general in a single call

console.log(filters)
if (Object.keys(filters).length === 0) {
const resp = await request.get(`/lease-ups/applications/rest_api?listing_id=${listingId}`)
const rowsPerPage = 50000
return {
records: [...resp],
pages: resp.length / rowsPerPage
// listing_type: null
}
}

// Fetch application preferences associated with a lease up listing.
const appPrefs = await getLeaseUpApplications(listingId, filters)

Expand All @@ -100,6 +114,9 @@ const fetchLeaseUpApplications = async (
generalApps.pages = generalAppsResponse.pages
}

console.log(appPrefs)
console.log(generalApps)

return {
records: [...appPrefs.records, ...generalApps.records],
pages: appPrefs.pages + generalApps.pages,
Expand Down
6 changes: 6 additions & 0 deletions app/services/force/custom_api/application_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def submit(custom_api_attrs, method)
application(result['id'])
end

def application_preferences(id)
api_get("/Listing/Application/Preference/#{id}")
rescue Faraday::ResourceNotFound
nil
end

private

def update_application(custom_api_attrs)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
get 'record-set/:id' => 'flagged_applications#record_set'
end

resources :lease_up_applications_rest_api, path: 'lease-ups/applications/rest_api', only: %w[index]
resources :lease_up_applications, path: 'lease-ups/applications', only: %w[index]
resources :lease_up_listings, path: 'lease-ups/listings', only: %w[index show]

Expand Down
Loading