Possible working ETL
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
import { FastifyRequest, FastifyReply } from 'fastify';
|
||||
import { Pool } from 'pg';
|
||||
import { VehicleDataService } from '../domain/vehicle-data.service';
|
||||
import { VINDecodeService } from '../domain/vin-decode.service';
|
||||
import { PlatformCacheService } from '../domain/platform-cache.service';
|
||||
import { cacheService } from '../../../core/config/redis';
|
||||
import {
|
||||
@@ -13,21 +12,18 @@ import {
|
||||
ModelsQuery,
|
||||
TrimsQuery,
|
||||
EnginesQuery,
|
||||
TransmissionsQuery,
|
||||
VINDecodeRequest
|
||||
TransmissionsQuery
|
||||
} from '../models/requests';
|
||||
import { logger } from '../../../core/logging/logger';
|
||||
|
||||
export class PlatformController {
|
||||
private vehicleDataService: VehicleDataService;
|
||||
private vinDecodeService: VINDecodeService;
|
||||
private pool: Pool;
|
||||
|
||||
constructor(pool: Pool) {
|
||||
this.pool = pool;
|
||||
const platformCache = new PlatformCacheService(cacheService);
|
||||
this.vehicleDataService = new VehicleDataService(platformCache);
|
||||
this.vinDecodeService = new VINDecodeService(platformCache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,12 +96,14 @@ export class PlatformController {
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/platform/transmissions?year={year}&make={make}&model={model}
|
||||
* GET /api/platform/transmissions?year={year}&make={make}&model={model}&trim={trim}[&engine={engine}]
|
||||
*/
|
||||
async getTransmissions(request: FastifyRequest<{ Querystring: TransmissionsQuery }>, reply: FastifyReply): Promise<void> {
|
||||
try {
|
||||
const { year, make, model } = request.query as any;
|
||||
const transmissions = await this.vehicleDataService.getTransmissions(this.pool, year, make, model);
|
||||
const { year, make, model, trim, engine } = request.query as any;
|
||||
const transmissions = engine
|
||||
? await this.vehicleDataService.getTransmissionsForTrimAndEngine(this.pool, year, make, model, trim, engine)
|
||||
: await this.vehicleDataService.getTransmissionsForTrim(this.pool, year, make, model, trim);
|
||||
reply.code(200).send({ transmissions });
|
||||
} catch (error) {
|
||||
logger.error('Controller error: getTransmissions', { error, query: request.query });
|
||||
@@ -113,34 +111,4 @@ export class PlatformController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/platform/vehicle?vin={vin}
|
||||
*/
|
||||
async decodeVIN(request: FastifyRequest<{ Querystring: VINDecodeRequest }>, reply: FastifyReply): Promise<void> {
|
||||
try {
|
||||
const { vin } = request.query;
|
||||
const result = await this.vinDecodeService.decodeVIN(this.pool, vin);
|
||||
|
||||
if (!result.success) {
|
||||
if (result.error && result.error.includes('Invalid VIN')) {
|
||||
reply.code(400).send(result);
|
||||
} else if (result.error && result.error.includes('unavailable')) {
|
||||
reply.code(503).send(result);
|
||||
} else {
|
||||
reply.code(404).send(result);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
reply.code(200).send(result);
|
||||
} catch (error) {
|
||||
logger.error('Controller error: decodeVIN', { error, query: request.query });
|
||||
reply.code(500).send({
|
||||
vin: request.query.vin,
|
||||
result: null,
|
||||
success: false,
|
||||
error: 'Internal server error during VIN decoding'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user