Skip to content

Commit 28ffe31

Browse files
committed
feat: adds library data model and related interfaces for media items and guests
1 parent 38a5d4e commit 28ffe31

File tree

7 files changed

+101
-2
lines changed

7 files changed

+101
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { MediaItem } from './media_item.js';
2+
3+
export interface LibraryGuest {
4+
getId(): string;
5+
getEmail(): string;
6+
getName(): string;
7+
getCheckedOutMediaItems(): ReadonlySet<MediaItem>;
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface MediaItem {
2+
getId(): string;
3+
getTitle(): string;
4+
canCheckOut(): boolean;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface CheckoutModel {
2+
mediaItemId: string;
3+
checkoutDate: Date;
4+
dueDate: Date;
5+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { LibraryGuest } from '../library/library_guest.js';
2+
import { MediaItem } from '../library/media_item.js';
3+
import { CheckoutModel } from './checkout_model.js';
4+
5+
export class LibraryDataModel {
6+
public mediaItems: MediaItem[];
7+
public guests: LibraryGuest[];
8+
9+
constructor(mediaItems: MediaItem[], guests: LibraryGuest[]) {
10+
this.mediaItems = mediaItems;
11+
this.guests = guests;
12+
}
13+
14+
public getMediaItems(): MediaItem[] {
15+
return this.mediaItems;
16+
}
17+
18+
public getGuests(): LibraryGuest[] {
19+
return this.guests;
20+
}
21+
22+
public getCheckoutsByEmail(): Map<string, CheckoutModel[]> {
23+
const results = new Map<string, CheckoutModel[]>();
24+
this.guests.forEach((guest) => {
25+
results.set(
26+
guest.getEmail(),
27+
Array.from(guest.getCheckedOutMediaItems()).map((item: MediaItem) => ({
28+
mediaItemId: item.getId(),
29+
checkoutDate: new Date(),
30+
dueDate: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000), // 14 days from now
31+
})),
32+
);
33+
});
34+
return results;
35+
}
36+
}

lesson_27/api/src/data/programs.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
"id": "a06f970a-03b7-4cbb-9efd-f4e99029a456",
2020
"title": "Platform Programs",
2121
"description": "Platform programs are designed for high school graduates, college students, career changers, or professionals looking to develop the technology job readiness skills for today’s workforce."
22+
},
23+
{
24+
"title": "new prog",
25+
"description": "new ",
26+
"id": "6d084301-3161-4f1a-b995-30478afb7f1d"
27+
},
28+
{
29+
"title": "new ",
30+
"description": "prog2",
31+
"id": "2cc2e17d-1714-4d1d-8a22-dbf53c29e5b5"
32+
},
33+
{
34+
"title": "new",
35+
"description": "new",
36+
"id": "44efa6e4-f7c5-4a36-8c64-4dd70403cb42"
2237
}
2338
]
24-
}
39+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
SELECT 1;
1+
SELECT *
2+
FROM ;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- Query 1: Count of media items by type
2+
SELECT
3+
type,
4+
COUNT(*) as item_count
5+
FROM media_items
6+
GROUP BY type
7+
ORDER BY type;
8+
9+
-- Query 2: Sum of total pages checked out by guests
10+
SELECT
11+
SUM(pages) as total_pages_checked_out
12+
FROM checked_out_items
13+
WHERE guest_id IS NOT NULL;
14+
15+
-- Query 3: All guests and their corresponding checked out items
16+
SELECT
17+
g.id as guest_id,
18+
g.name as guest_name,
19+
g.email as guest_email,
20+
g.phone as guest_phone,
21+
g.address as guest_address,
22+
coi.id as checked_out_item_id,
23+
coi.media_item_id,
24+
coi.checkout_date,
25+
coi.return_date,
26+
coi.pages
27+
FROM guests g
28+
LEFT JOIN checked_out_items coi ON g.id = coi.guest_id
29+
ORDER BY g.id, coi.checkout_date;

0 commit comments

Comments
 (0)