Skip to content

Fix: Changed data base refrance name to match the table it is accessing #342

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 5 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 @@ -2,6 +2,7 @@

import com.codedifferently.lesson14.models.LibraryDataModel;
import com.codedifferently.lesson14.repository.LibraryGuestRepository;
import com.codedifferently.lesson14.repository.LibraryUserRepository;
import com.codedifferently.lesson14.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 @@ -16,6 +16,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.codedifferently.lesson14.models;

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;
public String first_name;
public String last_name;
public String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.codedifferently.lesson14.repository;

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

public interface LibraryUserRepository extends CrudRepository<LibraryUserModel, String> {
@Override
List<LibraryUserModel> findAll();
}
24 changes: 24 additions & 0 deletions lesson_14/db/db_app/src/main/resources/queries/mohamedibrahim.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SELECT type, COUNT(*)
FROM media_items
GROUP BY type;

SELECT SUM(pages)
FROM media_items, checked_out_items
WHERE id = item_id ;

SELECT G.type, G.name, CI.*
FROM guests G
LEFT JOIN checked_out_items CI
ON G.email = CI.email;

CREATE TABLE library_users(
id VARCHAR(36) PRIMARY KEY,
email VARCHAR(320),
first_name VARCHAR(50),
last_name VARCHAR(50),
password VARCHAR(72));

INSERT INTO library_users(id, email,first_name, last_name, password)
VALUES ("2584d0d6-fe06-46f2-be8b-6f1a31b57fb3","[email protected]","John", "Book Jr.", "$2a$12$pKO91AkPiVjNjPX0f8Cu1Os6zPO3e7slKayXMGXgeTr2grCwM.0Hu");

SELECT * FROM library_users;
Binary file modified lesson_14/db/db_app/src/main/resources/sqlite/data.db
Binary file not shown.