Skip to content

Commit

Permalink
Added lookupService and catsAPI service to further wrap bc gov apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronaldo Macapobre committed Jan 3, 2025
1 parent 9d7b323 commit ebc547a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
11 changes: 5 additions & 6 deletions aws/lambdas/locations/get-locations/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { APIGatewayEvent, APIGatewayProxyResult, Context } from "aws-lambda";
import { HttpService } from "../../../services/httpService";
import { LookupService } from "../../../services/lookupService";
import SecretsManagerService from "../../../services/secretsManagerService";

export const handler = async (
Expand All @@ -10,16 +11,14 @@ export const handler = async (

try {
const smService = new SecretsManagerService();
const secretStringJson = await smService.getSecret(
process.env.FILE_SERVICES_CLIENT_SECRET_NAME!
);
const { baseUrl, username, password } = JSON.parse(secretStringJson);
const httpService = new HttpService();
const lookupService = new LookupService(httpService, smService);

lookupService.init();

await httpService.init(baseUrl, username, password);
const queryParams = event.queryStringParameters || {};

const data = await httpService.get(event.path, queryParams);
const data = await lookupService.get(event.path, queryParams);

return {
statusCode: 200,
Expand Down
11 changes: 5 additions & 6 deletions aws/lambdas/locations/get-rooms/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { APIGatewayEvent, APIGatewayProxyResult, Context } from "aws-lambda";
import { HttpService } from "../../../services/httpService";
import { LookupService } from "../../../services/lookupService";
import SecretsManagerService from "../../../services/secretsManagerService";

export const handler = async (
Expand All @@ -10,16 +11,14 @@ export const handler = async (

try {
const smService = new SecretsManagerService();
const secretStringJson = await smService.getSecret(
process.env.FILE_SERVICES_CLIENT_SECRET_NAME!
);
const { baseUrl, username, password } = JSON.parse(secretStringJson);
const httpService = new HttpService();
const lookupService = new LookupService(httpService, smService);

lookupService.init();

await httpService.init(baseUrl, username, password);
const queryParams = event.queryStringParameters || {};

const data = await httpService.get(event.path, queryParams);
const data = await lookupService.get(event.path, queryParams);

return {
statusCode: 200,
Expand Down
35 changes: 35 additions & 0 deletions aws/services/lookupService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { IHttpService } from "./httpService";
import SecretsManagerService from "./secretsManagerService";

export class LookupService {
constructor(
private httpService: IHttpService,
private smService: SecretsManagerService
) {}

async init() {
console.log(
`Retrieving credentials for ${process.env.FILE_SERVICES_CLIENT_SECRET_NAME}.`
);

const secretStringJson = await this.smService.getSecret(
process.env.FILE_SERVICES_CLIENT_SECRET_NAME!
);

console.log(`Credentials retrieved: ${secretStringJson}`);

console.log(`Initializing httpService`);

const { baseUrl, username, password } = JSON.parse(secretStringJson);

await this.httpService.init(baseUrl, username, password);

console.log("httpService initialized.");
}

async get(url: string, queryParams?: Record<string, unknown>) {
console.log(`Sending GET request for ${url}...`);

return await this.httpService.get(url, queryParams);
}
}

0 comments on commit ebc547a

Please sign in to comment.