Skip to content

Commit 6f11cb4

Browse files
committed
Merge branch 'main' of https://github.com/angie-3/code-differently-24-q4 into angielesson14
2 parents 1d7b8f1 + 6185a38 commit 6f11cb4

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 LjMcwilliamsLoader implements Loader {
7+
getLoaderName(): string {
8+
return 'ljmcwilliams';
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+
// TODO: Implement this method.
24+
const media = [];
25+
const readable = fs
26+
.createReadStream('data/media_items.csv', 'utf-8')
27+
.pipe(csv());
28+
for await (const row of readable) {
29+
/**This destructures the CSV file rows. */
30+
const { id, type, title, year } = row;
31+
media.push(new MediaItem(id, title, type, year, []));
32+
}
33+
return media;
34+
}
35+
36+
/*
37+
An asyncchronous function named loadCredits
38+
returns a Promise of an array of Credit Objects.
39+
*/
40+
async loadCredits(): Promise<Credit[]> {
41+
//The empty credits array will store parsed credit data
42+
const credits = [];
43+
/**
44+
* This var creates a readable stream from the CSV file and
45+
* is piped through the csv function to parse the data.
46+
*/
47+
const readable = fs
48+
.createReadStream('data/credits.csv', 'utf-8')
49+
.pipe(csv());
50+
//This asynchronously iterates over each row of the parsed CSV data.
51+
for await (const row of readable) {
52+
const { media_item_id, role, name } = row;
53+
credits.push(new Credit(media_item_id, name, role));
54+
}
55+
return credits;
56+
}
57+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { HummadTanweerLoader } from './hummad_tanweer_loader.js';
1010
import { JamesCapparellLoader } from './james_capparell_loader.js';
1111
import { JosephCaballeroLoader } from './joseph_caballero_loader.js';
1212
import { KimberleeHaldaneLoader } from './kimberlee_haldane_loader.js';
13+
import { LjMcwilliamsLoader } from './lj_mcwilliams_loader.js';
1314
import { NileJacksonLoader } from './nile_jackson_loader.js';
1415
import { OyeyemiJimohLoader } from './oyeyemi_jimoh_loader.js';
1516
import { PabloLimonParedesLoader } from './pablo_limon_paredes_loader.js';
@@ -32,6 +33,7 @@ const LOADER_PROVIDERS = [
3233
JamesCapparellLoader,
3334
JosephCaballeroLoader,
3435
KimberleeHaldaneLoader,
36+
LjMcwilliamsLoader,
3537
NileJacksonLoader,
3638
OyeyemiJimohLoader,
3739
PabloLimonParedesLoader,

lesson_13/maps_java/maps_app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232

3333
application {
3434
// Define the main class for the application.
35-
mainClass.set("com.codedifferently.lesson12.Lesson12")
35+
mainClass.set("com.codedifferently.lesson13.Lesson13")
3636
}
3737

3838
tasks.named<Test>("test") {

lesson_14/exceptions/exceptions_app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232

3333
application {
3434
// Define the main class for the application.
35-
mainClass.set("com.codedifferently.lesson12.Lesson12")
35+
mainClass.set("com.codedifferently.lesson14.Lesson14")
3636
}
3737

3838
tasks.named<Test>("test") {

lesson_14/exceptions/exceptions_app/src/test/java/com/codedifferently/lesson14/ecommerce/EcommerceSystemTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ void testPlaceOrder_productDoesNotExist() throws Exception {
4040
assertThatThrownBy(() -> ecommerceSystem.placeOrder("1", 1))
4141
.isInstanceOf(ProductNotFoundException.class)
4242
.hasMessage("Product with ID 1 not found");
43+
44+
// Act
45+
assertThatThrownBy(() -> ecommerceSystem.placeOrder("34", 1))
46+
.isInstanceOf(ProductNotFoundException.class)
47+
.hasMessage("Product with ID 34 not found");
4348
}
4449

4550
@Test
@@ -58,18 +63,23 @@ void testCheckOrderStatus_orderDoesNotExist() {
5863
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("1"))
5964
.isInstanceOf(OrderNotFoundException.class)
6065
.hasMessage("Order with ID 1 not found");
66+
67+
// Act
68+
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("33"))
69+
.isInstanceOf(OrderNotFoundException.class)
70+
.hasMessage("Order with ID 33 not found");
6171
}
6272

6373
@Test
6474
void testCheckOrderStatus_orderCancelled() throws Exception {
6575
// Arrange
66-
ecommerceSystem.addProduct("1", "Laptop");
67-
String orderId = ecommerceSystem.placeOrder("1", 1);
76+
ecommerceSystem.addProduct("58", "Laptop");
77+
String orderId = ecommerceSystem.placeOrder("58", 1);
6878
ecommerceSystem.cancelOrder(orderId);
6979

7080
// Act
71-
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("1"))
81+
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("58"))
7282
.isInstanceOf(OrderNotFoundException.class)
73-
.hasMessage("Order with ID 1 not found");
83+
.hasMessage("Order with ID 58 not found");
7484
}
7585
}

0 commit comments

Comments
 (0)