Skip to content

Commit 62fd069

Browse files
feat: adds A'nanatawa's media items loader (#394)
* Adds: ananatawa_loader to Lesson10 and modifies loaders.module.ts file * feat: adds A'nanatawas Loader and edits loaders.module.ts file * Fixed A'nanatawas_loader so tests pass --------- Co-authored-by: Anthony D. Mays <[email protected]>
1 parent 50680f2 commit 62fd069

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import csv from 'csv-parser';
2+
import fs from 'fs';
3+
import { Credit, MediaItem } from '../models/index.js';
4+
import { Loader } from './loader.js';
5+
6+
export class AnanatawasLoader implements Loader {
7+
getLoaderName(): string {
8+
return 'ananatawa';
9+
}
10+
11+
async loadData(): Promise<MediaItem[]> {
12+
const credits = await this.loadCredits();
13+
const mediaItems = await this.loadMediaItems();
14+
15+
console.log(
16+
`Loaded ${credits.length} credits and ${mediaItems.length} media items`,
17+
);
18+
19+
return [...mediaItems.values()];
20+
}
21+
22+
async loadMediaItems(): Promise<MediaItem[]> {
23+
const MediaItems = [];
24+
const readable = fs
25+
.createReadStream('data/media_items.csv', 'utf-8')
26+
.pipe(csv());
27+
for await (const row of readable) {
28+
const { id, title, type, year } = row;
29+
MediaItems.push(new MediaItem(id, title, type, year, []));
30+
}
31+
return MediaItems;
32+
}
33+
34+
async loadCredits(): Promise<Credit[]> {
35+
const credits = [];
36+
const readable = fs
37+
.createReadStream('data/credits.csv', 'utf-8')
38+
.pipe(csv());
39+
for await (const row of readable) {
40+
const { media_item_id, role, name } = row;
41+
credits.push(new Credit(media_item_id, name, role));
42+
}
43+
return credits;
44+
}
45+
}

lesson_10/libraries/src/loaders/loaders.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Module } from '@nestjs/common';
2+
import { AnanatawasLoader } from './ananatawa_loader.js';
23
import { AnthonyMaysLoader } from './anthony_mays_loader.js';
34
import { BryanaSingletonBarnhartLoader } from './bryana_singleton_barnhart_loader.js';
45
import { ChanelHuttLoader } from './chanel_hutt_loader.js';
@@ -21,6 +22,7 @@ import { OliviaJamesLoader } from './olivia_james_loader.js';
2122
export const Loaders = Symbol.for('Loaders');
2223

2324
const LOADER_PROVIDERS = [
25+
AnanatawasLoader,
2426
AnthonyMaysLoader,
2527
NiaPackLoader,
2628
BryanaSingletonBarnhartLoader,
@@ -53,4 +55,3 @@ const LOADER_PROVIDERS = [
5355
exports: [Loaders],
5456
})
5557
export class LoadersModule {}
56-
// got assistance from ai and copilot aswell as Meiko ,Mercedes and Dillon

0 commit comments

Comments
 (0)