Skip to content

Commit

Permalink
#3060-added onboarding endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Dec 17, 2024
1 parent 55f17f4 commit 2722e7d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import workPackageTemplatesRouter from './src/routes/work-package-templates.rout
import carsRouter from './src/routes/cars.routes';
import organizationRouter from './src/routes/organizations.routes';
import recruitmentRouter from './src/routes/recruitment.routes';
import onboardingRouter from './src/routes/onboarding.routes';

const app = express();

Expand Down Expand Up @@ -68,6 +69,7 @@ app.use('/templates', workPackageTemplatesRouter);
app.use('/cars', carsRouter);
app.use('/organizations', organizationRouter);
app.use('/recruitment', recruitmentRouter);
app.use('/onboarding', onboardingRouter);
app.use('/', (_req, res) => {
res.status(200).json('Welcome to FinishLine');
});
Expand Down
22 changes: 22 additions & 0 deletions src/backend/src/controllers/onboarding.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextFunction, Request, Response } from 'express';
import OnboardingServices from '../services/onboarding.services';

export default class OnboardingController {
static async downloadImage(req: Request, res: Response, next: NextFunction) {
try {
const { fileId } = req.params;
console.log('FILE ID:', fileId);

const imageData = await OnboardingServices.downloadImage(fileId);

// Set the appropriate headers for the HTTP response
res.setHeader('content-type', String(imageData.type));
res.setHeader('content-length', imageData.buffer.length);

// Send the Buffer as the response body
res.send(imageData.buffer);
} catch (error: unknown) {
return next(error);
}
}
}
8 changes: 8 additions & 0 deletions src/backend/src/routes/onboarding.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import express from 'express';
import OnboardingController from '../controllers/onboarding.controller';

const onboardingRouter = express.Router();

onboardingRouter.get('/image/:fileId', OnboardingController.downloadImage);

export default onboardingRouter;
12 changes: 12 additions & 0 deletions src/backend/src/services/onboarding.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NotFoundException } from '../utils/errors.utils';
import { downloadImageFile } from '../utils/google-integration.utils';

export default class OnboardingServices {
static async downloadImage(fileId: string) {
const fileData = await downloadImageFile(fileId);
console.log('FILE DATA RECEIVED');

if (!fileData) throw new NotFoundException('Image File', fileId);
return fileData;
}
}
17 changes: 17 additions & 0 deletions src/frontend/src/apis/onboarding.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import axios from 'axios';
import { apiUrls } from '../utils/urls';

/**
* API Call to download a google image
* @param fileId file id to be downloaded
* @returns an image blob
*/
export const downloadGoogleImage = async (fileId: string): Promise<Blob> => {
const response = await axios.get(apiUrls.imageById(fileId), {
responseType: 'arraybuffer' // Set the response type to 'arraybuffer' to receive the image as a Buffer
});
console.log('ID IN API:', fileId);
const imageBuffer = new Uint8Array(response.data);
const imageBlob = new Blob([imageBuffer], { type: response.headers['content-type'] });
return imageBlob;
};
2 changes: 1 addition & 1 deletion src/frontend/src/hooks/organizations.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
setOrganizationLogo,
setOrganizationFeaturedProjects
} from '../apis/organizations.api';
import { downloadGoogleImage } from '../apis/finance.api';
import { downloadGoogleImage } from '../apis/onboarding.api';

interface OrganizationProvider {
organizationId: string;
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ const faqCreate = () => `${recruitment()}/faq/create`;
const faqEdit = (id: string) => `${recruitment()}/faq/${id}/edit`;
const faqDelete = (id: string) => `${recruitment()}/faq/${id}/delete`;

/************** Onboarding Endpoints ***************/
const onboarding = () => `${API_URL}/onboarding`;
const imageById = (imageId: string) => `${onboarding()}/image/${imageId}`;

/**************** Other Endpoints ****************/
const version = () => `https://api.github.com/repos/Northeastern-Electric-Racing/FinishLine/releases/latest`;

Expand Down Expand Up @@ -354,6 +358,7 @@ export const apiUrls = {
faqCreate,
faqEdit,
faqDelete,
imageById,

version
};

0 comments on commit 2722e7d

Please sign in to comment.