From 4adab3cdac0fc36be3ab72952e01a5f1766ef0f4 Mon Sep 17 00:00:00 2001 From: marleomac3 Date: Thu, 17 Oct 2024 20:47:41 +0000 Subject: [PATCH 1/4] feat: solved merge conflict and generated loader file --- .../src/loaders/lj_mcwilliams_loader.ts | 57 +++++++++++++++++++ .../libraries/src/loaders/loaders.module.ts | 7 ++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts diff --git a/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts b/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts new file mode 100644 index 000000000..94b5a036f --- /dev/null +++ b/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts @@ -0,0 +1,57 @@ +import csv from 'csv-parser'; +import fs from 'fs'; +import { Credit, MediaItem } from '../models/index.js'; +import { Loader } from './loader.js'; + +export class LjMcwilliamsLoader implements Loader { + getLoaderName(): string { + return 'ljmcwilliams'; + } + + async loadData(): Promise { + const credits = await this.loadCredits(); + const mediaItems = await this.loadMediaItems(); + + console.log( + `Loaded ${credits.length} credits and ${mediaItems.length} media items`, + ); + + return [...mediaItems.values()]; + } + + async loadMediaItems(): Promise { + // TODO: Implement this method. + const media = []; + const readable = fs + .createReadStream('data/media_items.csv', 'utf-8') + .pipe(csv()); + for await (const row of readable) { + /**this destructures the CSV file rows */ + const { id, type, title, year } = row; + media.push(new MediaItem(id, title, type, year, [])); + } + return media; + } + + /* + an asyncchronous function named loadCredits + returns a Promise of an array of Credit Objects + */ + async loadCredits(): Promise { + //the empty credits array will store parsed credit data + const credits = []; + /** + * this var creates a readable stream from the CSV file and + * is piped through the csv function to parse the data + */ + const readable = fs + .createReadStream('data/credits.csv', 'utf-8') + .pipe(csv()); + //this asynchronously iterates over each row of the parsed CSV data + for await (const row of readable) { + const { media_item_id, role, name } = row; + credits.push(new Credit(media_item_id, name, role)); + } + return credits; + } +} diff --git a/lesson_10/libraries/src/loaders/loaders.module.ts b/lesson_10/libraries/src/loaders/loaders.module.ts index 5997b6f7e..9c78af8b1 100644 --- a/lesson_10/libraries/src/loaders/loaders.module.ts +++ b/lesson_10/libraries/src/loaders/loaders.module.ts @@ -1,11 +1,16 @@ import { Module } from '@nestjs/common'; import { AnthonyMaysLoader } from './anthony_mays_loader.js'; +import { LjMcwilliamsLoader } from './lj_mcwilliams_loader.js'; import { XavierCruzLoader } from './xavier_cruz_loader.js'; export const Loaders = Symbol.for('Loaders'); // Add your quiz provider here. -const LOADER_PROVIDERS = [AnthonyMaysLoader, XavierCruzLoader]; +const LOADER_PROVIDERS = [ + AnthonyMaysLoader, + XavierCruzLoader, + LjMcwilliamsLoader, +]; @Module({ providers: [ From c6d9624e13a3673ace2390c2d4bc3455c475f3fd Mon Sep 17 00:00:00 2001 From: marleomac3 Date: Fri, 18 Oct 2024 11:43:00 +0000 Subject: [PATCH 2/4] fix: Capitalized and punctuated my comments properly --- .../libraries/src/loaders/lj_mcwilliams_loader.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts b/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts index 94b5a036f..da8c5bb3a 100644 --- a/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts +++ b/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts @@ -26,7 +26,7 @@ export class LjMcwilliamsLoader implements Loader { .createReadStream('data/media_items.csv', 'utf-8') .pipe(csv()); for await (const row of readable) { - /**this destructures the CSV file rows */ + /**This destructures the CSV file rows. */ const { id, type, title, year } = row; media.push(new MediaItem(id, title, type, year, [])); } @@ -34,20 +34,20 @@ export class LjMcwilliamsLoader implements Loader { } /* - an asyncchronous function named loadCredits - returns a Promise of an array of Credit Objects + An asyncchronous function named loadCredits + returns a Promise of an array of Credit Objects. */ async loadCredits(): Promise { //the empty credits array will store parsed credit data const credits = []; /** - * this var creates a readable stream from the CSV file and - * is piped through the csv function to parse the data + * This var creates a readable stream from the CSV file and + * is piped through the csv function to parse the data. */ const readable = fs .createReadStream('data/credits.csv', 'utf-8') .pipe(csv()); - //this asynchronously iterates over each row of the parsed CSV data + //This asynchronously iterates over each row of the parsed CSV data. for await (const row of readable) { const { media_item_id, role, name } = row; credits.push(new Credit(media_item_id, name, role)); From 60f01069308cb4e724b43e752337696a2b5f741d Mon Sep 17 00:00:00 2001 From: marleomac3 Date: Fri, 18 Oct 2024 11:44:39 +0000 Subject: [PATCH 3/4] fix: fixed one capitalization I missed previously --- lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts b/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts index da8c5bb3a..842df07e1 100644 --- a/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts +++ b/lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts @@ -38,7 +38,7 @@ export class LjMcwilliamsLoader implements Loader { returns a Promise of an array of Credit Objects. */ async loadCredits(): Promise { - //the empty credits array will store parsed credit data + //The empty credits array will store parsed credit data const credits = []; /** * This var creates a readable stream from the CSV file and From 7786dba5d2dbe9524a40f5254fa3135437bf6f4d Mon Sep 17 00:00:00 2001 From: "Anthony D. Mays" Date: Sat, 26 Oct 2024 13:16:37 -0400 Subject: [PATCH 4/4] Update loaders.module.ts --- lesson_10/libraries/src/loaders/loaders.module.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lesson_10/libraries/src/loaders/loaders.module.ts b/lesson_10/libraries/src/loaders/loaders.module.ts index 94c25e953..d80a6ccd3 100644 --- a/lesson_10/libraries/src/loaders/loaders.module.ts +++ b/lesson_10/libraries/src/loaders/loaders.module.ts @@ -3,7 +3,6 @@ import { Module } from '@nestjs/common'; import { AmiyahJonesLoader } from './amiyah_jones.js'; import { AngelicaCastilloLoader } from './angelica_castillo_loader.js'; import { AnthonyMaysLoader } from './anthony_mays_loader.js'; -import { LjMcwilliamsLoader } from './lj_mcwilliams_loader.js'; import { ChelseaOgbonniaLoader } from './chelsea_ogbonnia_loader.js'; import { DavidSmithLoader } from './david_smith_loader.js'; import { DwightBlueLoader } from './dwight_blue_loader.js'; @@ -11,6 +10,7 @@ import { HummadTanweerLoader } from './hummad_tanweer_loader.js'; import { JamesCapparellLoader } from './james_capparell_loader.js'; import { JosephCaballeroLoader } from './joseph_caballero_loader.js'; import { KimberleeHaldaneLoader } from './kimberlee_haldane_loader.js'; +import { LjMcwilliamsLoader } from './lj_mcwilliams_loader.js'; import { NileJacksonLoader } from './nile_jackson_loader.js'; import { OyeyemiJimohLoader } from './oyeyemi_jimoh_loader.js'; import { PabloLimonParedesLoader } from './pablo_limon_paredes_loader.js'; @@ -23,9 +23,6 @@ import { ZionBuchananLoader } from './zion_buchanan_loader.js'; export const Loaders = Symbol.for('Loaders'); const LOADER_PROVIDERS = [ - AnthonyMaysLoader, - XavierCruzLoader, - LjMcwilliamsLoader, AmiyahJonesLoader, AngelicaCastilloLoader, AnthonyMaysLoader, @@ -36,6 +33,7 @@ const LOADER_PROVIDERS = [ JamesCapparellLoader, JosephCaballeroLoader, KimberleeHaldaneLoader, + LjMcwilliamsLoader, NileJacksonLoader, OyeyemiJimohLoader, PabloLimonParedesLoader,