Skip to content

feat: lesson 28 solution - vicente #657

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 3 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
@@ -0,0 +1,30 @@
package com.codedifferently.lesson28.models;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
@Table(name = "library_users")
public class LibraryUserModel {
@Id
@Column(name="user_id")
private String userId;

@Column(name="email")
private String email;

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

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

@Column(name="password")
private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.codedifferently.lesson28.repository;

import org.springframework.data.repository.CrudRepository;

import com.codedifferently.lesson28.models.LibraryUserModel;

public interface LibraryUserRepository extends CrudRepository<LibraryUserModel, String> {
}
29 changes: 29 additions & 0 deletions lesson_28/db/db_app/src/main/resources/queries/vicente.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Active: 1748708794846@@127.0.0.1@3306
-- 1)
SELECT type, COUNT(*) FROM media_items GROUP BY type;
-- 2)
SELECT SUM(pages) FROM media_items
JOIN checked_out_items ON media_items.id = checked_out_items.item_id;
-- 3)
SELECT name, title, item_id FROM guests
LEFT JOIN checked_out_items ON checked_out_items.email = guests.email
LEFT JOIN media_items ON checked_out_items.item_id = media_items.id;

-- Add a new table called library_users to the SQLite database that stores a user's id (UUID formatted string), email,
-- first name, last name, and a password (bcrypt encoded string). Add a model and repository that loads the users into the
-- LibraryDataModel (see LibraryGuestModel and LibraryGuestRepository as examples). Populate the database with a few users.
CREATE TABLE library_users (
user_id VARCHAR(36) PRIMARY KEY,
email VARCHAR(320),
first_name VARCHAR(255),
last_name VARCHAR(255),
password VARCHAR(255)
);

INSERT INTO library_users (user_id, email, first_name, last_name, password) VALUES
('550e8400-e29b-41d4-a716-446655440000', '[email protected]', 'Vicente', 'Test', '$2a$10$7QdB9JXzXTZr1NmVvl3poOT8bq/tBzSvWj7cXzDYPnS6X7CayVuR6'),
('6c9e34ff-57a1-4f3a-9f09-0a3e7461df7a', '[email protected]', 'Kobe', 'Bryant', '$2a$10$zRUj9hULhZlUz3EK2ky9W.B7IYqJS/8RqDhL6FfRMLV7e9UK9uRzO'),
('a7d1f0c5-7d42-4a89-bf18-962dd0c6a1cd', '[email protected]', 'Michael', 'Jordan', '$2a$10$JqwHo6iW4aB7B7A0sXPuBOu9k6fi9i5cz2HgL7tss62tWcyeKkpqG'),
('2f1d38f4-1692-4d28-958e-8a71c792f239', '[email protected]', 'Lebron', 'James', '$2a$10$U1FQtWZdyq6guoZq6k3L6u2nZ8kgWqW6UlIYQGeF3By6F5XLZbP5e'),
('b3c47289-ff23-4ee1-b3a1-0c9e271ac9b4', '[email protected]', 'Steph', 'Curry', '$2a$10$Q9rZw3J6RRIwJtzPf4X0fej4KY6iHLFej1ZJXJZ6nTrYp1MZNoeKa');