Skip to content
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 != null ? this.users : new ArrayList<>();
}

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,17 @@
package com.codedifferently.lesson25.models;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.UUID;

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

@Id public UUID id;
public String email;
public String firstName;
public String lastName;
public String passwordHash;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codedifferently.lesson25.repository;

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

public interface LibraryUserRepository extends CrudRepository<LibraryUserModel, UUID> {

@Override
List<LibraryUserModel> findAll();

LibraryUserModel findByEmail(String email);
}
24 changes: 24 additions & 0 deletions lesson_25/db/db_app/src/main/resources/queries/trinitiejackson.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SELECT type, COUNT(*) AS count
FROM media_items
GROUP BY type;

SELECT SUM(pages)
FROM media_items
JOIN checked_out_items ON media_items.id = checked_out_items.item_id;

SELECT guests.name, guests.email, media_items.title
FROM guests
LEFT JOIN checked_out_items ON guests.email = checked_out_items.email
LEFT JOIN media_items ON checked_out_items.item_id = media_items.id;

CREATE TABLE library_users (
id TEXT PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
password_hash TEXT NOT NULL
);

INSERT INTO library_users (id, email, first_name, last_name, password_hash)
VALUES ('550e8400-e29b-41d4-a716-446655440000', '[email protected]', 'Trinitie', 'Jackson', '$2y$10$fBjbX04w/CPZ4YZNJpLBR.hyuz1YXbyIFj92udVrckYEXjPzhoDHq'),
('550e8400-e29b-41d4-a716-446655440001', '[email protected]', 'John', 'Doe', '$2y$10$QnMskk1wZ.T5148M9aALAuAeCHPRW72e3aN41Ysms4gOu1/YSjJn.');
Binary file modified lesson_25/db/db_app/src/main/resources/sqlite/data.db
Binary file not shown.