-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Features): Makes the upload of features (shapefile and csv) async…
…hronous
- Loading branch information
1 parent
8805e10
commit 88831b4
Showing
31 changed files
with
931 additions
and
240 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
api/apps/api/src/migrations/api/1708099064649-AddFeatureShapefileApiEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddFeatureShapefileApiEvents1708099064649 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
INSERT INTO api_event_kinds (id) values | ||
('features.shapefile.import.submitted/v1/alpha'), | ||
('features.shapefile.import.finished/v1/alpha'), | ||
('features.shapefile.import.failed/v1/alpha') | ||
`); | ||
|
||
await queryRunner.query(` | ||
UPDATE features SET creation_status = 'created' | ||
WHERE creation_status = 'done'; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DELETE FROM api_event_kinds WHERE id IN ( | ||
'features.shapefile.import.submitted/v1/alpha', | ||
'features.shapefile.import.finished/v1/alpha', | ||
'features.shapefile.import.failed/v1/alpha') | ||
`); | ||
await queryRunner.query(` | ||
UPDATE features SET creation_status = 'done' | ||
WHERE creation_status = 'created'; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
api/apps/api/src/modules/geo-features/adapters/feature-shapefile-upload-api-events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { API_EVENT_KINDS } from '@marxan/api-events'; | ||
import { ApiEventsService } from '@marxan-api/modules/api-events'; | ||
import { | ||
FeatureShapefileImportEventsPort, | ||
FeatureShapefileImportState, | ||
} from '@marxan-api/modules/geo-features/ports/feature-shapefile-import-events-port'; | ||
|
||
@Injectable() | ||
export class FeatureShapefileImportApiEvents | ||
extends ApiEventsService | ||
implements FeatureShapefileImportEventsPort | ||
{ | ||
private readonly eventsMap: Record< | ||
FeatureShapefileImportState, | ||
API_EVENT_KINDS | ||
> = { | ||
[FeatureShapefileImportState.FeatureShapefileSubmitted]: | ||
API_EVENT_KINDS.features__shapefile__import__submitted__v1__alpha, | ||
[FeatureShapefileImportState.FeatureShapefileFinished]: | ||
API_EVENT_KINDS.features__shapefile__import__finished__v1__alpha, | ||
[FeatureShapefileImportState.FeatureShapefileFailed]: | ||
API_EVENT_KINDS.features__shapefile__import__failed__v1__alpha, | ||
}; | ||
|
||
async event( | ||
projectId: string, | ||
state: FeatureShapefileImportState, | ||
context?: Record<string, unknown>, | ||
): Promise<void> { | ||
await this.create({ | ||
data: context ?? {}, | ||
topic: projectId, | ||
kind: this.eventsMap[state], | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
api/apps/api/src/modules/geo-features/adapters/geo-features-adapters.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ApiEventsModule } from '../../api-events'; | ||
import { FeatureShapefileImportEventsPort } from '@marxan-api/modules/geo-features/ports/feature-shapefile-import-events-port'; | ||
import { FeatureShapefileImportApiEvents } from '@marxan-api/modules/geo-features/adapters/feature-shapefile-upload-api-events'; | ||
|
||
@Module({ | ||
imports: [ApiEventsModule], | ||
providers: [ | ||
{ | ||
provide: FeatureShapefileImportEventsPort, | ||
useClass: FeatureShapefileImportApiEvents, | ||
}, | ||
], | ||
exports: [FeatureShapefileImportEventsPort], | ||
}) | ||
export class GeoFeaturesAdaptersModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.