Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.codedifferently.lesson25.models.LibraryDataModel;
import com.codedifferently.lesson25.repository.LibraryGuestRepository;
import com.codedifferently.lesson25.repository.LibraryUserRepository;
import com.codedifferently.lesson25.repository.MediaItemRepository;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -13,13 +14,15 @@ public final class LibraryDbDataLoader implements LibraryDataLoader {

@Autowired private MediaItemRepository mediaItemsRepository;
@Autowired private LibraryGuestRepository libraryGuestRepository;
@Autowired private LibraryUserRepository libraryUserRepository;

@Override
public LibraryDataModel loadData() throws IOException {
var model = new LibraryDataModel();

model.mediaItems = mediaItemsRepository.findAll();
model.guests = libraryGuestRepository.findAll();
model.users = libraryUserRepository.findAll();

return model;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class LibraryDataModel {

public List<MediaItemModel> mediaItems;
public List<LibraryGuestModel> guests;
public List<LibraryUserModel> users;

public List<MediaItem> getMediaItems() {
List<MediaItem> results = new ArrayList<>();
Expand Down Expand Up @@ -52,6 +53,10 @@ public List<LibraryGuest> getGuests() {
return results;
}

public List<LibraryUserModel> getUsers() {
return this.users;
}

public Map<String, List<CheckoutModel>> getCheckoutsByEmail() {
Map<String, List<CheckoutModel>> results = new HashMap<>();
for (LibraryGuestModel guest : this.guests) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.codedifferently.lesson25.models;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "library_users")
public class LibraryUserModel {

@Id public String id;
public String email;

@Column(name = "first_name")
public String firstName;

@Column(name = "last_name")
public String lastName;

public String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.codedifferently.lesson25.repository;

import com.codedifferently.lesson25.models.LibraryUserModel;
import java.util.List;
import org.springframework.data.repository.CrudRepository;

public interface LibraryUserRepository extends CrudRepository<LibraryUserModel, String> {

@Override
List<LibraryUserModel> findAll();
}
17 changes: 17 additions & 0 deletions lesson_25/db/db_app/src/main/resources/queries/lindaquinoa.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- 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(mi.pages) as total_pages_checked_out
FROM checked_out_items coi
JOIN media_items mi ON coi.item_id = mi.id
WHERE mi.pages IS NOT NULL;

-- Query 3: All 5 guests with corresponding checked_out_items records
SELECT g.type, g.name, g.email, coi.item_id, coi.due_date
FROM guests g
LEFT JOIN checked_out_items coi ON g.email = coi.email
ORDER BY g.name, coi.due_date;
Binary file modified lesson_25/db/db_app/src/main/resources/sqlite/data.db
Binary file not shown.