Skip to content

feat: adds library data model and related interfaces for media items #640

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
8 changes: 8 additions & 0 deletions lesson_10/libraries/src/library/library_guest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { MediaItem } from './media_item.js';

export interface LibraryGuest {
getId(): string;
getEmail(): string;
getName(): string;
getCheckedOutMediaItems(): ReadonlySet<MediaItem>;
}
5 changes: 5 additions & 0 deletions lesson_10/libraries/src/library/media_item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface MediaItem {
getId(): string;
getTitle(): string;
canCheckOut(): boolean;
}
5 changes: 5 additions & 0 deletions lesson_10/libraries/src/models/checkout_model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CheckoutModel {
mediaItemId: string;
checkoutDate: Date;
dueDate: Date;
}
36 changes: 36 additions & 0 deletions lesson_10/libraries/src/models/library_data_model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { LibraryGuest } from '../library/library_guest.js';
import { MediaItem } from '../library/media_item.js';
import { CheckoutModel } from './checkout_model.js';

export class LibraryDataModel {
public mediaItems: MediaItem[];
public guests: LibraryGuest[];

constructor(mediaItems: MediaItem[], guests: LibraryGuest[]) {
this.mediaItems = mediaItems;
this.guests = guests;
}

public getMediaItems(): MediaItem[] {
return this.mediaItems;
}

public getGuests(): LibraryGuest[] {
return this.guests;
}

public getCheckoutsByEmail(): Map<string, CheckoutModel[]> {
const results = new Map<string, CheckoutModel[]>();
this.guests.forEach((guest) => {
results.set(
guest.getEmail(),
Array.from(guest.getCheckedOutMediaItems()).map((item: MediaItem) => ({
mediaItemId: item.getId(),
checkoutDate: new Date(),
dueDate: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000), // 14 days from now
})),
);
});
return results;
}
}
17 changes: 16 additions & 1 deletion lesson_27/api/src/data/programs.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
"id": "a06f970a-03b7-4cbb-9efd-f4e99029a456",
"title": "Platform Programs",
"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."
},
{
"title": "new prog",
"description": "new ",
"id": "6d084301-3161-4f1a-b995-30478afb7f1d"
},
{
"title": "new ",
"description": "prog2",
"id": "2cc2e17d-1714-4d1d-8a22-dbf53c29e5b5"
},
{
"title": "new",
"description": "new",
"id": "44efa6e4-f7c5-4a36-8c64-4dd70403cb42"
}
]
}
}
29 changes: 29 additions & 0 deletions resources/queries/media_and_guest_queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Query 1: Count of media items by type
SELECT
type,
COUNT(*) as item_count
FROM media_items
GROUP BY type
ORDER BY type;

-- Query 2: Sum of total pages checked out by guests
SELECT
SUM(pages) as total_pages_checked_out
FROM checked_out_items
WHERE guest_id IS NOT NULL;

-- Query 3: All guests and their corresponding checked out items
SELECT
g.id as guest_id,
g.name as guest_name,
g.email as guest_email,
g.phone as guest_phone,
g.address as guest_address,
coi.id as checked_out_item_id,
coi.media_item_id,
coi.checkout_date,
coi.return_date,
coi.pages
FROM guests g
LEFT JOIN checked_out_items coi ON g.id = coi.guest_id
ORDER BY g.id, coi.checkout_date;