Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chigazo Lesson 10 Media Loader #343

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
887b8f0
Merge pull request #1 from code-differently/main
A1-4U2T1NN Sep 26, 2024
05ad627
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 27, 2024
5715b6a
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
6c909b0
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
4c1a3f2
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
de19403
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
56aa83d
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 1, 2024
8529105
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 2, 2024
4f76813
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 3, 2024
48bf962
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 5, 2024
1da88b9
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 7, 2024
3068765
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 9, 2024
712efd6
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 11, 2024
5db7413
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 11, 2024
5096f8e
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 12, 2024
09341aa
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 14, 2024
a8f634e
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 15, 2024
b643a4c
feat: created chigazograham.json file
Oct 16, 2024
cae2152
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 16, 2024
68ccb5f
fix: deleted lesson_09 content from main;
Oct 16, 2024
bfc22bf
Merge branch 'code-differently:main' into lesson_10
A1-4U2T1NN Oct 16, 2024
26aa2b9
feat: added loader file into loaders Folder; added loader provider to…
Oct 17, 2024
b0580aa
Merge branch 'code-differently:main' into lesson_10
A1-4U2T1NN Oct 17, 2024
3e8bd38
feat: added chigazo_graham_loader.ts file with completed media loader…
Oct 17, 2024
0cf5223
Merge branch 'lesson_10' of https://github.com/A1-4U2T1NN/code-differ…
Oct 17, 2024
95771a9
chore: converted .pipe csv into manual csv parser;
Oct 17, 2024
35b501f
fix: corrected creating a new line for every variable within array;
Oct 17, 2024
fcbf22c
feat: added id to row array;
Oct 17, 2024
36a334d
chore: made lesson_10 and lesson_10 extra credit seperate branches;
Oct 17, 2024
a694891
fix: recreated loader from a previous commit;
Oct 17, 2024
6d0d2bf
fix: removed id from row array;
Oct 17, 2024
6790a90
chore removed lesson_09 package.json; removed TODO comment;
Oct 18, 2024
75f3eee
feat: added 'id' back into row and new media item;
Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lesson_09/types/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lesson_09/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"csv-parser": "^3.0.0"
}
}
45 changes: 45 additions & 0 deletions lesson_10/libraries/src/loaders/chigazo_graham_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import csv from 'csv-parser';
import fs from 'fs';
import { Credit, MediaItem } from '../models/index.js';
import { Loader } from './loader.js';

export class ChigazoGrahamLoader implements Loader {
getLoaderName(): string {
return 'chigazograham';
}

async loadData(): Promise<MediaItem[]> {
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<MediaItem[]> {
const mediaItems = [];
const readable = fs
.createReadStream('data/media_items.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { id, type, title, genre, year } = row;
mediaItems.push(new MediaItem(id, type, title, genre, year,));
}
return mediaItems;
}

async loadCredits(): Promise<Credit[]> {
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;
}
}
3 changes: 2 additions & 1 deletion lesson_10/libraries/src/loaders/loaders.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Module } from '@nestjs/common';
import { AnthonyMaysLoader } from './anthony_mays_loader.js';
import { XavierCruzLoader } from './xavier_cruz_loader.js';
import { ChigazoGrahamLoader } from './chigazo_graham_loader.js';

export const Loaders = Symbol.for('Loaders');

// Add your quiz provider here.
const LOADER_PROVIDERS = [AnthonyMaysLoader, XavierCruzLoader];
const LOADER_PROVIDERS = [AnthonyMaysLoader, XavierCruzLoader, ChigazoGrahamLoader];

@Module({
providers: [
Expand Down