From 3c9aee892f831c0ec5a71ed24695fbbb5999c02d Mon Sep 17 00:00:00 2001 From: htanweer244 Date: Thu, 17 Oct 2024 20:38:21 +0000 Subject: [PATCH 1/6] Feat: Fixed two files for lesson 10 by Hummad Tanweer --- .../src/loaders/hummad_tanweer_loader.ts | 46 +++++++++++++++++++ .../libraries/src/loaders/loaders.module.ts | 3 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts diff --git a/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts new file mode 100644 index 00000000..540d2326 --- /dev/null +++ b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts @@ -0,0 +1,46 @@ +import csv from 'csv-parser'; +import fs from 'fs'; +import { Credit, MediaItem } from '../models/index.js'; +import { Loader } from './loader.js'; + +export class HummadTanweerLoader implements Loader { + getLoaderName(): string { + return 'hummadtanweer'; + } + + 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) { + const { id, title, type, year: realeaseYear } = row; + media.push(new MediaItem(id, title, type, realeaseYear, [])); + } + return media; + } + + async loadCredits(): Promise { + const credits = []; + const readable = fs + .createReadStream('data/credits.csv', 'utf-8') + .pipe(csv()); + 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 fe823555..7f573fbe 100644 --- a/lesson_10/libraries/src/loaders/loaders.module.ts +++ b/lesson_10/libraries/src/loaders/loaders.module.ts @@ -1,10 +1,11 @@ import { Module } from '@nestjs/common'; +import { HummadTanweerLoader } from './hummad_tanweer_loader.js'; import { AnthonyMaysLoader } from './anthony_mays_loader.js'; export const Loaders = Symbol.for('Loaders'); // Add your quiz provider here. -const LOADER_PROVIDERS = [AnthonyMaysLoader]; +const LOADER_PROVIDERS = [HummadTanweerLoader, AnthonyMaysLoader]; @Module({ providers: [ From c25523599a80555d0bcf884aaa517959fdc2e31b Mon Sep 17 00:00:00 2001 From: htanweer244 Date: Thu, 17 Oct 2024 22:44:15 +0000 Subject: [PATCH 2/6] resloved conflicts --- lesson_10/libraries/src/loaders/loaders.module.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lesson_10/libraries/src/loaders/loaders.module.ts b/lesson_10/libraries/src/loaders/loaders.module.ts index a8fde6e4..3f81232e 100644 --- a/lesson_10/libraries/src/loaders/loaders.module.ts +++ b/lesson_10/libraries/src/loaders/loaders.module.ts @@ -1,15 +1,13 @@ import { Module } from '@nestjs/common'; import { HummadTanweerLoader } from './hummad_tanweer_loader.js'; import { AnthonyMaysLoader } from './anthony_mays_loader.js'; -import { XavierCruzLoader } from './xavier_cruz_loader.js'; export const Loaders = Symbol.for('Loaders'); // Add your quiz provider here. -lesson_10 -const LOADER_PROVIDERS = [HummadTanweerLoader, AnthonyMaysLoader]; -const LOADER_PROVIDERS = [AnthonyMaysLoader, XavierCruzLoader]; -main + +const LOADER_PROVIDERS = [AnthonyMaysLoader, HummadTanweerLoader]; + @Module({ providers: [ From 9a1c73d6cfff57a28943e5028a27db75edf7fbc1 Mon Sep 17 00:00:00 2001 From: htanweer244 Date: Thu, 17 Oct 2024 22:59:00 +0000 Subject: [PATCH 3/6] changes to loader file --- lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts index 540d2326..890d16f1 100644 --- a/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts +++ b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts @@ -20,7 +20,6 @@ export class HummadTanweerLoader implements Loader { } async loadMediaItems(): Promise { - // TODO: Implement this method. const media = []; const readable = fs .createReadStream('data/media_items.csv', 'utf-8') From d78519e2fda5ed8f0a1678cc9cc23b6abc1f54c7 Mon Sep 17 00:00:00 2001 From: htanweer244 Date: Thu, 17 Oct 2024 20:38:21 +0000 Subject: [PATCH 4/6] Feat: Fixed two files for lesson 10 by Hummad Tanweer --- .../src/loaders/hummad_tanweer_loader.ts | 46 +++++++++++++++++++ .../libraries/src/loaders/loaders.module.ts | 8 ++++ 2 files changed, 54 insertions(+) create mode 100644 lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts diff --git a/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts new file mode 100644 index 00000000..540d2326 --- /dev/null +++ b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts @@ -0,0 +1,46 @@ +import csv from 'csv-parser'; +import fs from 'fs'; +import { Credit, MediaItem } from '../models/index.js'; +import { Loader } from './loader.js'; + +export class HummadTanweerLoader implements Loader { + getLoaderName(): string { + return 'hummadtanweer'; + } + + 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) { + const { id, title, type, year: realeaseYear } = row; + media.push(new MediaItem(id, title, type, realeaseYear, [])); + } + return media; + } + + async loadCredits(): Promise { + const credits = []; + const readable = fs + .createReadStream('data/credits.csv', 'utf-8') + .pipe(csv()); + 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 33ccc5d1..29129da8 100644 --- a/lesson_10/libraries/src/loaders/loaders.module.ts +++ b/lesson_10/libraries/src/loaders/loaders.module.ts @@ -1,5 +1,9 @@ import { Module } from '@nestjs/common'; +<<<<<<< HEAD import { AngelicaCastilloLoader } from './angelica_castillo_loader.js'; +======= +import { HummadTanweerLoader } from './hummad_tanweer_loader.js'; +>>>>>>> 3c9aee8 (Feat: Fixed two files for lesson 10 by Hummad Tanweer) import { AnthonyMaysLoader } from './anthony_mays_loader.js'; import { JamesCapparellLoader } from './james_capparell_loader.js'; import { NileJacksonLoader } from './nile_jackson_loader.js'; @@ -8,6 +12,7 @@ import { XavierCruzLoader } from './xavier_cruz_loader.js'; export const Loaders = Symbol.for('Loaders'); // Add your quiz provider here. +<<<<<<< HEAD const LOADER_PROVIDERS = [ AnthonyMaysLoader, AngelicaCastilloLoader, @@ -15,6 +20,9 @@ const LOADER_PROVIDERS = [ NileJacksonLoader, XavierCruzLoader, ]; +======= +const LOADER_PROVIDERS = [HummadTanweerLoader, AnthonyMaysLoader]; +>>>>>>> 3c9aee8 (Feat: Fixed two files for lesson 10 by Hummad Tanweer) @Module({ providers: [ From 9a4fcd534bf3abe9d4934342a67a203b93862923 Mon Sep 17 00:00:00 2001 From: htanweer244 Date: Thu, 17 Oct 2024 22:44:15 +0000 Subject: [PATCH 5/6] resloved conflicts --- lesson_10/libraries/src/loaders/loaders.module.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lesson_10/libraries/src/loaders/loaders.module.ts b/lesson_10/libraries/src/loaders/loaders.module.ts index 29129da8..1e361310 100644 --- a/lesson_10/libraries/src/loaders/loaders.module.ts +++ b/lesson_10/libraries/src/loaders/loaders.module.ts @@ -5,14 +5,18 @@ import { AngelicaCastilloLoader } from './angelica_castillo_loader.js'; import { HummadTanweerLoader } from './hummad_tanweer_loader.js'; >>>>>>> 3c9aee8 (Feat: Fixed two files for lesson 10 by Hummad Tanweer) import { AnthonyMaysLoader } from './anthony_mays_loader.js'; +<<<<<<< HEAD import { JamesCapparellLoader } from './james_capparell_loader.js'; import { NileJacksonLoader } from './nile_jackson_loader.js'; import { XavierCruzLoader } from './xavier_cruz_loader.js'; +======= +>>>>>>> c255235 (resloved conflicts) export const Loaders = Symbol.for('Loaders'); // Add your quiz provider here. <<<<<<< HEAD +<<<<<<< HEAD const LOADER_PROVIDERS = [ AnthonyMaysLoader, AngelicaCastilloLoader, @@ -23,6 +27,11 @@ const LOADER_PROVIDERS = [ ======= const LOADER_PROVIDERS = [HummadTanweerLoader, AnthonyMaysLoader]; >>>>>>> 3c9aee8 (Feat: Fixed two files for lesson 10 by Hummad Tanweer) +======= + +const LOADER_PROVIDERS = [AnthonyMaysLoader, HummadTanweerLoader]; + +>>>>>>> c255235 (resloved conflicts) @Module({ providers: [ From 99f2f6c3d1f7e9136787415c26eef7a41cb2ac7f Mon Sep 17 00:00:00 2001 From: htanweer244 Date: Thu, 17 Oct 2024 22:59:00 +0000 Subject: [PATCH 6/6] changes to loader file --- lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts index 540d2326..890d16f1 100644 --- a/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts +++ b/lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts @@ -20,7 +20,6 @@ export class HummadTanweerLoader implements Loader { } async loadMediaItems(): Promise { - // TODO: Implement this method. const media = []; const readable = fs .createReadStream('data/media_items.csv', 'utf-8')