Skip to content

Commit

Permalink
refactor(location search): Photon: restrict via API URL on shop & ame…
Browse files Browse the repository at this point in the history
…nity (#808)
  • Loading branch information
raphodn authored Sep 20, 2024
1 parent 8f7a8e9 commit dfe1a98
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import constants from '../constants'
const PRICE_UPDATE_FIELDS = ['price', 'price_is_discounted', 'price_without_discount', 'price_per', 'currency', 'date']
const PRICE_CREATE_FIELDS = PRICE_UPDATE_FIELDS.concat(['product_code', 'product_name', 'category_tag', 'labels_tags', 'origins_tags', 'location_osm_id', 'location_osm_type', 'proof_id'])
const PROOF_UPDATE_FIELDS = ['type', 'date', 'currency']
const LOCATION_SEARCH_LIMIT = 10

const OP_DEFAULT_PAGE_SIZE = 20 // 100 slows down the app
const OP_DEFAULT_HEADERS = {
Expand Down Expand Up @@ -231,31 +232,39 @@ export default {
},

openfoodfactsProductSearch(code) {
return fetch(`${constants.OFF_API_URL}/${code}.json`, {
const url = `${constants.OFF_API_URL}/${code}.json`
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
.then((response) => response.json())
},

openstreetmapNominatimSearch(q) {
return fetch(`${constants.OSM_NOMINATIM_SEARCH_URL}?q=${q}&addressdetails=1&format=json&limit=10`, {
const url = `${constants.OSM_NOMINATIM_SEARCH_URL}?q=${q}&addressdetails=1&format=json&limit=${LOCATION_SEARCH_LIMIT}`
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
.then((response) => response.json())
.then((data) => data.filter(l => !constants.NOMINATIM_RESULT_TYPE_EXCLUDE_LIST.includes(l.type)))
},
openstreetmapNominatimLookup(id) {
return fetch(`${constants.OSM_NOMINATIM_LOOKUP_URL}?osm_ids=N${id},W${id},R${id}&addressdetails=1&format=json`, {
const url = `${constants.OSM_NOMINATIM_LOOKUP_URL}?osm_ids=N${id},W${id},R${id}&addressdetails=1&format=json`
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
.then((response) => response.json())
.then((data) => data.filter(l => !constants.NOMINATIM_RESULT_TYPE_EXCLUDE_LIST.includes(l.type)))
},
openstreetmapPhotonSearch(q) {
return fetch(`${constants.OSM_PHOTON_SEARCH_URL}?q=${q}&limit=10`, {
// Photon: restrict the search to shop & amenity
openstreetmapPhotonSearch(q, restrictToShop=true) {
let url = `${constants.OSM_PHOTON_SEARCH_URL}?q=${q}&limit=${LOCATION_SEARCH_LIMIT}`
if (restrictToShop) {
url += '&osm_key=shop&osm_tag=amenity'
}
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
Expand Down

0 comments on commit dfe1a98

Please sign in to comment.