Skip to content

task: completed lesson 10 work with extra credit #367

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
166 changes: 31 additions & 135 deletions lesson_10/libraries/package-lock.json

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

47 changes: 47 additions & 0 deletions lesson_10/libraries/src/loaders/justin_eklund_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import csv from 'csv-parser';
import fs from 'fs';
import { Credit, MediaItem } from '../models/index.js';
import { Loader } from './loader.js';

export class JustinEklundLoader implements Loader {
getLoaderName(): string {
return 'justineklund';
}

async loadData(): Promise<MediaItem[]> {
const credits = await this.loadCredits();
const mediaItems = await this.loadMediaItems();
const mediamap = new Map<string, MediaItem>();
mediaItems.forEach((mediaItem) => {
mediamap.set(mediaItem.getId(), mediaItem);
}); 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, year } = row;
mediaItems.push(new MediaItem(id, title, type, 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;
}
}
// got assistance from ai and copilot aswell as Meiko and Mercedes
4 changes: 4 additions & 0 deletions lesson_10/libraries/src/loaders/loaders.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Module } from '@nestjs/common';

import { AnthonyMaysLoader } from './anthony_mays_loader.js';
import { JustinEklundLoader } from './justin_eklund_loader.js';
export const Loaders = Symbol.for('Loaders');

const LOADER_PROVIDERS = [AnthonyMaysLoader, JustinEklundLoader];
import { DylanLaffertysLoader } from './dylan_lafferty_loaders.js';

export const Loaders = Symbol.for('Loaders');
Expand Down
Loading