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 eb9e1bc
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 37 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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import ApplicationManager, {
import { Test } from '@nestjs/testing';
import { AppModule } from 'app.module';
import { ImpactService } from '../../../src/modules/impact/impact.service';
import { GeoCodingService } from '../../../src/modules/geo-coding/geo-coding.service';

const expectedJSONAPIAttributes: string[] = [
'title',
Expand Down Expand Up @@ -176,7 +177,7 @@ describe('ScenarioInterventionsModule (e2e)', () => {
Test.createTestingModule({
imports: [AppModule],
})
.overrideProvider(GeoCodingAbstractClass)
.overrideProvider(GeoCodingService)
.useValue(geoCodingServiceMock),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Cache } from 'cache-manager';
import { AppModule } from 'app.module';
import { CacheGeocoder } from 'modules/geo-coding/geocoders/cache.geocoder';
import { GoogleMapsGeocoder } from 'modules/geo-coding/geocoders/google-maps.geocoder';
import { Geocoder } from 'modules/geo-coding/geocoders/geocoder.interface';
import { geocodeResponses } from './mocks/geo-coding.mock-response';
import ApplicationManager, {
TestApplication,
Expand Down Expand Up @@ -43,7 +42,7 @@ describe('GeoCoding Service (Integration Testing)', () => {
.useClass(GoogleMapsGeocoderMock),
);

cacheGeocoder = testApplication.get<CacheGeocoder>(Geocoder);
cacheGeocoder = testApplication.get<CacheGeocoder>(CacheGeocoder);
cacheManager = testApplication.get<Cache>(CACHE_MANAGER);
});

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 @@ -9,7 +9,6 @@ import { Task } from 'modules/tasks/task.entity';
import ApplicationManager, {
TestApplication,
} from '../../../utils/application-manager';
import { User } from 'modules/users/user.entity';
import { createUser } from '../../../entity-mocks';
import { DataSource } from 'typeorm';
import { clearTestDataFromDatabase } from '../../../utils/database-test-helper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MockFileService,
MockGeoCodingService,
} from '../../../../utils/service-mocks';
import { GeoCodingAbstractClass } from 'modules/geo-coding/geo-coding-abstract-class';
import { GeoCodingService } from '../../../../../src/modules/geo-coding/geo-coding.service';

describe('Sourcing Data Correct Import (Integration Tests)', () => {
let sourcingDataImportTestManager: SourcingDataImportTestManager;
Expand All @@ -16,7 +16,7 @@ describe('Sourcing Data Correct Import (Integration Tests)', () => {
TestManager.buildCustomTestModule()
.overrideProvider(FileService)
.useClass(MockFileService)
.overrideProvider(GeoCodingAbstractClass)
.overrideProvider(GeoCodingService)
.useClass(MockGeoCodingService),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
createSourcingLocation,
createSourcingRecord,
createSupplier,
createTask,
} from '../../../entity-mocks';
import { GeoRegion } from 'modules/geo-regions/geo-region.entity';
import { UnknownLocationGeoCodingStrategy } from 'modules/geo-coding/strategies/unknown-location.geocoding.service';
Expand All @@ -47,8 +46,7 @@ import { h3BasicFixture } from '../../../e2e/h3-data/mocks/h3-fixtures';
import { SourcingDataImportService } from 'modules/import-data/sourcing-data/sourcing-data-import.service';
import { FileService } from 'modules/import-data/file.service';
import { createWorldToCalculateIndicatorRecords } from '../../../utils/indicator-records-preconditions';
import { GeoCodingAbstractClass } from 'modules/geo-coding/geo-coding-abstract-class';
import { Material, MATERIALS_STATUS } from 'modules/materials/material.entity';
import { Material } from 'modules/materials/material.entity';
import { ScenarioIntervention } from 'modules/scenario-interventions/scenario-intervention.entity';
import { SourcingRecordsWithIndicatorRawData } from 'modules/sourcing-records/dto/sourcing-records-with-indicator-raw-data.dto';
import { ImpactCalculator } from 'modules/indicator-records/services/impact-calculator.service';
Expand All @@ -59,6 +57,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 +178,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 eb9e1bc

Please sign in to comment.