diff --git a/app/providers/geo/GeoApiClient.test.ts b/app/providers/geo/GeoApiClient.test.ts index d5f4211d3956ebb173968a1ca2d9b5878c6746dc..a9fa64b17095f13e33a5e276b8d3e47dfbcb95b9 100644 --- a/app/providers/geo/GeoApiClient.test.ts +++ b/app/providers/geo/GeoApiClient.test.ts @@ -40,4 +40,12 @@ describe('GeoAPIClient', () => { lon: 10.000654, }) }) + + it('fetches city name of place id', async () => { + using _ = fakeFetch(aPlaceDetailsReponse) + + const response = await client.resolveCityName('somePlaceId') + + assertEquals(response, 'Hamburg') + }) }) diff --git a/app/providers/geo/GeoApiClient.ts b/app/providers/geo/GeoApiClient.ts index ed5d5649493696ea9543ce0e035f6544ec1c31d2..8eadc1ccae93dc4173760da2e8ecfb9851225cf3 100644 --- a/app/providers/geo/GeoApiClient.ts +++ b/app/providers/geo/GeoApiClient.ts @@ -5,7 +5,8 @@ export interface ResolvesCoordinates { } export class GeoApiClient implements ResolvesCoordinates { - constructor(private readonly endpointUrl: string) {} + constructor(private readonly endpointUrl: string) { + } async resolveCoordinates( geolocationId: string, @@ -16,7 +17,21 @@ export class GeoApiClient implements ResolvesCoordinates { return { lat, lon } } else { throw new Deno.errors.NotCapable( - `Resolution of lat/lon failed (no data included in response for geolocationId=${geolocationId})`, + `Resolution of lat/lon failed (no data in response for geolocationId=${geolocationId})`, + ) + } + } + + async resolveCityName( + geolocationId: string, + ): Promise<string> { + const response = await this.fetchPlaceDetails(geolocationId) + const { city } = response.data?.placeDetails?.geolocation?.properties || {} + if (city) { + return city + } else { + throw new Deno.errors.NotCapable( + `Resolution of city name failed (no data in response for geolocationId=${geolocationId})`, ) } } diff --git a/app/providers/geo/GeoApiClient.types.ts b/app/providers/geo/GeoApiClient.types.ts index d8153f7d34cdc5480efd592b4b960aeab7d44c0e..28322905624d198cc6a24f2452b20b3dfde3b0c1 100644 --- a/app/providers/geo/GeoApiClient.types.ts +++ b/app/providers/geo/GeoApiClient.types.ts @@ -10,6 +10,7 @@ export type GeolocationCoordinates = { export type GeolocationProperties = { formatted: string + city: string } & GeolocationCoordinates export type GeoAPIResponse = {