diff --git a/src/components/PriceCard.vue b/src/components/PriceCard.vue index c87650cf561..63b4d04d4f1 100644 --- a/src/components/PriceCard.vue +++ b/src/components/PriceCard.vue @@ -213,7 +213,7 @@ export default { if (this.readonly) { return } - this.$router.push({ path: `/locations/${this.price.location_id}` }) + this.$router.push({ path: `/locations/${this.price.location_osm_type.toLowerCase()}/${this.price.location_osm_id}` }) }, goToUser() { if (this.readonly) { diff --git a/src/router.js b/src/router.js index f12ef33bc19..b85e2d547cc 100644 --- a/src/router.js +++ b/src/router.js @@ -21,7 +21,7 @@ const routes = [ { path: '/add/single', name: 'add-price-single', component: AddPriceSingle, meta: { title: 'Add a single price', requiresAuth: true }}, { path: '/prices', name: 'prices', component: PriceList, meta: { title: 'Latest prices', icon: 'mdi-tag-multiple-outline', drawerMenu: true }}, { path: '/products/:id', name: 'product-detail', component: ProductDetail, meta: { title: 'Product detail' }}, - { path: '/locations/:id', name: 'location-detail', component: LocationDetail, meta: { title: 'Location detail' }}, + { path: '/locations/:osmtype/:osmid', name: 'location-detail', component: LocationDetail, meta: { title: 'Location detail' }}, { path: '/users/:username', name: 'user-detail', component: UserDetail, meta: { title: 'User detail' }}, { path: '/stats', name: 'stats', component: Stats, meta: { title: 'Stats' }}, { path: '/:path(.*)', component: NotFound }, diff --git a/src/services/api.js b/src/services/api.js index 0cfd560a7d2..66896a4eb1b 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -103,6 +103,17 @@ export default { .then((response) => response.json()) }, + getLocationByOSMTypeAndId(locationOSMType, locationOSMId) { + const url = `${import.meta.env.VITE_OPEN_PRICES_API_URL}/locations/osm/${locationOSMType}/${locationOSMId}` + return fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .then((response) => response.json()) + }, + openfoodfactsProductSearch(code) { return fetch(`${OPENFOODFACTS_PRODUCT_URL}/${code}.json`, { method: 'GET', diff --git a/src/views/LocationDetail.vue b/src/views/LocationDetail.vue index 0a7abb17e00..12f9efdc3c5 100644 --- a/src/views/LocationDetail.vue +++ b/src/views/LocationDetail.vue @@ -9,13 +9,18 @@ - - - + + + OpenStreetMap -

- Location not found in OpenStreetMap... Don't hesitate to add it :) + + + + + +

+ Location not found in our database...

@@ -65,7 +70,7 @@ export default { }, methods: { getLocation() { - return api.getLocationById(this.$route.params.id) + return api.getLocationByOSMTypeAndId(this.$route.params.osmtype, this.$route.params.osmid) .then((data) => { if (data.id) { this.location = data @@ -75,7 +80,7 @@ export default { getLocationPrices() { this.loading = true this.locationPricePage += 1 - return api.getPrices({ location_id: this.$route.params.id, page: this.locationPricePage }) + return api.getPrices({ location_osm_type: this.$route.params.osmtype.toUpperCase(), location_osm_id: this.$route.params.osmid, page: this.locationPricePage }) .then((data) => { this.locationPriceList.push(...data.items) this.locationPriceTotal = data.total @@ -86,10 +91,13 @@ export default { if (location) { return utils.getLocationTitle(location, true) } - return this.$route.params.id + return `${this.$route.params.osmtype} ${this.$route.params.osmid}` }, - getLocationOSMUrl(location) { - return `https://www.openstreetmap.org/${location.osm_type.toLowerCase()}/${location.osm_id}` + getLocationOSMUrl() { + if (this.location) { + return `https://www.openstreetmap.org/${this.location.osm_type.toLowerCase()}/${this.location.osm_id}` + } + return `https://www.openstreetmap.org/${this.$route.params.osmtype.toLowerCase()}/${this.$route.params.osmid}` } } }