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 @@ -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 @@ -59,4 +60,12 @@ public Map<String, List<CheckoutModel>> getCheckoutsByEmail() {
}
return results;
}

public List<LibraryUserModel> getUsers() {
if (this.users == null) {
return new ArrayList<>();
} else {
return this.users;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.codedifferently.lesson25.models;

import jakarta.persistence.Column;
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;

@Column(unique = true, nullable = false)
public String email;

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

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

@Column(nullable = false)
public String password;
}
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);
}
19 changes: 19 additions & 0 deletions lesson_25/db/db_app/src/main/resources/queries/tyranricejr.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- SQL queries by tyranricejr for Lesson 25 assignment

-- Query 1: Count of media items by type
SELECT type, COUNT(*) as 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 and any corresponding records in the checked_out_items table
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.