Skip to content

Commit

Permalink
remove references to geocoding abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 30, 2024
1 parent 6cebea6 commit 7f3255a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 28 deletions.
8 changes: 2 additions & 6 deletions api/src/modules/geo-coding/geo-coding.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { PointOfProductionGeocodingStrategy } from 'modules/geo-coding/strategie
import { AdminRegionOfProductionService } from 'modules/geo-coding/strategies/admin-region-of-production.service';
import { SourcingLocationsModule } from 'modules/sourcing-locations/sourcing-locations.module';
import { GeoCodingService } from 'modules/geo-coding/geo-coding.service';
import { GeoCodingAbstractClass } from 'modules/geo-coding/geo-coding-abstract-class';
import { Geocoder } from 'modules/geo-coding/geocoders/geocoder.interface';
import { CacheGeocoder } from 'modules/geo-coding/geocoders/cache.geocoder';
import { GoogleMapsGeocoder } from 'modules/geo-coding/geocoders/google-maps.geocoder';
import * as redisStore from 'cache-manager-redis-store';
Expand All @@ -22,8 +20,6 @@ const geocodingCacheTTL: number = parseInt(
`${geocodingCacheConfig.geocodingCacheTTL}`,
10,
);
const geocodingCacheEnabled: boolean =
`${geocodingCacheConfig.enabled}`.toLowerCase() === 'true';

