Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement metar, taf, and atis for POSCON #137

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/atis/atis.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AtisController {
description: 'The source for the ICAO',
example: 'faa',
required: false,
enum: ['faa', 'vatsim', 'ivao', 'pilotedge'],
enum: ['faa', 'vatsim', 'ivao', 'pilotedge', 'poscon'],
})
@ApiOkResponse({ description: 'ATIS notice was found', type: Atis })
@ApiNotFoundResponse({ description: 'ATIS not available for ICAO' })
Expand Down
20 changes: 20 additions & 0 deletions src/atis/atis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class AtisService {
return this.handleIvao(icaoCode);
case 'pilotedge':
return this.handlePilotEdge(icaoCode).toPromise();
case 'poscon':
return this.handlePOSCON(icaoCode).toPromise();
}
}

Expand Down Expand Up @@ -123,6 +125,24 @@ export class AtisService {
);
}

private handlePOSCON(icao: string): Observable<Atis> {
return this.http
.get<any>(`https://services.poscon.com/atis/${icao}`)
.pipe(
tap((response) => this.logger.debug(
`Response status ${response.status} for POSCON ATIS request`,
)),
map((response) => ({
icao,
source: 'POSCON',
combined: response.data.atis.body,
})),
catchError((err) => {
throw this.generateNotAvailableException(err, icao);
}),
);
}

private generateNotAvailableException(err: any, icao: string) {
const exception = new HttpException(
`ATIS not available for ICAO: ${icao}`,
Expand Down
2 changes: 1 addition & 1 deletion src/metar/metar.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class MetarController {
description: 'The source for the METAR',
example: 'vatsim',
required: false,
enum: ['vatsim', 'ms', 'ivao', 'pilotedge'],
enum: ['vatsim', 'ms', 'ivao', 'pilotedge', 'poscon'],
})
@ApiOkResponse({ description: 'METAR notice was found', type: Metar })
@ApiNotFoundResponse({ description: 'METAR not available for ICAO' })
Expand Down
16 changes: 16 additions & 0 deletions src/metar/metar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class MetarService {
return this.handleMs(icaoCode);
case 'pilotedge':
return this.handlePilotEdge(icaoCode).toPromise();
case 'poscon':
return this.handlePOSCON(icaoCode).toPromise();
}
}

Expand Down Expand Up @@ -117,6 +119,20 @@ export class MetarService {
);
}

// POSCON
private handlePOSCON(icao: string): Observable<Metar> {
return this.http.get<any>(`https://services.poscon.com/metar/${icao}`)
.pipe(
tap((response) => this.logger.debug(`Response status ${response.status} for POSCON METAR request`)),
map((response) => ({ icao, metar: response.data.metar, source: 'POSCON' })),
catchError(
(err) => {
throw this.generateNotAvailableException(err, icao);
},
),
);
}

private generateNotAvailableException(err: any, icao: string): HttpException {
const exception = new HttpException(`METAR not available for ICAO: ${icao}`, 404);
this.logger.error(err);
Expand Down
2 changes: 1 addition & 1 deletion src/taf/taf.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class TafController {
@Get(':icao')
@CacheTTL(120)
@ApiParam({ name: 'icao', description: 'The ICAO of the airport to search for', example: 'KLAX' })
@ApiQuery({ name: 'source', description: 'The source for the TAF', example: 'faa', required: false, enum: ['aviationweather', 'faa'] })
@ApiQuery({ name: 'source', description: 'The source for the TAF', example: 'faa', required: false, enum: ['aviationweather', 'faa', 'poscon'] })
@ApiOkResponse({ description: 'TAF notice was found', type: Taf })
@ApiNotFoundResponse({ description: 'TAF not available for ICAO' })
getForICAO(@Param('icao') icao: string, @Query('source') source?: string): Promise<Taf> {
Expand Down
14 changes: 14 additions & 0 deletions src/taf/taf.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class TafService {
return this.handleAviationWeather(icaoCode).toPromise();
case 'faa':
return this.handleFaa(icaoCode);
case 'poscon':
return this.handlePOSCON(icaoCode).toPromise();
}
}

Expand Down Expand Up @@ -88,6 +90,18 @@ export class TafService {
});
}

private handlePOSCON(icao: string): Observable<Taf> {
return this.http.get<any>(`https://services.poscon.com/taf/${icao}`)
.pipe(
tap((response) => this.logger.debug(`Response status ${response.status} for POSCON TAF request`)),
map((response) => ({
icao,
taf: response.data.taf,
source: 'POSCON',
})),
);
}

private generateNotAvailableException(err: any, icao: string): HttpException {
const exception = new HttpException(`TAF not available for ICAO: ${icao}`, 404);
this.logger.error(err);
Expand Down