Skip to content

Feat: implements sql query and creates a new table for the library_users #635

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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 @@ -16,6 +16,7 @@
public class LibraryDataModel {
public List<MediaItemModel> mediaItems;
public List<LibraryGuestModel> guests;
public List<LibraryUsersModel> users;

public List<MediaItem> getMediaItems() {
List<MediaItem> results = new ArrayList<>();
Expand Down Expand Up @@ -58,4 +59,9 @@ public Map<String, List<CheckoutModel>> getCheckoutsByEmail() {
}
return results;
}

public List<LibraryUsersModel> getUsers() {

return users;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.codedifferently.lesson28.models;

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

@Entity
@Table(name = "library_users")
public class LibraryUsersModel {
@Id public UUID id;

public String email;
public String firstName;
public String lastName;
public String passwordString;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.codedifferently.lesson28.repository;

import com.codedifferently.lesson28.models.LibraryUsersModel;
import java.util.List;
import java.util.UUID;
import org.springframework.data.repository.CrudRepository;

public interface LibraryUsersRepository extends CrudRepository<LibraryUsersModel, UUID> {
@Override
List<LibraryUsersModel> findAll();
}
28 changes: 28 additions & 0 deletions lesson_28/db/db_app/src/main/resources/queries/dylanlafferty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- 1. Count of media items by type
SELECT
type,
COUNT(*) AS total
FROM
media_items
GROUP BY
type;

-- 2. Sum of total pages checked out by guests
SELECT
SUM(pages) AS total_pages
FROM
media_items m
JOIN
checked_out_items c ON m.id = c.item_id;

-- 3. All 5 guests and their corresponding checked-out items
SELECT
g.*,
c.email,
item.title
FROM
guests g
LEFT JOIN
checked_out_items c ON c.email = g.email
LEFT JOIN
media_items item ON item.id = c.item_id;
Binary file modified lesson_28/db/db_app/src/main/resources/sqlite/data.db
Binary file not shown.