@Module({
imports: [
Expand All @@ -41,7 +37,7 @@ const geocodingCacheEnabled: boolean =
providers: [
GoogleMapsGeocoder,
{
provide: Geocoder,
provide: CacheGeocoder,
useClass: CacheGeocoder,
},
{
Expand All @@ -54,6 +50,6 @@ const geocodingCacheEnabled: boolean =
PointOfProductionGeocodingStrategy,
AdminRegionOfProductionService,
],
exports: [GeoCodingAbstractClass],
exports: [GeoCodingService],
})
export class GeoCodingModule {}
5 changes: 2 additions & 3 deletions api/src/modules/geo-coding/geocoders/cache.geocoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { Inject, Logger } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import {
GeocodeArgs,
GeocoderInterface,
GeocodeResponse,
} from 'modules/geo-coding/geocoders/geocoder.interface';
import { Cache } from 'cache-manager';
import { GoogleMapsGeocoder } from 'modules/geo-coding/geocoders/google-maps.geocoder';

export class CacheGeocoder implements GeocoderInterface {
export class CacheGeocoder {
private logger: Logger = new Logger(CacheGeocoder.name);

constructor(
@Inject(GoogleMapsGeocoder) private backendGeocoder: GeocoderInterface,
private backendGeocoder: GoogleMapsGeocoder,
@Inject(CACHE_MANAGER) private cacheManager: Cache,
) {}

Expand Down
7 changes: 2 additions & 5 deletions api/src/modules/geo-coding/geocoders/google-maps.geocoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import {
GeocodeResponseData,
} from '@googlemaps/google-maps-services-js/dist/geocode/geocode';
import { inspect } from 'util';
import {
GeocodeArgs,
GeocoderInterface,
} from 'modules/geo-coding/geocoders/geocoder.interface';
import { GeocodeArgs } from 'modules/geo-coding/geocoders/geocoder.interface';
import { GeoCodingError } from 'modules/geo-coding/errors/geo-coding.error';

export class GoogleMapsGeocoder implements GeocoderInterface {
export class GoogleMapsGeocoder {
private logger: Logger = new Logger(GoogleMapsGeocoder.name);
private readonly client: ClientType;
private readonly apiKey: string = config.get('geolocation.gmapsApiKey');
Expand Down
11 changes: 4 additions & 7 deletions api/src/modules/geo-coding/strategies/base-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { AdminRegionsService } from 'modules/admin-regions/admin-regions.service';
import { GeoRegionsService } from 'modules/geo-regions/geo-regions.service';
import { SourcingLocationsService } from 'modules/sourcing-locations/sourcing-locations.service';
import { SourcingData } from 'modules/import-data/sourcing-data/dto-processor.service';
import {
GeocodeResponse,
Geocoder,
GeocoderInterface,
} from 'modules/geo-coding/geocoders/geocoder.interface';
import { GeocodeResponse } from 'modules/geo-coding/geocoders/geocoder.interface';
import { AddressComponent } from '@googlemaps/google-maps-services-js';
import { GeocodeResult } from '@googlemaps/google-maps-services-js/dist/common';
import { SourcingLocation } from 'modules/sourcing-locations/sourcing-location.entity';
import { GeoCodingError } from 'modules/geo-coding/errors/geo-coding.error';
import { CacheGeocoder } from 'modules/geo-coding/geocoders/cache.geocoder';

/**
* @note: Landgriffon Geocoding strategy doc:
Expand All @@ -21,7 +18,7 @@ import { GeoCodingError } from 'modules/geo-coding/errors/geo-coding.error';
@Injectable()
export abstract class BaseStrategy {
constructor(
@Inject(Geocoder) protected readonly geocoder: GeocoderInterface,
protected readonly geocoder: CacheGeocoder,
protected readonly adminRegionService: AdminRegionsService,
protected readonly geoRegionService: GeoRegionsService,
protected readonly sourcingLocationService: SourcingLocationsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { SourcingData } from 'modules/import-data/sourcing-data/dto-processor.se
import { Supplier } from 'modules/suppliers/supplier.entity';
import { Material } from 'modules/materials/material.entity';
import { BusinessUnit } from 'modules/business-units/business-unit.entity';
import { GeoCodingAbstractClass } from 'modules/geo-coding/geo-coding-abstract-class';
import { TasksService } from 'modules/tasks/tasks.service';
import { IndicatorsService } from 'modules/indicators/indicators.service';
import { Indicator } from 'modules/indicators/indicator.entity';
Expand All @@ -26,6 +25,7 @@ import { ExcelValidationError } from 'modules/import-data/sourcing-data/validati
import { GeoCodingError } from 'modules/geo-coding/errors/geo-coding.error';
import { SourcingDataDbCleaner } from 'modules/import-data/sourcing-data/sourcing-data.db-cleaner';
import { SourcingLocation } from 'modules/sourcing-locations/sourcing-location.entity';
import { GeoCodingService } from 'modules/geo-coding/geo-coding.service';

export interface SourcingRecordsSheets extends Record<string, any[]> {
materials: Record<string, any>[];
Expand Down Expand Up @@ -57,7 +57,7 @@ export class SourcingDataImportService {
protected readonly supplierService: SuppliersService,
protected readonly sourcingLocationService: SourcingLocationsService,
protected readonly fileService: FileService<SourcingRecordsSheets>,
protected readonly geoCodingService: GeoCodingAbstractClass,
protected readonly geoCodingService: GeoCodingService,
protected readonly tasksService: TasksService,
protected readonly indicatorService: IndicatorsService,
protected readonly impactService: ImpactService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
SourcingLocation,
} from 'modules/sourcing-locations/sourcing-location.entity';
import { SourcingLocationsService } from 'modules/sourcing-locations/sourcing-locations.service';
import { GeoCodingAbstractClass } from 'modules/geo-coding/geo-coding-abstract-class';
import { InterventionBuilder } from 'modules/scenario-interventions/services/intervention-builder.service';
import { SourcingRecord } from 'modules/sourcing-records/sourcing-record.entity';
import { InsertResult } from 'typeorm';
import { IndicatorRecord } from 'modules/indicator-records/indicator-record.entity';
import { GeoCodingService } from 'modules/geo-coding/geo-coding.service';

@Injectable()
export class ScenarioInterventionsService extends AppBaseService<
Expand All @@ -44,7 +44,7 @@ export class ScenarioInterventionsService extends AppBaseService<
constructor(
protected readonly scenarioInterventionRepository: ScenarioInterventionRepository,
protected readonly interventionBuilder: InterventionBuilder,
protected readonly geoCodingService: GeoCodingAbstractClass,
protected readonly geoCodingService: GeoCodingService,
protected readonly sourcingLocationsService: SourcingLocationsService,
) {
super(
Expand Down
3 changes: 1 addition & 2 deletions api/test/integration/geo-coding/geo-coding.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { GeocodeResponseData } from '@googlemaps/google-maps-services-js/dist/ge
import { AdminRegionRepository } from 'modules/admin-regions/admin-region.repository';
import { PointOfProductionGeocodingStrategy } from 'modules/geo-coding/strategies/point-of-production.geocoding.service';
import { UnknownLocationGeoCodingStrategy } from 'modules/geo-coding/strategies/unknown-location.geocoding.service';
import { GeoCodingAbstractClass } from 'modules/geo-coding/geo-coding-abstract-class';
import ApplicationManager, {
TestApplication,
} from '../../utils/application-manager';
Expand All @@ -36,7 +35,7 @@ describe('GeoCoding Service (Integration Testing)', () => {
testApplication = await ApplicationManager.init();

adminRegionRepository = testApplication.get(AdminRegionRepository);
geoCodingService = testApplication.get(GeoCodingAbstractClass);
geoCodingService = testApplication.get(GeoCodingService);
adminRegionService = testApplication.get(AdminRegionsService);
geoRegionRepository = testApplication.get(GeoRegionRepository);
sourcingLocationService = testApplication.get(SourcingLocationsService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import ApplicationManager, {
TestApplication,
} from '../../../utils/application-manager';
import { SourcingDataDbCleaner } from '../../../../src/modules/import-data/sourcing-data/sourcing-data.db-cleaner';
import { GeoCodingService } from '../../../../src/modules/geo-coding/geo-coding.service';

let tablesToDrop: string[] = [];

Expand Down Expand Up @@ -179,7 +180,7 @@ describe('Sourcing Data import', () => {
})
.overrideProvider(FileService)
.useClass(MockFileService)
.overrideProvider(GeoCodingAbstractClass)
.overrideProvider(GeoCodingService)
.useValue(geoCodingServiceMock)
.overrideProvider(UnknownLocationGeoCodingStrategy)
.useClass(UnknownLocationServiceMock),
Expand Down

0 comments on commit 7f3255a

Please sign in to comment.