From 5674f3c889598319ac003db0efe9378fd7ce1b62 Mon Sep 17 00:00:00 2001 From: Jigar Patel Date: Thu, 22 Apr 2021 00:24:24 +0000 Subject: [PATCH 1/2] add category_names array to each video metadata record --- api/src/data/VideoDatabaseClient.ts | 44 ++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/api/src/data/VideoDatabaseClient.ts b/api/src/data/VideoDatabaseClient.ts index 05df40e1..1298a96e 100644 --- a/api/src/data/VideoDatabaseClient.ts +++ b/api/src/data/VideoDatabaseClient.ts @@ -58,16 +58,20 @@ class VideoDatabaseClient { } } - public videoMetadata = { + public videoMetadata = { /** - * Returns metadata about video conetent such as (title, description, streaming url, category, user, upload date) + * Returns metadata about video content such as (title, description, streaming url, category, user, upload date) * * @param limit Optionally specify amount of rows that should be returned * @returns DBQueryResponse * + * TODO: add types for db metadata response + * * */ get: async (limit?: string): Promise => { const queryResult: DBQueryResponse = { data: null, wasRequestSuccessful: false, message: '' } + + // retrieve initial video metadata try{ if(limit){ const limitedDataQuery = 'SELECT * FROM get_all_video_data_by_limit($1);'; @@ -83,7 +87,23 @@ class VideoDatabaseClient { console.error(message) queryResult.message = message } - + + // retrieve & add categories associated with each video + + for (let index = 0; index < queryResult.data.length; index++) { + const data = queryResult.data[index]; + + const videoID: number = parseInt(data.id); + const categoriesResponse = await this.videoCategories.getCategoriesByVideoID(videoID); + const category_names: string[] = []; + + categoriesResponse.data.forEach( (categoryItem) => { + category_names.push(categoryItem.name) + }) + + data['category_names'] = category_names; + } + return queryResult; }, @@ -164,7 +184,23 @@ class VideoDatabaseClient { } return queryResult; - } + }, + getCategoriesByVideoID: async (videoID: number) : Promise => { + const queryResult: DBQueryResponse = { data: null, wasRequestSuccessful: false, message: '' } + + try{ + const categoriesByVideoIDResponse = 'SELECT * FROM get_categories_for_video_id($1);' + queryResult.data = (await this.#videoDatabaseClient.query(categoriesByVideoIDResponse, [videoID])).rows + queryResult.wasRequestSuccessful = true; + queryResult.message = 'Success retrieving categories for a specific video ID' + }catch(error) { + const message = `Error retrieving categories for a specific video ID` + console.error(message) + queryResult.message = message + } + + return queryResult; + } } From 3d667a1742ebf2a1bde4f492cf8dcdef2c1b4314 Mon Sep 17 00:00:00 2001 From: Jigar Patel Date: Mon, 26 Apr 2021 00:22:08 +0000 Subject: [PATCH 2/2] remove old client code --- api/src/app.ts | 2 +- api/src/controllers/VideoController.ts | 139 +------------------------ 2 files changed, 5 insertions(+), 136 deletions(-) diff --git a/api/src/app.ts b/api/src/app.ts index 2f550411..8f56f119 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -40,7 +40,7 @@ export default class App { this.#openIDConfig = openIDConfig this.#videoDatabaseConfig = videoDatabaseConfig - this.#app.use(cors({ credentials: true })) //! FIXME: update cors configuration after deployment + this.#app.use(cors({ credentials: true })) } public start = async (callBack?: Mocha.Done): Promise => { diff --git a/api/src/controllers/VideoController.ts b/api/src/controllers/VideoController.ts index 5de94d27..6ceff725 100644 --- a/api/src/controllers/VideoController.ts +++ b/api/src/controllers/VideoController.ts @@ -34,12 +34,11 @@ export class VideoController extends Controller { //* need to add +1 for month since .getMonth() subtracts 1 to represent (0-11 month range) const uploadDate = `${datestamp.getFullYear()}-${datestamp.getMonth() + 1}-${datestamp.getDate()}` - - const isPublic = true - // const categories = [3,1,2] - - //!FIXME: get info from client later + const categories = JSON.parse(_req.body.categories) + + // TODO: add public/private feature later + const isPublic = true // const isPublic = _req.body.is_public; const videoMetadata: Video = { @@ -85,39 +84,6 @@ export class VideoController extends Controller { else this.fail(res, categoriesData.message) } - @Get('/file-upload', [requiresAuth()]) - async file_uploader(_req: Request, res: Response): Promise { - res.writeHead(200, { 'Content-Type': 'text/html' }) - res.write(` - - - - -

Upload Video

- -
- -
-
- -
-
- -
- -


- -
-
- -
- - - - `) - return res.end() - } - @Get('/videos') async get_video_metadata(_req: Request, res: Response): Promise { let { limit } = _req.query @@ -169,101 +135,4 @@ export class VideoController extends Controller { } } - @Get('/video-test') - async video_test(req: Request, res: Response): Promise { - res.writeHead(200, { 'Content-Type': 'text/html' }) - res.write( - ` - - - - - - - - - - -
-
- Streaming URL Here: - - - - -
Video Links
-
    -
- - - - - - `, - ) - res.end() - } }