From ac5c2167ba2807dcfca5cc7c06a2871deb69e4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Mon, 25 Nov 2024 11:09:12 +0000 Subject: [PATCH 01/22] test --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index abacc66c5..b532135d8 100644 --- a/README.md +++ b/README.md @@ -99,3 +99,6 @@ complexity, in Java. It's OK if you need to pause here with Acebook and learn ho ### Spring Security and Auth0 - [ ] I can explain how this app is secured + +test + From b1e9b585e4d2d6f2d0987e5f3e8cd850360ba216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Mon, 25 Nov 2024 11:15:42 +0000 Subject: [PATCH 02/22] test2 --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index b532135d8..4a049042e 100644 --- a/README.md +++ b/README.md @@ -100,5 +100,4 @@ complexity, in Java. It's OK if you need to pause here with Acebook and learn ho - [ ] I can explain how this app is secured -test - +test2 From d3e89fb3e76aac7e5e6555f57932d1d38d54d778 Mon Sep 17 00:00:00 2001 From: Valeria Date: Mon, 25 Nov 2024 12:14:42 +0000 Subject: [PATCH 03/22] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c64b53754..de3480724 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dependency-reduced-pom.xml .factorypath .project .settings/ +*.yml \ No newline at end of file From a2abeb1b457aa27be965f0ca5be3f6c1429c00e5 Mon Sep 17 00:00:00 2001 From: Valeria Date: Mon, 25 Nov 2024 12:38:13 +0000 Subject: [PATCH 04/22] add credentials in env file and add that file in gitignore --- .gitignore | 2 +- src/main/resources/application.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index de3480724..6ef8a3252 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ dependency-reduced-pom.xml .factorypath .project .settings/ -*.yml \ No newline at end of file +.env \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 699e8575a..6066ee3fe 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ okta: oauth2: - issuer: https://dev-edward-andress.uk.auth0.com/ + issuer: ${OKTA_ISSUER} client-id: ${OKTA_CLIENT_ID} client-secret: ${OKTA_CLIENT_SECRET} From 9fbebc460c6c5eca66a4218dd96091cd5d1e0856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Mon, 25 Nov 2024 13:11:43 +0000 Subject: [PATCH 05/22] env file update --- .gitignore | 1 + pom.xml | 10 ++++++++++ src/main/resources/application.yml | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c64b53754..6ef8a3252 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dependency-reduced-pom.xml .factorypath .project .settings/ +.env \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8daa56c4e..7f65cf08e 100644 --- a/pom.xml +++ b/pom.xml @@ -95,8 +95,18 @@ org.thymeleaf.extras thymeleaf-extras-springsecurity6 + + nz.net.ultraq.thymeleaf + thymeleaf-layout-dialect + + + me.paulschwarz + spring-dotenv + 3.0.0 + + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 699e8575a..6066ee3fe 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ okta: oauth2: - issuer: https://dev-edward-andress.uk.auth0.com/ + issuer: ${OKTA_ISSUER} client-id: ${OKTA_CLIENT_ID} client-secret: ${OKTA_CLIENT_SECRET} From 507a7a79f5c8b19dd6dfafd17716bbc2179fdcce Mon Sep 17 00:00:00 2001 From: Valeria Date: Tue, 26 Nov 2024 09:32:32 +0000 Subject: [PATCH 06/22] add part where we hide credentials --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a049042e..f62a36b5b 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,28 @@ Below, you'll find specific learning objectives for each tool. ## QuickStart Instructions - Fork and clone this repository to your machine -- Open the codebase in an IDE like InteliJ or VSCode +- Open the codebase in an IDE like IntelliJ or VSCode - Create a new Postgres database called `acebook_springboot_development` - Install Maven `brew install maven` - [Set up Auth0](https://journey.makers.tech/pages/auth0) (you only need the "Create an Auth0 app" section) - NOTE: Each member of the team will need their own Auth0 app + - Create a file .env with this structure: + OKTA_ISSUER= + OKTA_CLIENT_ID= + OKTA_CLIENT_SECRET= + + Make sure the naming matches the one on the file application.yml: + issuer: ${OKTA_ISSUER} + client-id: ${OKTA_CLIENT_ID} + client-secret: ${OKTA_CLIENT_SECRET} +- update your .gitignore with .env +- add dependencies in pom.xml: + + com.okta.spring + okta-spring-boot-starter + 3.0.7 + + - Build the app and start the server, using the Maven command `mvn spring-boot:run` > The database migrations will run automatically at this point - Visit `http://localhost:8080/` to sign up From bf1d6e46d06e596985426ccd273ae3ba0d3885e7 Mon Sep 17 00:00:00 2001 From: Jess Pates Date: Tue, 26 Nov 2024 13:11:30 +0000 Subject: [PATCH 07/22] db tables created --- .../migration/V10__create_messages_table.sql | 8 ++ .../V11__create_friendships_table.sql | 8 ++ .../V12__add_timestamp_to_messages.sql | 2 + .../V13__add_timestamp_to_friendships.sql | 2 + .../V14__add_notifications_table.sql | 19 ++++ .../V15__add_pending_to_friendship_status.sql | 2 + .../db/migration/V3__update_users_table.sql | 4 + .../db/migration/V4__update_posts_table.sql | 5 + .../migration/V5__create_post_likes_table.sql | 8 ++ .../migration/V6__create_comments_table.sql | 7 ++ .../V7__add_commenter_id_to_comments.sql | 3 + .../V8__create_comment_likes_table.sql | 8 ++ .../db/migration/V9__create_chats_table.sql | 7 ++ src/main/resources/db/seeds/R__dev_seed.sql | 102 ++++++++++++++++++ 14 files changed, 185 insertions(+) create mode 100644 src/main/resources/db/migration/V10__create_messages_table.sql create mode 100644 src/main/resources/db/migration/V11__create_friendships_table.sql create mode 100644 src/main/resources/db/migration/V12__add_timestamp_to_messages.sql create mode 100644 src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql create mode 100644 src/main/resources/db/migration/V14__add_notifications_table.sql create mode 100644 src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql create mode 100644 src/main/resources/db/migration/V3__update_users_table.sql create mode 100644 src/main/resources/db/migration/V4__update_posts_table.sql create mode 100644 src/main/resources/db/migration/V5__create_post_likes_table.sql create mode 100644 src/main/resources/db/migration/V6__create_comments_table.sql create mode 100644 src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql create mode 100644 src/main/resources/db/migration/V8__create_comment_likes_table.sql create mode 100644 src/main/resources/db/migration/V9__create_chats_table.sql create mode 100644 src/main/resources/db/seeds/R__dev_seed.sql diff --git a/src/main/resources/db/migration/V10__create_messages_table.sql b/src/main/resources/db/migration/V10__create_messages_table.sql new file mode 100644 index 000000000..d515c7128 --- /dev/null +++ b/src/main/resources/db/migration/V10__create_messages_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE messages ( + id bigserial PRIMARY KEY, + sender_id INT, + chat_id INT, + message TEXT, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); diff --git a/src/main/resources/db/migration/V11__create_friendships_table.sql b/src/main/resources/db/migration/V11__create_friendships_table.sql new file mode 100644 index 000000000..660ef725e --- /dev/null +++ b/src/main/resources/db/migration/V11__create_friendships_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE friendships ( + id bigserial PRIMARY KEY, + sender_id INT, + receiver_id INT, + status VARCHAR(20), + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE +); diff --git a/src/main/resources/db/migration/V12__add_timestamp_to_messages.sql b/src/main/resources/db/migration/V12__add_timestamp_to_messages.sql new file mode 100644 index 000000000..a4d4245f4 --- /dev/null +++ b/src/main/resources/db/migration/V12__add_timestamp_to_messages.sql @@ -0,0 +1,2 @@ +ALTER TABLE messages +ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP; \ No newline at end of file diff --git a/src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql b/src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql new file mode 100644 index 000000000..9b8560879 --- /dev/null +++ b/src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql @@ -0,0 +1,2 @@ +ALTER TABLE friendships +ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP; \ No newline at end of file diff --git a/src/main/resources/db/migration/V14__add_notifications_table.sql b/src/main/resources/db/migration/V14__add_notifications_table.sql new file mode 100644 index 000000000..96d3f85ef --- /dev/null +++ b/src/main/resources/db/migration/V14__add_notifications_table.sql @@ -0,0 +1,19 @@ +CREATE TABLE notifications ( + id bigserial PRIMARY KEY, + sender_id INT, + receiver_id INT, + type VARCHAR(50), + content VARCHAR(255), + is_read BOOLEAN DEFAULT FALSE, + post_id INT, + comment_id INT, + friendship_id INT, + chat_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, + CONSTRAINT fk_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, + CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql b/src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql new file mode 100644 index 000000000..ff2f9fe8b --- /dev/null +++ b/src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql @@ -0,0 +1,2 @@ +ALTER TABLE friendships +ALTER COLUMN status SET DEFAULT 'pending'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V3__update_users_table.sql b/src/main/resources/db/migration/V3__update_users_table.sql new file mode 100644 index 000000000..6222d1d38 --- /dev/null +++ b/src/main/resources/db/migration/V3__update_users_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE users +ADD my_status VARCHAR(255), +ADD profile_photo_url TEXT, +ADD bio TEXT; \ No newline at end of file diff --git a/src/main/resources/db/migration/V4__update_posts_table.sql b/src/main/resources/db/migration/V4__update_posts_table.sql new file mode 100644 index 000000000..82f6f736b --- /dev/null +++ b/src/main/resources/db/migration/V4__update_posts_table.sql @@ -0,0 +1,5 @@ +ALTER TABLE posts +ADD photo_url TEXT, +ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +ADD user_id INT, +ADD CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; \ No newline at end of file diff --git a/src/main/resources/db/migration/V5__create_post_likes_table.sql b/src/main/resources/db/migration/V5__create_post_likes_table.sql new file mode 100644 index 000000000..87f413664 --- /dev/null +++ b/src/main/resources/db/migration/V5__create_post_likes_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE post_likes ( + id bigserial PRIMARY KEY, + user_id INT, + post_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE +); diff --git a/src/main/resources/db/migration/V6__create_comments_table.sql b/src/main/resources/db/migration/V6__create_comments_table.sql new file mode 100644 index 000000000..54f298b99 --- /dev/null +++ b/src/main/resources/db/migration/V6__create_comments_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE comments ( + id bigserial PRIMARY KEY, + post_id INT, + content TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE +); diff --git a/src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql b/src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql new file mode 100644 index 000000000..04c4de25e --- /dev/null +++ b/src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql @@ -0,0 +1,3 @@ +ALTER TABLE comments +ADD commenter_id INT, +ADD CONSTRAINT fk_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE; \ No newline at end of file diff --git a/src/main/resources/db/migration/V8__create_comment_likes_table.sql b/src/main/resources/db/migration/V8__create_comment_likes_table.sql new file mode 100644 index 000000000..b50ce57aa --- /dev/null +++ b/src/main/resources/db/migration/V8__create_comment_likes_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE comment_likes ( + id bigserial PRIMARY KEY, + user_id INT, + comment_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE +); diff --git a/src/main/resources/db/migration/V9__create_chats_table.sql b/src/main/resources/db/migration/V9__create_chats_table.sql new file mode 100644 index 000000000..b7f3bf060 --- /dev/null +++ b/src/main/resources/db/migration/V9__create_chats_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE chats ( + id bigserial PRIMARY KEY, + user_1_id INT, + user_2_id INT, + CONSTRAINT fk_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE +); diff --git a/src/main/resources/db/seeds/R__dev_seed.sql b/src/main/resources/db/seeds/R__dev_seed.sql new file mode 100644 index 000000000..926dc0946 --- /dev/null +++ b/src/main/resources/db/seeds/R__dev_seed.sql @@ -0,0 +1,102 @@ +--DROP TABLES +DROP TABLE IF EXISTS posts; +DROP TABLE IF EXISTS post_likes; +DROP TABLE IF EXISTS comments; +DROP TABLE IF EXISTS comment_likes; +DROP TABLE IF EXISTS chats; +DROP TABLE IF EXISTS messages; +DROP TABLE IF EXISTS friendships; +DROP TABLE IF EXISTS notifications; + +--CREATE POSTS TABLE +CREATE TABLE posts ( + id bigserial PRIMARY KEY, + content varchar(250) NOT NULL, + photo_url TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + user_id INT, + CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE POST_LIKES TABLE +CREATE TABLE post_likes ( + id bigserial PRIMARY KEY, + user_id INT, + post_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE +); + +--CREATE COMMENTS TABLE +CREATE TABLE comments ( + id bigserial PRIMARY KEY, + post_id INT, + content TEXT, + commenter_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE COMMENT_LIKES TABLE +CREATE TABLE comment_likes ( + id bigserial PRIMARY KEY, + user_id INT, + comment_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE +); + +--CREATE CHATS TABLE +CREATE TABLE chats ( + id bigserial PRIMARY KEY, + user_1_id INT, + user_2_id INT, + CONSTRAINT fk_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE MESSAGES TABLE +CREATE TABLE messages ( + id bigserial PRIMARY KEY, + sender_id INT, + chat_id INT, + message TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); + +--CREATE FRIENDSHIPS TABLE +CREATE TABLE friendships ( + id bigserial PRIMARY KEY, + sender_id INT, + receiver_id INT, + status VARCHAR(20) DEFAULT 'pending', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE NOTIFICATIONS TABLE +CREATE TABLE notifications ( + id bigserial PRIMARY KEY, + sender_id INT, + receiver_id INT, + type VARCHAR(50), + content VARCHAR(255), + is_read BOOLEAN DEFAULT FALSE, + post_id INT, + comment_id INT, + friendship_id INT, + chat_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, + CONSTRAINT fk_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, + CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); \ No newline at end of file From 45714e72d0e2e512bb2fcabce8dc93234a511b15 Mon Sep 17 00:00:00 2001 From: Valeria Date: Tue, 26 Nov 2024 13:16:40 +0000 Subject: [PATCH 08/22] update --- README.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f62a36b5b..b19302467 100644 --- a/README.md +++ b/README.md @@ -20,21 +20,24 @@ Below, you'll find specific learning objectives for each tool. - [Set up Auth0](https://journey.makers.tech/pages/auth0) (you only need the "Create an Auth0 app" section) - NOTE: Each member of the team will need their own Auth0 app - Create a file .env with this structure: - OKTA_ISSUER= - OKTA_CLIENT_ID= + > OKTA_ISSUER=
+ OKTA_CLIENT_ID=
OKTA_CLIENT_SECRET= - Make sure the naming matches the one on the file application.yml: - issuer: ${OKTA_ISSUER} - client-id: ${OKTA_CLIENT_ID} - client-secret: ${OKTA_CLIENT_SECRET} + Make sure the naming matches the one on the file application.yml:
+ issuer: ${OKTA_ISSUER}
+ client-id: ${OKTA_CLIENT_ID}
+ client-secret: ${OKTA_CLIENT_SECRET}
+
- update your .gitignore with .env -- add dependencies in pom.xml: + +- add dependencies in pom.xml:
+
- com.okta.spring - okta-spring-boot-starter - 3.0.7 - + com.okta.spring + okta-spring-boot-starter + 3.0.7 + - Build the app and start the server, using the Maven command `mvn spring-boot:run` > The database migrations will run automatically at this point From 2ab557971eab6fe03711518ab791c9cd9f727399 Mon Sep 17 00:00:00 2001 From: Jess Pates Date: Tue, 26 Nov 2024 16:01:40 +0000 Subject: [PATCH 09/22] create db tables --- .DS_Store | Bin 0 -> 6148 bytes .../migration/V10__create_messages_table.sql | 8 -- .../V11__create_friendships_table.sql | 8 -- .../V12__add_timestamp_to_messages.sql | 2 - .../V13__add_timestamp_to_friendships.sql | 2 - .../V14__add_notifications_table.sql | 19 ---- .../V15__add_pending_to_friendship_status.sql | 2 - .../db/migration/V3__create_tables.sql | 95 ++++++++++++++++++ .../db/migration/V3__update_users_table.sql | 4 - .../db/migration/V4__add_names_to_users.sql | 4 + .../db/migration/V4__update_posts_table.sql | 5 - .../migration/V5__create_post_likes_table.sql | 8 -- .../migration/V6__create_comments_table.sql | 7 -- .../V7__add_commenter_id_to_comments.sql | 3 - .../V8__create_comment_likes_table.sql | 8 -- .../db/migration/V9__create_chats_table.sql | 7 -- src/main/resources/db/seeds/R__dev_seed.sql | 23 ++++- 17 files changed, 117 insertions(+), 88 deletions(-) create mode 100644 .DS_Store delete mode 100644 src/main/resources/db/migration/V10__create_messages_table.sql delete mode 100644 src/main/resources/db/migration/V11__create_friendships_table.sql delete mode 100644 src/main/resources/db/migration/V12__add_timestamp_to_messages.sql delete mode 100644 src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql delete mode 100644 src/main/resources/db/migration/V14__add_notifications_table.sql delete mode 100644 src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql create mode 100644 src/main/resources/db/migration/V3__create_tables.sql delete mode 100644 src/main/resources/db/migration/V3__update_users_table.sql create mode 100644 src/main/resources/db/migration/V4__add_names_to_users.sql delete mode 100644 src/main/resources/db/migration/V4__update_posts_table.sql delete mode 100644 src/main/resources/db/migration/V5__create_post_likes_table.sql delete mode 100644 src/main/resources/db/migration/V6__create_comments_table.sql delete mode 100644 src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql delete mode 100644 src/main/resources/db/migration/V8__create_comment_likes_table.sql delete mode 100644 src/main/resources/db/migration/V9__create_chats_table.sql diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8be003822890097b528201382f0f0b3ba4a812b9 GIT binary patch literal 6148 zcmeHKL5tHs82zTLZNeh-ps<&PfY(x6-CYDPv33t0ylg}dDmB@ZHJHtmB(*{*-Ch8NBgJf*EX!Zn;bM8dTRC++6 z&M~LrNh&X*R7N{&TlgCt;Ct7lgsv#0ORC>LekdLxhu>7F>GxYiVwp@$W0qcNuV7~+AZQ&g3AGTHNfOX(M zc7Wdx9+J^FSZP$R4m4^D0PLWw0)74vWQ}LgH&|)J2tsHnP)mi`VhAlq-7`GjV5L#Z zNtn%tFuyF!4n?S6$N4=)C*fwtCOpK?HSronWA zOEPQg&c*Rs>mlDDIha>z{2@U{EydvSQhbP1fx5>Xpl`6!hzi1f2q+tDV;%UT4txjO C6^Tm# literal 0 HcmV?d00001 diff --git a/src/main/resources/db/migration/V10__create_messages_table.sql b/src/main/resources/db/migration/V10__create_messages_table.sql deleted file mode 100644 index d515c7128..000000000 --- a/src/main/resources/db/migration/V10__create_messages_table.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE messages ( - id bigserial PRIMARY KEY, - sender_id INT, - chat_id INT, - message TEXT, - CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE -); diff --git a/src/main/resources/db/migration/V11__create_friendships_table.sql b/src/main/resources/db/migration/V11__create_friendships_table.sql deleted file mode 100644 index 660ef725e..000000000 --- a/src/main/resources/db/migration/V11__create_friendships_table.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE friendships ( - id bigserial PRIMARY KEY, - sender_id INT, - receiver_id INT, - status VARCHAR(20), - CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE -); diff --git a/src/main/resources/db/migration/V12__add_timestamp_to_messages.sql b/src/main/resources/db/migration/V12__add_timestamp_to_messages.sql deleted file mode 100644 index a4d4245f4..000000000 --- a/src/main/resources/db/migration/V12__add_timestamp_to_messages.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE messages -ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP; \ No newline at end of file diff --git a/src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql b/src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql deleted file mode 100644 index 9b8560879..000000000 --- a/src/main/resources/db/migration/V13__add_timestamp_to_friendships.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE friendships -ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP; \ No newline at end of file diff --git a/src/main/resources/db/migration/V14__add_notifications_table.sql b/src/main/resources/db/migration/V14__add_notifications_table.sql deleted file mode 100644 index 96d3f85ef..000000000 --- a/src/main/resources/db/migration/V14__add_notifications_table.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE TABLE notifications ( - id bigserial PRIMARY KEY, - sender_id INT, - receiver_id INT, - type VARCHAR(50), - content VARCHAR(255), - is_read BOOLEAN DEFAULT FALSE, - post_id INT, - comment_id INT, - friendship_id INT, - chat_id INT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, - CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, - CONSTRAINT fk_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, - CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE -); \ No newline at end of file diff --git a/src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql b/src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql deleted file mode 100644 index ff2f9fe8b..000000000 --- a/src/main/resources/db/migration/V15__add_pending_to_friendship_status.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE friendships -ALTER COLUMN status SET DEFAULT 'pending'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V3__create_tables.sql b/src/main/resources/db/migration/V3__create_tables.sql new file mode 100644 index 000000000..4e67ba85e --- /dev/null +++ b/src/main/resources/db/migration/V3__create_tables.sql @@ -0,0 +1,95 @@ +--UPDATE EXISTING USERS TABLE +ALTER TABLE users +ADD my_status VARCHAR(255), +ADD profile_photo_url TEXT, +ADD bio TEXT; + +--UPDATE EXISTING POSTS TABLE +ALTER TABLE posts +ADD photo_url TEXT, +ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +ADD user_id INT, +ADD CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; + +--CREATE POST_LIKES TABLE +CREATE TABLE post_likes ( + id bigserial PRIMARY KEY, + user_id INT, + post_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE +); + +--CREATE COMMENTS TABLE +CREATE TABLE comments ( + id bigserial PRIMARY KEY, + post_id INT, + content TEXT, + commenter_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE COMMENT_LIKES TABLE +CREATE TABLE comment_likes ( + id bigserial PRIMARY KEY, + user_id INT, + comment_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE +); + +--CREATE CHATS TABLE +CREATE TABLE chats ( + id bigserial PRIMARY KEY, + user_1_id INT, + user_2_id INT, + CONSTRAINT fk_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE MESSAGES TABLE +CREATE TABLE messages ( + id bigserial PRIMARY KEY, + sender_id INT, + chat_id INT, + message TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); + +--CREATE FRIENDSHIPS TABLE +CREATE TABLE friendships ( + id bigserial PRIMARY KEY, + sender_id INT, + receiver_id INT, + status VARCHAR(20) DEFAULT 'pending', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE NOTIFICATIONS TABLE +CREATE TABLE notifications ( + id bigserial PRIMARY KEY, + sender_id INT, + receiver_id INT, + type VARCHAR(50), + content VARCHAR(255), + is_read BOOLEAN DEFAULT FALSE, + post_id INT, + comment_id INT, + friendship_id INT, + chat_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, + CONSTRAINT fk_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, + CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V3__update_users_table.sql b/src/main/resources/db/migration/V3__update_users_table.sql deleted file mode 100644 index 6222d1d38..000000000 --- a/src/main/resources/db/migration/V3__update_users_table.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE users -ADD my_status VARCHAR(255), -ADD profile_photo_url TEXT, -ADD bio TEXT; \ No newline at end of file diff --git a/src/main/resources/db/migration/V4__add_names_to_users.sql b/src/main/resources/db/migration/V4__add_names_to_users.sql new file mode 100644 index 000000000..5ca8970fe --- /dev/null +++ b/src/main/resources/db/migration/V4__add_names_to_users.sql @@ -0,0 +1,4 @@ +--UPDATE EXISTING USERS TABLE +ALTER TABLE users +ADD first_name VARCHAR(100), +ADD last_name VARCHAR(100); \ No newline at end of file diff --git a/src/main/resources/db/migration/V4__update_posts_table.sql b/src/main/resources/db/migration/V4__update_posts_table.sql deleted file mode 100644 index 82f6f736b..000000000 --- a/src/main/resources/db/migration/V4__update_posts_table.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE posts -ADD photo_url TEXT, -ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -ADD user_id INT, -ADD CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; \ No newline at end of file diff --git a/src/main/resources/db/migration/V5__create_post_likes_table.sql b/src/main/resources/db/migration/V5__create_post_likes_table.sql deleted file mode 100644 index 87f413664..000000000 --- a/src/main/resources/db/migration/V5__create_post_likes_table.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE post_likes ( - id bigserial PRIMARY KEY, - user_id INT, - post_id INT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE -); diff --git a/src/main/resources/db/migration/V6__create_comments_table.sql b/src/main/resources/db/migration/V6__create_comments_table.sql deleted file mode 100644 index 54f298b99..000000000 --- a/src/main/resources/db/migration/V6__create_comments_table.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE comments ( - id bigserial PRIMARY KEY, - post_id INT, - content TEXT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE -); diff --git a/src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql b/src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql deleted file mode 100644 index 04c4de25e..000000000 --- a/src/main/resources/db/migration/V7__add_commenter_id_to_comments.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE comments -ADD commenter_id INT, -ADD CONSTRAINT fk_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE; \ No newline at end of file diff --git a/src/main/resources/db/migration/V8__create_comment_likes_table.sql b/src/main/resources/db/migration/V8__create_comment_likes_table.sql deleted file mode 100644 index b50ce57aa..000000000 --- a/src/main/resources/db/migration/V8__create_comment_likes_table.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE comment_likes ( - id bigserial PRIMARY KEY, - user_id INT, - comment_id INT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE -); diff --git a/src/main/resources/db/migration/V9__create_chats_table.sql b/src/main/resources/db/migration/V9__create_chats_table.sql deleted file mode 100644 index b7f3bf060..000000000 --- a/src/main/resources/db/migration/V9__create_chats_table.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE chats ( - id bigserial PRIMARY KEY, - user_1_id INT, - user_2_id INT, - CONSTRAINT fk_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE -); diff --git a/src/main/resources/db/seeds/R__dev_seed.sql b/src/main/resources/db/seeds/R__dev_seed.sql index 926dc0946..c33808a08 100644 --- a/src/main/resources/db/seeds/R__dev_seed.sql +++ b/src/main/resources/db/seeds/R__dev_seed.sql @@ -1,12 +1,12 @@ --DROP TABLES -DROP TABLE IF EXISTS posts; +DROP TABLE IF EXISTS notifications; DROP TABLE IF EXISTS post_likes; -DROP TABLE IF EXISTS comments; +DROP TABLE IF EXISTS posts; DROP TABLE IF EXISTS comment_likes; -DROP TABLE IF EXISTS chats; +DROP TABLE IF EXISTS comments; DROP TABLE IF EXISTS messages; +DROP TABLE IF EXISTS chats; DROP TABLE IF EXISTS friendships; -DROP TABLE IF EXISTS notifications; --CREATE POSTS TABLE CREATE TABLE posts ( @@ -99,4 +99,17 @@ CREATE TABLE notifications ( CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, CONSTRAINT fk_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE -); \ No newline at end of file +); + +--CREATE POSTS TABLE +--CREATE TABLE posts ( +-- id bigserial PRIMARY KEY, +-- content varchar(250) NOT NULL, +-- photo_url TEXT, +-- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +-- user_id INT, +-- CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +--); + +--INSERT POSTS SEEDS +INSERT INTO (content, photo_url, user_id) VALUES (); \ No newline at end of file From e9a185e2e3b93570b90c0c15ce5ffdc616b790d5 Mon Sep 17 00:00:00 2001 From: Jess Pates Date: Wed, 27 Nov 2024 09:34:28 +0000 Subject: [PATCH 10/22] seed data for db --- src/main/resources/db/seeds/R__dev_seed.sql | 282 +++++++++++++++++--- 1 file changed, 240 insertions(+), 42 deletions(-) diff --git a/src/main/resources/db/seeds/R__dev_seed.sql b/src/main/resources/db/seeds/R__dev_seed.sql index c33808a08..a5178afad 100644 --- a/src/main/resources/db/seeds/R__dev_seed.sql +++ b/src/main/resources/db/seeds/R__dev_seed.sql @@ -1,12 +1,15 @@ +--COMMAND TO RUN: psql -d acebook_springboot_development -f src/main/resources/db/seeds/R__dev_seed.sql +--WILL NEED USERS WITH IDS 1-5 (columns: id, username, enabled, my_status, profile_photo_url, bio, first_name, last_name) + --DROP TABLES -DROP TABLE IF EXISTS notifications; -DROP TABLE IF EXISTS post_likes; -DROP TABLE IF EXISTS posts; -DROP TABLE IF EXISTS comment_likes; -DROP TABLE IF EXISTS comments; -DROP TABLE IF EXISTS messages; -DROP TABLE IF EXISTS chats; -DROP TABLE IF EXISTS friendships; +DROP TABLE IF EXISTS notifications CASCADE; +DROP TABLE IF EXISTS post_likes CASCADE; +DROP TABLE IF EXISTS posts CASCADE; +DROP TABLE IF EXISTS comment_likes CASCADE; +DROP TABLE IF EXISTS comments CASCADE; +DROP TABLE IF EXISTS messages CASCADE; +DROP TABLE IF EXISTS chats CASCADE; +DROP TABLE IF EXISTS friendships CASCADE; --CREATE POSTS TABLE CREATE TABLE posts ( @@ -15,7 +18,7 @@ CREATE TABLE posts ( photo_url TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, user_id INT, - CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + CONSTRAINT fk_posts_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ); --CREATE POST_LIKES TABLE @@ -24,8 +27,8 @@ CREATE TABLE post_likes ( user_id INT, post_id INT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE + CONSTRAINT fk_postlikes_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_postlikes_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE ); --CREATE COMMENTS TABLE @@ -35,8 +38,8 @@ CREATE TABLE comments ( content TEXT, commenter_id INT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, - CONSTRAINT fk_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE + CONSTRAINT fk_comments_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_comments_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE ); --CREATE COMMENT_LIKES TABLE @@ -45,8 +48,8 @@ CREATE TABLE comment_likes ( user_id INT, comment_id INT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE + CONSTRAINT fk_commentlikes_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_commentlikes_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE ); --CREATE CHATS TABLE @@ -54,8 +57,8 @@ CREATE TABLE chats ( id bigserial PRIMARY KEY, user_1_id INT, user_2_id INT, - CONSTRAINT fk_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE + CONSTRAINT fk_chats_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_chats_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE ); --CREATE MESSAGES TABLE @@ -65,8 +68,8 @@ CREATE TABLE messages ( chat_id INT, message TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE + CONSTRAINT fk_messages_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_messages_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE ); --CREATE FRIENDSHIPS TABLE @@ -76,8 +79,8 @@ CREATE TABLE friendships ( receiver_id INT, status VARCHAR(20) DEFAULT 'pending', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE + CONSTRAINT fk_friendships_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_friendships_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE ); --CREATE NOTIFICATIONS TABLE @@ -88,28 +91,223 @@ CREATE TABLE notifications ( type VARCHAR(50), content VARCHAR(255), is_read BOOLEAN DEFAULT FALSE, - post_id INT, - comment_id INT, - friendship_id INT, - chat_id INT, + post_id INT NULL, + comment_id INT NULL, + friendship_id INT NULL, + chat_id INT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, - CONSTRAINT fk_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, - CONSTRAINT fk_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, - CONSTRAINT fk_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE + CONSTRAINT fk_notifications_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE ); ---CREATE POSTS TABLE ---CREATE TABLE posts ( --- id bigserial PRIMARY KEY, --- content varchar(250) NOT NULL, --- photo_url TEXT, --- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- user_id INT, --- CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ---); - --INSERT POSTS SEEDS -INSERT INTO (content, photo_url, user_id) VALUES (); \ No newline at end of file +INSERT INTO posts (content, photo_url, user_id, created_at) VALUES +('Sunday brunch 🥑🍞', 'https://plus.unsplash.com/premium_photo-1673581430690-0b42ab287ae9?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-11-25 08:00:00'), +('Anyone else obsessed with the new season of Stranger Things? Can’t stop watching! 📺🍿', NULL, 2, '2024-11-01 09:00:00'), +('Had the best weekend hike! Nature really does wonders for the soul. 🌲🌄', 'https://images.unsplash.com/photo-1501554728187-ce583db33af7?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 3, '2024-11-01 10:00:00'), +('First day at my new job today! Excited for this new chapter. ✨ #NewBeginnings', NULL, 1, '2024-11-02 08:00:00'), +('Halloween activities #Boo', 'https://plus.unsplash.com/premium_photo-1714618933590-febf07fce40c?q=80&w=2660&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-10-31 18:00:00'), +('Starting the weekend right 💪 #FitnessGoals #Crossfit', 'https://images.unsplash.com/photo-1623874514711-0f321325f318?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 2, '2024-11-22 09:30:00'), +('Caught a sunset that looked like it was straight out of a painting tonight. 🌅', 'https://plus.unsplash.com/premium_photo-1673002094195-f18084be89ce?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 3, '2024-11-02 10:45:00'), +('He just knocked over my coffee. Good job he''s cute. 🐱☕️', 'https://images.unsplash.com/photo-1513360371669-4adf3dd7dff8?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 4, '2024-11-02 12:00:00'), +('Tried a new recipe today: vegan meatballs! It was surprisingly delicious. 🍝 #CookingAdventures', 'https://images.unsplash.com/photo-1515516969-d4008cc6241a?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-11-24 19:00:00'), +('Weekend plans: Netflix and pizza, obviously. 🍕🍿 #LazySaturday', NULL, 2, '2024-10-28 16:00:00'); + +--INSERT POST_LIKES SEEDS +INSERT INTO post_likes (user_id, post_id, created_at) VALUES +(5, 1, '2024-11-25 08:05:23'), +(2, 1, '2024-11-25 09:12:47'), +(3, 1, '2024-11-25 10:25:10'), +(4, 1, '2024-11-26 14:15:00'), +(1, 2, '2024-11-01 10:30:00'), +(3, 2, '2024-11-01 15:40:23'), +(5, 2, '2024-11-02 11:10:50'), +(2, 3, '2024-11-02 12:45:00'), +(4, 3, '2024-11-03 16:30:23'), +(2, 5, '2024-11-02 08:25:30'), +(1, 6, '2024-11-22 09:50:00'), +(5, 6, '2024-11-22 10:35:45'), +(3, 6, '2024-11-22 11:20:30'), +(4, 6, '2024-11-22 13:55:40'), +(4, 7, '2024-11-02 12:05:12'), +(1, 8, '2024-10-29 15:25:33'), +(5, 8, '2024-10-30 10:40:20'), +(2, 9, '2024-11-24 20:05:02'), +(1, 10, '2024-11-02 12:10:00'), +(3, 10, '2024-11-02 12:30:15'), +(4, 10, '2024-11-02 13:00:45'); + +--INSERT COMMENT SEEDS +INSERT INTO comments (post_id, content, commenter_id, created_at) VALUES +(1, 'Looks delicious! 🍽️', 2, '2024-11-25 08:10:00'), +(1, 'I love brunch! Can I join next time? 😅', 3, '2024-11-25 09:20:30'), +(2, 'I’m obsessed too! Just finished the new season. 😱', 1, '2024-11-01 10:10:00'), +(3, 'Sounds like an amazing hike! Where did you go?', 4, '2024-11-01 14:25:50'), +(3, 'I need to get outdoors more! 🥾', 1, '2024-11-03 08:00:00'), +(4, 'Congratulations! Wishing you all the best! 🎉', 2, '2024-11-02 08:15:00'), +(4, 'Exciting! What’s your new role? ✨', 5, '2024-11-02 09:00:00'), +(4, 'Good luck on your new journey! 👏', 3, '2024-11-02 10:30:30'), +(5, 'Love the Halloween spirit! 🎃👻', 2, '2024-11-01 18:15:00'), +(5, 'Halloween is my favorite time of year! 🎃', 1, '2024-11-02 09:00:00'), +(6, 'I need to start working out like you! 🤩', 5, '2024-11-22 11:10:20'), +(6, 'I love your motivation! 💯', 4, '2024-11-22 13:20:45'), +(7, 'That’s a breathtaking view! 🌅', 5, '2024-11-02 11:00:00'), +(8, 'Cats are the best troublemakers! 😹', 3, '2024-11-02 12:10:00'), +(8, 'Haha, my cat does the same thing. So cute though! 🐱', 5, '2024-11-02 12:25:30'), +(9, 'I need to try this recipe! Vegan meatballs sound amazing!', 3, '2024-11-24 20:10:00'), +(9, 'This looks so good! Can you share the recipe? 😍', 5, '2024-11-24 20:30:30'); + +--INSERT COMMENT LIKES +INSERT INTO comment_likes (user_id, comment_id, created_at) VALUES +(1, 1, '2024-11-25 08:15:00'), +(3, 1, '2024-11-25 08:25:00'), +(4, 2, '2024-11-25 09:30:00'), +(1, 2, '2024-11-25 09:40:00'), +(5, 3, '2024-11-25 10:00:00'), +(2, 5, '2024-11-01 14:15:00'), +(5, 5, '2024-11-01 15:00:00'), +(1, 6, '2024-11-01 14:40:00'), +(1, 7, '2024-11-01 15:00:00'), +(1, 8, '2024-11-02 11:00:00'), +(1, 9, '2024-11-02 09:15:00'), +(4, 9, '2024-11-02 09:30:00'), +(1, 10, '2024-11-22 11:15:00'), +(2, 10, '2024-11-22 12:00:00'), +(1, 11, '2024-11-02 11:10:00'), +(4, 12, '2024-11-02 12:30:00'), +(3, 13, '2024-11-02 12:30:00'), +(4, 13, '2024-11-02 12:35:00'), +(4, 14, '2024-11-24 20:40:00'), +(4, 15, '2024-11-24 20:45:00'); + +--INSERT CHATS +INSERT INTO chats (user_1_id, user_2_id) VALUES +(1, 2), +(1, 3), +(4, 5); + +--INSERT MESSAGES +INSERT INTO messages (sender_id, chat_id, message, created_at) VALUES +(1, 1, 'Hey, how are you?', '2024-11-15 09:00:00'), +(2, 1, 'I''m good! How about you?', '2024-11-15 09:05:00'), +(1, 1, 'Doing well! Just got back from a trip.', '2024-11-15 09:15:00'), +(2, 1, 'That sounds awesome! Tell me more.', '2024-11-15 09:20:00'), + +(1, 2, 'Hey, just wanted to check in.', '2024-11-10 08:00:00'), +(3, 2, 'Everything is great here! How are you?', '2024-11-10 08:10:00'), +(1, 2, 'Can''t complain. Work is a bit hectic though.', '2024-11-10 08:15:00'), +(3, 2, 'Same here! But we''ll get through it.', '2024-11-10 08:30:00'), + +(4, 3, 'Hey, thanks for adding me! It was great meeting you last night.', '2024-11-26 14:30:00'), +(5, 3, 'No problem! It was so fun meeting you too. How''s everything going?', '2024-11-26 14:35:00'); + +--INSERT FRIENDSHIP SEEDS +--only pending, confirmed or blocked +INSERT INTO friendships (sender_id, receiver_id, status, created_at) VALUES +(1, 2, 'confirmed', '2024-09-15 10:00:00'), +(1, 3, 'confirmed', '2024-09-20 14:30:00'), +(1, 4, 'blocked', '2024-09-25 09:00:00'), +(1, 5, 'confirmed', '2024-09-28 16:45:00'), +(2, 3, 'confirmed', '2024-10-05 11:00:00'), +(2, 4, 'confirmed', '2024-10-06 13:10:00'), +(3, 5, 'pending', '2024-10-07 14:25:00'), +(4, 5, 'confirmed', '2024-10-09 09:45:00'); + +--INSERT NOTIFICATION SEEDS +-- Notifications for Post Likes +INSERT INTO notifications (sender_id, receiver_id, type, content, post_id, created_at, is_read) VALUES +(5, 1, 'like', 'Jess liked your post', 1, '2024-11-25 08:05:23', TRUE), +(2, 1, 'like', 'Tobi liked your post', 1, '2024-11-25 09:12:47', TRUE), +(3, 1, 'like', 'Shaeera liked your post', 1, '2024-11-25 10:25:10', TRUE), +(4, 1, 'like', 'Alessandro liked your post', 1, '2024-11-26 14:15:00', FALSE), +(1, 2, 'like', 'Valeria liked your post', 2, '2024-11-01 10:30:00', TRUE), +(3, 2, 'like', 'Shaeera liked your post', 2, '2024-11-01 15:40:23', TRUE), +(5, 2, 'like', 'Jess liked your post', 2, '2024-11-02 11:10:50', TRUE), +(2, 3, 'like', 'Tobi liked your post', 3, '2024-11-02 12:45:00', TRUE), +(4, 3, 'like', 'Alessandro liked your post', 3, '2024-11-03 16:30:23', TRUE), +(2, 1, 'like', 'Tobi liked your post', 5, '2024-11-02 08:25:30', TRUE), +(1, 2, 'like', 'Valeria liked your post', 6, '2024-11-22 09:50:00', TRUE), +(5, 2, 'like', 'Jess liked your post', 6, '2024-11-22 10:35:45', TRUE), +(3, 2, 'like', 'Shaeera liked your post', 6, '2024-11-22 11:20:30', TRUE), +(4, 2, 'like', 'Alessandro liked your post', 6, '2024-11-22 13:55:40', TRUE), +(4, 3, 'like', 'Alessandro liked your post', 7, '2024-11-02 12:05:12', TRUE), +(1, 4, 'like', 'Valeria liked your post', 8, '2024-10-29 15:25:33', TRUE), +(5, 4, 'like', 'Jess liked your post', 8, '2024-10-30 10:40:20', TRUE), +(2, 1, 'like', 'Tobi liked your post', 9, '2024-11-24 20:05:02', TRUE), +(1, 2, 'like', 'Valeria liked your post', 10, '2024-11-02 12:10:00', TRUE), +(3, 2, 'like', 'Shaeera liked your post', 10, '2024-11-02 12:30:15', TRUE), +(4, 2, 'like', 'Alessandro liked your post', 10, '2024-11-02 13:00:45', TRUE); + +-- Notifications for Comments +INSERT INTO notifications (sender_id, receiver_id, type, content, post_id, created_at, is_read) VALUES +(2, 1, 'comment', 'Tobi commented on your post', 1, '2024-11-25 08:10:00', TRUE), +(3, 1, 'comment', 'Shaeera commented on your post', 1, '2024-11-25 09:20:30', TRUE), +(1, 2, 'comment', 'Valeria commented on your post', 2, '2024-11-01 10:10:00', TRUE), +(4, 3, 'comment', 'Alessandro commented on your post', 3, '2024-11-01 14:25:50', TRUE), +(1, 3, 'comment', 'Valeria commented on your post', 3, '2024-11-03 08:00:00', TRUE), +(2, 1, 'comment', 'Tobi commented on your post', 4, '2024-11-02 08:15:00', TRUE), +(5, 1, 'comment', 'Jess commented on your post', 4, '2024-11-02 09:00:00', TRUE), +(3, 1, 'comment', 'Shaeera commented on your post', 4, '2024-11-02 10:30:30', TRUE), +(2, 1, 'comment', 'Tobi commented on your post', 5, '2024-11-01 18:15:00', TRUE), +(1, 1, 'comment', 'Valeria commented on your post', 5, '2024-11-02 09:00:00', TRUE), +(5, 2, 'comment', 'Jess commented on your post', 6, '2024-11-22 11:10:20', TRUE), +(4, 2, 'comment', 'Alessandro commented on your post', 6, '2024-11-22 13:20:45', TRUE), +(5, 3, 'comment', 'Jess commented on your post', 7, '2024-11-02 11:00:00', TRUE), +(3, 4, 'comment', 'Shaeera commented on your post', 8, '2024-11-02 12:10:00', TRUE), +(5, 4, 'comment', 'Jess commented on your post', 8, '2024-11-02 12:25:30', TRUE), +(3, 1, 'comment', 'Shaeera commented on your post', 9, '2024-11-24 20:10:00', TRUE), +(5, 1, 'comment', 'Jess commented on your post', 9, '2024-11-24 20:30:30', TRUE); + +-- Notifications for Comment Likes +INSERT INTO notifications (sender_id, receiver_id, type, content, comment_id, created_at, is_read) VALUES +(1, 2, 'like', 'Valeria liked your comment', 1, '2024-11-25 08:15:00', TRUE), +(3, 2, 'like', 'Shaeera liked your comment', 1, '2024-11-25 08:25:00', TRUE), +(4, 3, 'like', 'Alessandro liked your comment', 2, '2024-11-25 09:30:00', TRUE), +(1, 3, 'like', 'Valeria liked your comment', 2, '2024-11-25 09:40:00', TRUE), +(5, 1, 'like', 'Jess liked your comment', 3, '2024-11-25 10:00:00', TRUE), +(2, 1, 'like', 'Tobi liked your comment', 5, '2024-11-01 14:15:00', TRUE), +(5, 1, 'like', 'Jess liked your comment', 5, '2024-11-01 15:00:00', TRUE), +(1, 2, 'like', 'Valeria liked your comment', 6, '2024-11-01 14:40:00', TRUE), +(1, 5, 'like', 'Valeria liked your comment', 7, '2024-11-01 15:00:00', TRUE), +(1, 3, 'like', 'Valeria liked your comment', 8, '2024-11-02 11:00:00', TRUE), +(1, 2, 'like', 'Valeria liked your comment', 9, '2024-11-02 09:15:00', TRUE), +(4, 2, 'like', 'Alessandro liked your comment', 9, '2024-11-02 09:30:00', TRUE), +(1, 1, 'like', 'Valeria liked your comment', 10, '2024-11-22 11:15:00', TRUE), +(2, 1, 'like', 'Valeria liked your comment', 10, '2024-11-22 12:00:00', TRUE), +(1, 5, 'like', 'Valeria liked your comment', 11, '2024-11-02 11:10:00', TRUE), +(4, 4, 'like', 'Alessandro liked your comment', 12, '2024-11-02 12:30:00', TRUE), +(3, 5, 'like', 'Shaeera liked your comment', 13, '2024-11-02 12:30:00', TRUE), +(4, 5, 'like', 'Alessandro liked your comment', 13, '2024-11-02 12:35:00', TRUE), +(4, 3, 'like', 'Alessandro liked your comment', 14, '2024-11-24 20:40:00', TRUE), +(4, 5, 'like', 'Alessandro liked your comment', 15, '2024-11-24 20:45:00', TRUE); + +-- Notifications for Friend Requests +INSERT INTO notifications (sender_id, receiver_id, type, content, friendship_id, created_at, is_read) VALUES +(1, 2, 'friend_request', 'Valeria sent you a friend request', 1, '2024-09-15 10:00:00', TRUE), +(1, 3, 'friend_request', 'Valeria sent you a friend request', 2, '2024-09-20 14:30:00', TRUE), +(1, 4, 'friend_request', 'Valeria sent you a friend request', 3, '2024-09-28 16:45:00', TRUE), +(1, 5, 'friend_request', 'Valeria sent you a friend request', 4, '2024-10-05 11:00:00', TRUE), +(2, 3, 'friend_request', 'Tobi sent you a friend request', 5, '2024-10-06 13:10:00', TRUE), +(2, 4, 'friend_request', 'Tobi sent you a friend request', 6, '2024-10-07 14:25:00', TRUE), +(3, 5, 'friend_request', 'Shaeera sent you a friend request', 7, '2024-10-07 14:25:00', TRUE), +(4, 5, 'friend_request', 'Alessandro sent you a friend request', 8, '2024-10-09 09:45:00', TRUE); + +-- Notifications for Messages +INSERT INTO notifications (sender_id, receiver_id, type, content, chat_id, created_at, is_read) VALUES +(1, 2, 'message', 'Valeria sent you a message: "Hey, how are you?"', 1, '2024-11-15 09:00:00', TRUE), +(2, 1, 'message', 'Tobi sent you a message: "I''m good! How about you?"', 1, '2024-11-15 09:05:00', TRUE), +(1, 2, 'message', 'Valeria sent you a message: "Doing well! Just got back from a trip."', 1, '2024-11-15 09:15:00', TRUE), +(2, 1, 'message', 'Tobi sent you a message: "That sounds awesome! Tell me more."', 1, '2024-11-15 09:20:00', TRUE), + +(1, 3, 'message', 'Valeria sent you a message: "Hey, just wanted to check in."', 2, '2024-11-10 08:00:00', TRUE), +(3, 1, 'message', 'Shaeera sent you a message: "Everything is great here! How are you?"', 2, '2024-11-10 08:10:00', TRUE), +(1, 3, 'message', 'Valeria sent you a message: "Can''t complain. Work is a bit hectic though."', 2, '2024-11-10 08:15:00', TRUE), +(3, 1, 'message', 'Shaeera sent you a message: "Same here! But we''ll get through it."', 2, '2024-11-10 08:30:00', TRUE), + +(4, 5, 'message', 'Alessandro sent you a message: "Hey, thanks for adding me! It was great meeting you last night."', 3, '2024-11-26 14:30:00', TRUE), +(5, 4, 'message', 'Jess sent you a message: "No problem! It was so fun meeting you too. How''s everything going?"', 3, '2024-11-26 14:35:00', FALSE); + From 1502df65323a446b216d47c81f9f2a2de453552a Mon Sep 17 00:00:00 2001 From: Valeria Date: Wed, 27 Nov 2024 10:02:10 +0000 Subject: [PATCH 11/22] update with indentation --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b19302467..ed629b73e 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,13 @@ Below, you'll find specific learning objectives for each tool. - update your .gitignore with .env - add dependencies in pom.xml:
-
+```xml com.okta.spring okta-spring-boot-starter 3.0.7 - +``` - Build the app and start the server, using the Maven command `mvn spring-boot:run` > The database migrations will run automatically at this point - Visit `http://localhost:8080/` to sign up @@ -119,5 +119,3 @@ complexity, in Java. It's OK if you need to pause here with Acebook and learn ho ### Spring Security and Auth0 - [ ] I can explain how this app is secured - -test2 From e3710b626ca1eef0940c8de3da9fe5b866e67940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Wed, 27 Nov 2024 14:05:25 +0000 Subject: [PATCH 12/22] edit seed file --- src/main/resources/db/seeds/R__new_dev_seed.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/db/seeds/R__new_dev_seed.sql diff --git a/src/main/resources/db/seeds/R__new_dev_seed.sql b/src/main/resources/db/seeds/R__new_dev_seed.sql new file mode 100644 index 000000000..e69de29bb From 61e4de4b6a6e605370ce15f25941d5be23d40f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Wed, 27 Nov 2024 14:06:04 +0000 Subject: [PATCH 13/22] edit seed file --- .../resources/db/seeds/R__new_dev_seed.sql | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/main/resources/db/seeds/R__new_dev_seed.sql b/src/main/resources/db/seeds/R__new_dev_seed.sql index e69de29bb..4f9b6d317 100644 --- a/src/main/resources/db/seeds/R__new_dev_seed.sql +++ b/src/main/resources/db/seeds/R__new_dev_seed.sql @@ -0,0 +1,92 @@ +--CREATE POSTS TABLE +CREATE TABLE posts ( + id bigserial PRIMARY KEY, + content varchar(250) NOT NULL, + photo_url TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + user_id bigint, -- Change from INT to BIGINT + CONSTRAINT fk_posts_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE POST_LIKES TABLE +CREATE TABLE post_likes ( + id bigserial PRIMARY KEY, + user_id bigint, -- Change from INT to BIGINT + post_id bigint, -- Change from INT to BIGINT + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_postlikes_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_postlikes_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE +); + +--CREATE COMMENTS TABLE +CREATE TABLE comments ( + id bigserial PRIMARY KEY, + post_id bigint, -- Change from INT to BIGINT + content TEXT, + commenter_id bigint, -- Change from INT to BIGINT + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_comments_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_comments_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE COMMENT_LIKES TABLE +CREATE TABLE comment_likes ( + id bigserial PRIMARY KEY, + user_id bigint, -- Change from INT to BIGINT + comment_id bigint, -- Change from INT to BIGINT + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_commentlikes_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_commentlikes_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE +); + +--CREATE CHATS TABLE +CREATE TABLE chats ( + id bigserial PRIMARY KEY, + user_1_id bigint, -- Change from INT to BIGINT + user_2_id bigint, -- Change from INT to BIGINT + CONSTRAINT fk_chats_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_chats_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE MESSAGES TABLE +CREATE TABLE messages ( + id bigserial PRIMARY KEY, + sender_id bigint, -- Change from INT to BIGINT + chat_id bigint, -- Change from INT to BIGINT + message TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_messages_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_messages_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); + +--CREATE FRIENDSHIPS TABLE +CREATE TABLE friendships ( + id bigserial PRIMARY KEY, + sender_id bigint, -- Change from INT to BIGINT + receiver_id bigint, -- Change from INT to BIGINT + status VARCHAR(20) DEFAULT 'pending', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_friendships_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_friendships_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE +); + +--CREATE NOTIFICATIONS TABLE +CREATE TABLE notifications ( + id bigserial PRIMARY KEY, + sender_id bigint, -- Change from INT to BIGINT + receiver_id bigint, -- Change from INT to BIGINT + type VARCHAR(50), + content VARCHAR(255), + is_read BOOLEAN DEFAULT FALSE, + post_id bigint, -- Change from INT to BIGINT + comment_id bigint, -- Change from INT to BIGINT + friendship_id bigint, -- Change from INT to BIGINT + chat_id bigint, -- Change from INT to BIGINT + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_notifications_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, + CONSTRAINT fk_notifications_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE +); From 1942243f54669ff3a54ebf58dd70c23d539c7c8c Mon Sep 17 00:00:00 2001 From: Valeria Date: Wed, 27 Nov 2024 14:20:42 +0000 Subject: [PATCH 14/22] add version 5 migration --- src/main/resources/db/migration/V5__change_foreign_keys_type.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/db/migration/V5__change_foreign_keys_type.sql diff --git a/src/main/resources/db/migration/V5__change_foreign_keys_type.sql b/src/main/resources/db/migration/V5__change_foreign_keys_type.sql new file mode 100644 index 000000000..e69de29bb From e7e107f4926fac01cf42807acac6dd0411481019 Mon Sep 17 00:00:00 2001 From: Jess Pates Date: Wed, 27 Nov 2024 14:26:28 +0000 Subject: [PATCH 15/22] navbar and search results --- pom.xml | 5 ++ .../acebook/controller/SearchController.java | 26 +++++++++ src/main/resources/static/css/main.css | 43 +++++++++++++++ src/main/resources/static/css/nav.css | 53 +++++++++++++++++++ .../static/{main.css => css/posts.css} | 0 src/main/resources/static/css/search.css | 40 ++++++++++++++ .../resources/templates/fragments/nav.html | 23 ++++++++ src/main/resources/templates/posts/index.html | 10 +++- .../resources/templates/search/index.html | 34 ++++++++++++ 9 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/makersacademy/acebook/controller/SearchController.java create mode 100644 src/main/resources/static/css/main.css create mode 100644 src/main/resources/static/css/nav.css rename src/main/resources/static/{main.css => css/posts.css} (100%) create mode 100644 src/main/resources/static/css/search.css create mode 100644 src/main/resources/templates/fragments/nav.html create mode 100644 src/main/resources/templates/search/index.html diff --git a/pom.xml b/pom.xml index 7f65cf08e..c292ae12d 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,11 @@ spring-dotenv 3.0.0 + + org.springframework.boot + spring-boot-devtools + true + diff --git a/src/main/java/com/makersacademy/acebook/controller/SearchController.java b/src/main/java/com/makersacademy/acebook/controller/SearchController.java new file mode 100644 index 000000000..60dedc638 --- /dev/null +++ b/src/main/java/com/makersacademy/acebook/controller/SearchController.java @@ -0,0 +1,26 @@ +package com.makersacademy.acebook.controller; + +import com.makersacademy.acebook.model.User; +import com.makersacademy.acebook.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import java.util.List; + +@Controller +public class SearchController { + @Autowired + UserRepository userRepository; + + @GetMapping("/search") + public ModelAndView viewSearchResults(@RequestParam(value = "nav-search", required = false) String query) { + ModelAndView searchView = new ModelAndView("/search/index"); + List allUsers = (List) userRepository.findAll(); + searchView.addObject("users", allUsers); + return searchView; + } +} diff --git a/src/main/resources/static/css/main.css b/src/main/resources/static/css/main.css new file mode 100644 index 000000000..cb16d64ef --- /dev/null +++ b/src/main/resources/static/css/main.css @@ -0,0 +1,43 @@ +body { + margin: 0; + font-family: Roboto; + background-color: var(--light-grey); +} + +a { + text-decoration: none; + color: inherit; +} + +:root { + --acebook-blue: #3A5997; + --light-grey: #F3F4F7; + --default-box-shadow: rgba(0, 0, 0, 0.12) 0px 6px 16px; +} + +.blue_btn { + background-color: var(--acebook-blue); + color: white; + border-radius: 16px; + height: 2rem; + width: 8rem; + display: flex; + justify-content: center; + align-items: center; +} + +.white_btn { + background-color: white; + border: 2px solid var(--acebook-blue); + color: var(--acebook-blue); + border-radius: 16px; + height: 2rem; + width: 8rem; + display: flex; + justify-content: center; + align-items: center; +} + +.clickable:hover { + cursor: pointer; +} \ No newline at end of file diff --git a/src/main/resources/static/css/nav.css b/src/main/resources/static/css/nav.css new file mode 100644 index 000000000..62e22c786 --- /dev/null +++ b/src/main/resources/static/css/nav.css @@ -0,0 +1,53 @@ +nav { + height: 4rem; + background-color: var(--acebook-blue); + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 2rem; +} + +nav ul { + margin: 0; +} + +.navbar_left_container, .navbar_right_container { + display: flex; + justify-content: space-evenly; + gap: 2rem; +} + +.nav_icon_container { + background-color: white; + height: 2.5rem; + width: 2.5rem; + border-radius: 50%; + display: flex; + justify-content: center; + align-items: center; +} + +.nav_logo { + font-size: 3.5rem; + color: var(--acebook-blue); + font-weight: 900; + margin-top: -0.6rem; +} + +.fa-nav { + font-size: 1.5rem; +} + +.nav_icon_search { + background-color: white; + height: 2.5rem; + width: 16rem; + border-radius: 24px; + display: flex; + align-items: center; + padding-left: 1rem; +} + +.nav_icon_search input { + all: unset; +} \ No newline at end of file diff --git a/src/main/resources/static/main.css b/src/main/resources/static/css/posts.css similarity index 100% rename from src/main/resources/static/main.css rename to src/main/resources/static/css/posts.css diff --git a/src/main/resources/static/css/search.css b/src/main/resources/static/css/search.css new file mode 100644 index 000000000..973aea839 --- /dev/null +++ b/src/main/resources/static/css/search.css @@ -0,0 +1,40 @@ +.search_header { + text-align: center; + color: var(--acebook-blue); + font-size: 3rem; + margin-top: 3rem; +} + +.search_results_container { + max-width: 32rem; + margin: 0 auto 4rem auto; + display: flex; + flex-direction: column; + gap: 2rem; +} + +.search_results_container { + list-style: none; +} + +.search_results_card { + background-color: white; + height: 6rem; + border-radius: 16px; + box-shadow: var(--default-box-shadow); + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 2rem; +} + +.search_results_card p { + margin: 0; +} + +.search_mutual { + font-size: 0.8rem; + font-weight: 300; + padding-left: 1rem; + padding-top: 0.5rem; +} \ No newline at end of file diff --git a/src/main/resources/templates/fragments/nav.html b/src/main/resources/templates/fragments/nav.html new file mode 100644 index 000000000..97204c167 --- /dev/null +++ b/src/main/resources/templates/fragments/nav.html @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/posts/index.html b/src/main/resources/templates/posts/index.html index b5ef169f1..af89b5281 100644 --- a/src/main/resources/templates/posts/index.html +++ b/src/main/resources/templates/posts/index.html @@ -4,10 +4,16 @@ Acebook - + + + + + + + - +

Posts

diff --git a/src/main/resources/templates/search/index.html b/src/main/resources/templates/search/index.html new file mode 100644 index 000000000..11652d690 --- /dev/null +++ b/src/main/resources/templates/search/index.html @@ -0,0 +1,34 @@ + + + + + Acebook + + + + + + + + + +
+

Search Results

+ +
+
+
+

+ +

3 mutual friends

+
+ + + +
+
+ + + + From d4c5b8fdf5965ae30f486e3bf6bbf87020a03a68 Mon Sep 17 00:00:00 2001 From: Valeria Date: Wed, 27 Nov 2024 14:30:08 +0000 Subject: [PATCH 16/22] add version 5 migration --- .../V5__change_foreign_keys_type.sql | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/resources/db/migration/V5__change_foreign_keys_type.sql b/src/main/resources/db/migration/V5__change_foreign_keys_type.sql index e69de29bb..e9d419f12 100644 --- a/src/main/resources/db/migration/V5__change_foreign_keys_type.sql +++ b/src/main/resources/db/migration/V5__change_foreign_keys_type.sql @@ -0,0 +1,44 @@ +--UPDATE EXISTING POSTS TABLE +ALTER TABLE posts +ALTER COLUMN user_id TYPE BIGINT; + +--UPDATE POST_LIKES TABLE +ALTER TABLE post_likes +ALTER COLUMN user_id TYPE BIGINT; +ALTER COLUMN post_id TYPE BIGINT; + +--UPDATE COMMENTS TABLE +ALTER TABLE comments +ALTER COLUMN post_id TYPE BIGINT; +ALTER COLUMN commenter_id TYPE BIGINT; + +--UPDATE COMMENT_LIKES TABLE +ALTER TABLE comments_likes +ALTER COLUMN user_id TYPE BIGINT; +ALTER COLUMN comment_id TYPE BIGINT; + +--UPDATE CHATS TABLE +ALTER TABLE chats +ALTER COLUMN user_1_id TYPE BIGINT; +ALTER COLUMN user_2_id TYPE BIGINT; + +--UPDATE MESSAGES TABLE +ALTER TABLE messages +ALTER COLUMN sender_id TYPE BIGINT; +ALTER COLUMN chat_id TYPE BIGINT; + +--UPDATE FRIENDSHIPS TABLE +ALTER TABLE friendships +ALTER COLUMN sender_id TYPE BIGINT; +ALTER COLUMN receiver_id TYPE BIGINT; + +--UPDATE NOTIFICATIONS TABLE +ALTER TABLE notifications +ALTER COLUMN sender_id TYPE BIGINT; +ALTER COLUMN receiver_id TYPE BIGINT; +ALTER COLUMN post_id TYPE BIGINT; +ALTER COLUMN comment_id TYPE BIGINT; +ALTER COLUMN friendship_id TYPE BIGINT; +ALTER COLUMN chat_id TYPE BIGINT; + + From 9015498fd1663411ac01e734f61eff9561c17a5a Mon Sep 17 00:00:00 2001 From: Valeria Date: Wed, 27 Nov 2024 14:37:54 +0000 Subject: [PATCH 17/22] typo --- .../resources/db/migration/V5__change_foreign_keys_type.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/db/migration/V5__change_foreign_keys_type.sql b/src/main/resources/db/migration/V5__change_foreign_keys_type.sql index e9d419f12..5d75a0392 100644 --- a/src/main/resources/db/migration/V5__change_foreign_keys_type.sql +++ b/src/main/resources/db/migration/V5__change_foreign_keys_type.sql @@ -40,5 +40,3 @@ ALTER COLUMN post_id TYPE BIGINT; ALTER COLUMN comment_id TYPE BIGINT; ALTER COLUMN friendship_id TYPE BIGINT; ALTER COLUMN chat_id TYPE BIGINT; - - From 243ed7f2ef5dc8e97f57eef2462549693969ca78 Mon Sep 17 00:00:00 2001 From: Valeria Date: Wed, 27 Nov 2024 15:08:53 +0000 Subject: [PATCH 18/22] typos fixed --- src/main/resources/db/migration/V6__fix_typos_commas.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/db/migration/V6__fix_typos_commas.sql diff --git a/src/main/resources/db/migration/V6__fix_typos_commas.sql b/src/main/resources/db/migration/V6__fix_typos_commas.sql new file mode 100644 index 000000000..e69de29bb From 4d8bd63cd45c35cce9d33151a3f6d599a115e89c Mon Sep 17 00:00:00 2001 From: Valeria Date: Wed, 27 Nov 2024 15:12:20 +0000 Subject: [PATCH 19/22] typos fixed --- .../V5__change_foreign_keys_type.sql | 24 +++++------ .../db/migration/V6__fix_typos_commas.sql | 42 +++++++++++++++++++ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/main/resources/db/migration/V5__change_foreign_keys_type.sql b/src/main/resources/db/migration/V5__change_foreign_keys_type.sql index 5d75a0392..bb65d88d7 100644 --- a/src/main/resources/db/migration/V5__change_foreign_keys_type.sql +++ b/src/main/resources/db/migration/V5__change_foreign_keys_type.sql @@ -4,39 +4,39 @@ ALTER COLUMN user_id TYPE BIGINT; --UPDATE POST_LIKES TABLE ALTER TABLE post_likes -ALTER COLUMN user_id TYPE BIGINT; +ALTER COLUMN user_id TYPE BIGINT, ALTER COLUMN post_id TYPE BIGINT; --UPDATE COMMENTS TABLE ALTER TABLE comments -ALTER COLUMN post_id TYPE BIGINT; +ALTER COLUMN post_id TYPE BIGINT, ALTER COLUMN commenter_id TYPE BIGINT; --UPDATE COMMENT_LIKES TABLE -ALTER TABLE comments_likes -ALTER COLUMN user_id TYPE BIGINT; +ALTER TABLE comment_likes +ALTER COLUMN user_id TYPE BIGINT, ALTER COLUMN comment_id TYPE BIGINT; --UPDATE CHATS TABLE ALTER TABLE chats -ALTER COLUMN user_1_id TYPE BIGINT; +ALTER COLUMN user_1_id TYPE BIGINT, ALTER COLUMN user_2_id TYPE BIGINT; --UPDATE MESSAGES TABLE ALTER TABLE messages -ALTER COLUMN sender_id TYPE BIGINT; +ALTER COLUMN sender_id TYPE BIGINT, ALTER COLUMN chat_id TYPE BIGINT; --UPDATE FRIENDSHIPS TABLE ALTER TABLE friendships -ALTER COLUMN sender_id TYPE BIGINT; +ALTER COLUMN sender_id TYPE BIGINT, ALTER COLUMN receiver_id TYPE BIGINT; --UPDATE NOTIFICATIONS TABLE ALTER TABLE notifications -ALTER COLUMN sender_id TYPE BIGINT; -ALTER COLUMN receiver_id TYPE BIGINT; -ALTER COLUMN post_id TYPE BIGINT; -ALTER COLUMN comment_id TYPE BIGINT; -ALTER COLUMN friendship_id TYPE BIGINT; +ALTER COLUMN sender_id TYPE BIGINT, +ALTER COLUMN receiver_id TYPE BIGINT, +ALTER COLUMN post_id TYPE BIGINT, +ALTER COLUMN comment_id TYPE BIGINT, +ALTER COLUMN friendship_id TYPE BIGINT, ALTER COLUMN chat_id TYPE BIGINT; diff --git a/src/main/resources/db/migration/V6__fix_typos_commas.sql b/src/main/resources/db/migration/V6__fix_typos_commas.sql index e69de29bb..bb65d88d7 100644 --- a/src/main/resources/db/migration/V6__fix_typos_commas.sql +++ b/src/main/resources/db/migration/V6__fix_typos_commas.sql @@ -0,0 +1,42 @@ +--UPDATE EXISTING POSTS TABLE +ALTER TABLE posts +ALTER COLUMN user_id TYPE BIGINT; + +--UPDATE POST_LIKES TABLE +ALTER TABLE post_likes +ALTER COLUMN user_id TYPE BIGINT, +ALTER COLUMN post_id TYPE BIGINT; + +--UPDATE COMMENTS TABLE +ALTER TABLE comments +ALTER COLUMN post_id TYPE BIGINT, +ALTER COLUMN commenter_id TYPE BIGINT; + +--UPDATE COMMENT_LIKES TABLE +ALTER TABLE comment_likes +ALTER COLUMN user_id TYPE BIGINT, +ALTER COLUMN comment_id TYPE BIGINT; + +--UPDATE CHATS TABLE +ALTER TABLE chats +ALTER COLUMN user_1_id TYPE BIGINT, +ALTER COLUMN user_2_id TYPE BIGINT; + +--UPDATE MESSAGES TABLE +ALTER TABLE messages +ALTER COLUMN sender_id TYPE BIGINT, +ALTER COLUMN chat_id TYPE BIGINT; + +--UPDATE FRIENDSHIPS TABLE +ALTER TABLE friendships +ALTER COLUMN sender_id TYPE BIGINT, +ALTER COLUMN receiver_id TYPE BIGINT; + +--UPDATE NOTIFICATIONS TABLE +ALTER TABLE notifications +ALTER COLUMN sender_id TYPE BIGINT, +ALTER COLUMN receiver_id TYPE BIGINT, +ALTER COLUMN post_id TYPE BIGINT, +ALTER COLUMN comment_id TYPE BIGINT, +ALTER COLUMN friendship_id TYPE BIGINT, +ALTER COLUMN chat_id TYPE BIGINT; From 9f1aa7b6d343ffa03ebe6ab7b80c187e0cf379db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Wed, 27 Nov 2024 15:20:31 +0000 Subject: [PATCH 20/22] Add drop table --- src/main/resources/db/seeds/R__dev_seed.sql | 313 ------------------ .../resources/db/seeds/R__new_dev_seed.sql | 9 + 2 files changed, 9 insertions(+), 313 deletions(-) delete mode 100644 src/main/resources/db/seeds/R__dev_seed.sql diff --git a/src/main/resources/db/seeds/R__dev_seed.sql b/src/main/resources/db/seeds/R__dev_seed.sql deleted file mode 100644 index a5178afad..000000000 --- a/src/main/resources/db/seeds/R__dev_seed.sql +++ /dev/null @@ -1,313 +0,0 @@ ---COMMAND TO RUN: psql -d acebook_springboot_development -f src/main/resources/db/seeds/R__dev_seed.sql ---WILL NEED USERS WITH IDS 1-5 (columns: id, username, enabled, my_status, profile_photo_url, bio, first_name, last_name) - ---DROP TABLES -DROP TABLE IF EXISTS notifications CASCADE; -DROP TABLE IF EXISTS post_likes CASCADE; -DROP TABLE IF EXISTS posts CASCADE; -DROP TABLE IF EXISTS comment_likes CASCADE; -DROP TABLE IF EXISTS comments CASCADE; -DROP TABLE IF EXISTS messages CASCADE; -DROP TABLE IF EXISTS chats CASCADE; -DROP TABLE IF EXISTS friendships CASCADE; - ---CREATE POSTS TABLE -CREATE TABLE posts ( - id bigserial PRIMARY KEY, - content varchar(250) NOT NULL, - photo_url TEXT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - user_id INT, - CONSTRAINT fk_posts_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE -); - ---CREATE POST_LIKES TABLE -CREATE TABLE post_likes ( - id bigserial PRIMARY KEY, - user_id INT, - post_id INT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_postlikes_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_postlikes_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE -); - ---CREATE COMMENTS TABLE -CREATE TABLE comments ( - id bigserial PRIMARY KEY, - post_id INT, - content TEXT, - commenter_id INT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_comments_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, - CONSTRAINT fk_comments_commenter FOREIGN KEY (commenter_id) REFERENCES users(id) ON DELETE CASCADE -); - ---CREATE COMMENT_LIKES TABLE -CREATE TABLE comment_likes ( - id bigserial PRIMARY KEY, - user_id INT, - comment_id INT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_commentlikes_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_commentlikes_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE -); - ---CREATE CHATS TABLE -CREATE TABLE chats ( - id bigserial PRIMARY KEY, - user_1_id INT, - user_2_id INT, - CONSTRAINT fk_chats_user_1 FOREIGN KEY (user_1_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_chats_user_2 FOREIGN KEY (user_2_id) REFERENCES users(id) ON DELETE CASCADE -); - ---CREATE MESSAGES TABLE -CREATE TABLE messages ( - id bigserial PRIMARY KEY, - sender_id INT, - chat_id INT, - message TEXT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_messages_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_messages_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE -); - ---CREATE FRIENDSHIPS TABLE -CREATE TABLE friendships ( - id bigserial PRIMARY KEY, - sender_id INT, - receiver_id INT, - status VARCHAR(20) DEFAULT 'pending', - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_friendships_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_friendships_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE -); - ---CREATE NOTIFICATIONS TABLE -CREATE TABLE notifications ( - id bigserial PRIMARY KEY, - sender_id INT, - receiver_id INT, - type VARCHAR(50), - content VARCHAR(255), - is_read BOOLEAN DEFAULT FALSE, - post_id INT NULL, - comment_id INT NULL, - friendship_id INT NULL, - chat_id INT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT fk_notifications_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_notifications_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, - CONSTRAINT fk_notifications_post FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, - CONSTRAINT fk_notifications_comment FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE, - CONSTRAINT fk_notifications_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, - CONSTRAINT fk_notifications_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE -); - ---INSERT POSTS SEEDS -INSERT INTO posts (content, photo_url, user_id, created_at) VALUES -('Sunday brunch 🥑🍞', 'https://plus.unsplash.com/premium_photo-1673581430690-0b42ab287ae9?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-11-25 08:00:00'), -('Anyone else obsessed with the new season of Stranger Things? Can’t stop watching! 📺🍿', NULL, 2, '2024-11-01 09:00:00'), -('Had the best weekend hike! Nature really does wonders for the soul. 🌲🌄', 'https://images.unsplash.com/photo-1501554728187-ce583db33af7?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 3, '2024-11-01 10:00:00'), -('First day at my new job today! Excited for this new chapter. ✨ #NewBeginnings', NULL, 1, '2024-11-02 08:00:00'), -('Halloween activities #Boo', 'https://plus.unsplash.com/premium_photo-1714618933590-febf07fce40c?q=80&w=2660&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-10-31 18:00:00'), -('Starting the weekend right 💪 #FitnessGoals #Crossfit', 'https://images.unsplash.com/photo-1623874514711-0f321325f318?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 2, '2024-11-22 09:30:00'), -('Caught a sunset that looked like it was straight out of a painting tonight. 🌅', 'https://plus.unsplash.com/premium_photo-1673002094195-f18084be89ce?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 3, '2024-11-02 10:45:00'), -('He just knocked over my coffee. Good job he''s cute. 🐱☕️', 'https://images.unsplash.com/photo-1513360371669-4adf3dd7dff8?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 4, '2024-11-02 12:00:00'), -('Tried a new recipe today: vegan meatballs! It was surprisingly delicious. 🍝 #CookingAdventures', 'https://images.unsplash.com/photo-1515516969-d4008cc6241a?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-11-24 19:00:00'), -('Weekend plans: Netflix and pizza, obviously. 🍕🍿 #LazySaturday', NULL, 2, '2024-10-28 16:00:00'); - ---INSERT POST_LIKES SEEDS -INSERT INTO post_likes (user_id, post_id, created_at) VALUES -(5, 1, '2024-11-25 08:05:23'), -(2, 1, '2024-11-25 09:12:47'), -(3, 1, '2024-11-25 10:25:10'), -(4, 1, '2024-11-26 14:15:00'), -(1, 2, '2024-11-01 10:30:00'), -(3, 2, '2024-11-01 15:40:23'), -(5, 2, '2024-11-02 11:10:50'), -(2, 3, '2024-11-02 12:45:00'), -(4, 3, '2024-11-03 16:30:23'), -(2, 5, '2024-11-02 08:25:30'), -(1, 6, '2024-11-22 09:50:00'), -(5, 6, '2024-11-22 10:35:45'), -(3, 6, '2024-11-22 11:20:30'), -(4, 6, '2024-11-22 13:55:40'), -(4, 7, '2024-11-02 12:05:12'), -(1, 8, '2024-10-29 15:25:33'), -(5, 8, '2024-10-30 10:40:20'), -(2, 9, '2024-11-24 20:05:02'), -(1, 10, '2024-11-02 12:10:00'), -(3, 10, '2024-11-02 12:30:15'), -(4, 10, '2024-11-02 13:00:45'); - ---INSERT COMMENT SEEDS -INSERT INTO comments (post_id, content, commenter_id, created_at) VALUES -(1, 'Looks delicious! 🍽️', 2, '2024-11-25 08:10:00'), -(1, 'I love brunch! Can I join next time? 😅', 3, '2024-11-25 09:20:30'), -(2, 'I’m obsessed too! Just finished the new season. 😱', 1, '2024-11-01 10:10:00'), -(3, 'Sounds like an amazing hike! Where did you go?', 4, '2024-11-01 14:25:50'), -(3, 'I need to get outdoors more! 🥾', 1, '2024-11-03 08:00:00'), -(4, 'Congratulations! Wishing you all the best! 🎉', 2, '2024-11-02 08:15:00'), -(4, 'Exciting! What’s your new role? ✨', 5, '2024-11-02 09:00:00'), -(4, 'Good luck on your new journey! 👏', 3, '2024-11-02 10:30:30'), -(5, 'Love the Halloween spirit! 🎃👻', 2, '2024-11-01 18:15:00'), -(5, 'Halloween is my favorite time of year! 🎃', 1, '2024-11-02 09:00:00'), -(6, 'I need to start working out like you! 🤩', 5, '2024-11-22 11:10:20'), -(6, 'I love your motivation! 💯', 4, '2024-11-22 13:20:45'), -(7, 'That’s a breathtaking view! 🌅', 5, '2024-11-02 11:00:00'), -(8, 'Cats are the best troublemakers! 😹', 3, '2024-11-02 12:10:00'), -(8, 'Haha, my cat does the same thing. So cute though! 🐱', 5, '2024-11-02 12:25:30'), -(9, 'I need to try this recipe! Vegan meatballs sound amazing!', 3, '2024-11-24 20:10:00'), -(9, 'This looks so good! Can you share the recipe? 😍', 5, '2024-11-24 20:30:30'); - ---INSERT COMMENT LIKES -INSERT INTO comment_likes (user_id, comment_id, created_at) VALUES -(1, 1, '2024-11-25 08:15:00'), -(3, 1, '2024-11-25 08:25:00'), -(4, 2, '2024-11-25 09:30:00'), -(1, 2, '2024-11-25 09:40:00'), -(5, 3, '2024-11-25 10:00:00'), -(2, 5, '2024-11-01 14:15:00'), -(5, 5, '2024-11-01 15:00:00'), -(1, 6, '2024-11-01 14:40:00'), -(1, 7, '2024-11-01 15:00:00'), -(1, 8, '2024-11-02 11:00:00'), -(1, 9, '2024-11-02 09:15:00'), -(4, 9, '2024-11-02 09:30:00'), -(1, 10, '2024-11-22 11:15:00'), -(2, 10, '2024-11-22 12:00:00'), -(1, 11, '2024-11-02 11:10:00'), -(4, 12, '2024-11-02 12:30:00'), -(3, 13, '2024-11-02 12:30:00'), -(4, 13, '2024-11-02 12:35:00'), -(4, 14, '2024-11-24 20:40:00'), -(4, 15, '2024-11-24 20:45:00'); - ---INSERT CHATS -INSERT INTO chats (user_1_id, user_2_id) VALUES -(1, 2), -(1, 3), -(4, 5); - ---INSERT MESSAGES -INSERT INTO messages (sender_id, chat_id, message, created_at) VALUES -(1, 1, 'Hey, how are you?', '2024-11-15 09:00:00'), -(2, 1, 'I''m good! How about you?', '2024-11-15 09:05:00'), -(1, 1, 'Doing well! Just got back from a trip.', '2024-11-15 09:15:00'), -(2, 1, 'That sounds awesome! Tell me more.', '2024-11-15 09:20:00'), - -(1, 2, 'Hey, just wanted to check in.', '2024-11-10 08:00:00'), -(3, 2, 'Everything is great here! How are you?', '2024-11-10 08:10:00'), -(1, 2, 'Can''t complain. Work is a bit hectic though.', '2024-11-10 08:15:00'), -(3, 2, 'Same here! But we''ll get through it.', '2024-11-10 08:30:00'), - -(4, 3, 'Hey, thanks for adding me! It was great meeting you last night.', '2024-11-26 14:30:00'), -(5, 3, 'No problem! It was so fun meeting you too. How''s everything going?', '2024-11-26 14:35:00'); - ---INSERT FRIENDSHIP SEEDS ---only pending, confirmed or blocked -INSERT INTO friendships (sender_id, receiver_id, status, created_at) VALUES -(1, 2, 'confirmed', '2024-09-15 10:00:00'), -(1, 3, 'confirmed', '2024-09-20 14:30:00'), -(1, 4, 'blocked', '2024-09-25 09:00:00'), -(1, 5, 'confirmed', '2024-09-28 16:45:00'), -(2, 3, 'confirmed', '2024-10-05 11:00:00'), -(2, 4, 'confirmed', '2024-10-06 13:10:00'), -(3, 5, 'pending', '2024-10-07 14:25:00'), -(4, 5, 'confirmed', '2024-10-09 09:45:00'); - ---INSERT NOTIFICATION SEEDS --- Notifications for Post Likes -INSERT INTO notifications (sender_id, receiver_id, type, content, post_id, created_at, is_read) VALUES -(5, 1, 'like', 'Jess liked your post', 1, '2024-11-25 08:05:23', TRUE), -(2, 1, 'like', 'Tobi liked your post', 1, '2024-11-25 09:12:47', TRUE), -(3, 1, 'like', 'Shaeera liked your post', 1, '2024-11-25 10:25:10', TRUE), -(4, 1, 'like', 'Alessandro liked your post', 1, '2024-11-26 14:15:00', FALSE), -(1, 2, 'like', 'Valeria liked your post', 2, '2024-11-01 10:30:00', TRUE), -(3, 2, 'like', 'Shaeera liked your post', 2, '2024-11-01 15:40:23', TRUE), -(5, 2, 'like', 'Jess liked your post', 2, '2024-11-02 11:10:50', TRUE), -(2, 3, 'like', 'Tobi liked your post', 3, '2024-11-02 12:45:00', TRUE), -(4, 3, 'like', 'Alessandro liked your post', 3, '2024-11-03 16:30:23', TRUE), -(2, 1, 'like', 'Tobi liked your post', 5, '2024-11-02 08:25:30', TRUE), -(1, 2, 'like', 'Valeria liked your post', 6, '2024-11-22 09:50:00', TRUE), -(5, 2, 'like', 'Jess liked your post', 6, '2024-11-22 10:35:45', TRUE), -(3, 2, 'like', 'Shaeera liked your post', 6, '2024-11-22 11:20:30', TRUE), -(4, 2, 'like', 'Alessandro liked your post', 6, '2024-11-22 13:55:40', TRUE), -(4, 3, 'like', 'Alessandro liked your post', 7, '2024-11-02 12:05:12', TRUE), -(1, 4, 'like', 'Valeria liked your post', 8, '2024-10-29 15:25:33', TRUE), -(5, 4, 'like', 'Jess liked your post', 8, '2024-10-30 10:40:20', TRUE), -(2, 1, 'like', 'Tobi liked your post', 9, '2024-11-24 20:05:02', TRUE), -(1, 2, 'like', 'Valeria liked your post', 10, '2024-11-02 12:10:00', TRUE), -(3, 2, 'like', 'Shaeera liked your post', 10, '2024-11-02 12:30:15', TRUE), -(4, 2, 'like', 'Alessandro liked your post', 10, '2024-11-02 13:00:45', TRUE); - --- Notifications for Comments -INSERT INTO notifications (sender_id, receiver_id, type, content, post_id, created_at, is_read) VALUES -(2, 1, 'comment', 'Tobi commented on your post', 1, '2024-11-25 08:10:00', TRUE), -(3, 1, 'comment', 'Shaeera commented on your post', 1, '2024-11-25 09:20:30', TRUE), -(1, 2, 'comment', 'Valeria commented on your post', 2, '2024-11-01 10:10:00', TRUE), -(4, 3, 'comment', 'Alessandro commented on your post', 3, '2024-11-01 14:25:50', TRUE), -(1, 3, 'comment', 'Valeria commented on your post', 3, '2024-11-03 08:00:00', TRUE), -(2, 1, 'comment', 'Tobi commented on your post', 4, '2024-11-02 08:15:00', TRUE), -(5, 1, 'comment', 'Jess commented on your post', 4, '2024-11-02 09:00:00', TRUE), -(3, 1, 'comment', 'Shaeera commented on your post', 4, '2024-11-02 10:30:30', TRUE), -(2, 1, 'comment', 'Tobi commented on your post', 5, '2024-11-01 18:15:00', TRUE), -(1, 1, 'comment', 'Valeria commented on your post', 5, '2024-11-02 09:00:00', TRUE), -(5, 2, 'comment', 'Jess commented on your post', 6, '2024-11-22 11:10:20', TRUE), -(4, 2, 'comment', 'Alessandro commented on your post', 6, '2024-11-22 13:20:45', TRUE), -(5, 3, 'comment', 'Jess commented on your post', 7, '2024-11-02 11:00:00', TRUE), -(3, 4, 'comment', 'Shaeera commented on your post', 8, '2024-11-02 12:10:00', TRUE), -(5, 4, 'comment', 'Jess commented on your post', 8, '2024-11-02 12:25:30', TRUE), -(3, 1, 'comment', 'Shaeera commented on your post', 9, '2024-11-24 20:10:00', TRUE), -(5, 1, 'comment', 'Jess commented on your post', 9, '2024-11-24 20:30:30', TRUE); - --- Notifications for Comment Likes -INSERT INTO notifications (sender_id, receiver_id, type, content, comment_id, created_at, is_read) VALUES -(1, 2, 'like', 'Valeria liked your comment', 1, '2024-11-25 08:15:00', TRUE), -(3, 2, 'like', 'Shaeera liked your comment', 1, '2024-11-25 08:25:00', TRUE), -(4, 3, 'like', 'Alessandro liked your comment', 2, '2024-11-25 09:30:00', TRUE), -(1, 3, 'like', 'Valeria liked your comment', 2, '2024-11-25 09:40:00', TRUE), -(5, 1, 'like', 'Jess liked your comment', 3, '2024-11-25 10:00:00', TRUE), -(2, 1, 'like', 'Tobi liked your comment', 5, '2024-11-01 14:15:00', TRUE), -(5, 1, 'like', 'Jess liked your comment', 5, '2024-11-01 15:00:00', TRUE), -(1, 2, 'like', 'Valeria liked your comment', 6, '2024-11-01 14:40:00', TRUE), -(1, 5, 'like', 'Valeria liked your comment', 7, '2024-11-01 15:00:00', TRUE), -(1, 3, 'like', 'Valeria liked your comment', 8, '2024-11-02 11:00:00', TRUE), -(1, 2, 'like', 'Valeria liked your comment', 9, '2024-11-02 09:15:00', TRUE), -(4, 2, 'like', 'Alessandro liked your comment', 9, '2024-11-02 09:30:00', TRUE), -(1, 1, 'like', 'Valeria liked your comment', 10, '2024-11-22 11:15:00', TRUE), -(2, 1, 'like', 'Valeria liked your comment', 10, '2024-11-22 12:00:00', TRUE), -(1, 5, 'like', 'Valeria liked your comment', 11, '2024-11-02 11:10:00', TRUE), -(4, 4, 'like', 'Alessandro liked your comment', 12, '2024-11-02 12:30:00', TRUE), -(3, 5, 'like', 'Shaeera liked your comment', 13, '2024-11-02 12:30:00', TRUE), -(4, 5, 'like', 'Alessandro liked your comment', 13, '2024-11-02 12:35:00', TRUE), -(4, 3, 'like', 'Alessandro liked your comment', 14, '2024-11-24 20:40:00', TRUE), -(4, 5, 'like', 'Alessandro liked your comment', 15, '2024-11-24 20:45:00', TRUE); - --- Notifications for Friend Requests -INSERT INTO notifications (sender_id, receiver_id, type, content, friendship_id, created_at, is_read) VALUES -(1, 2, 'friend_request', 'Valeria sent you a friend request', 1, '2024-09-15 10:00:00', TRUE), -(1, 3, 'friend_request', 'Valeria sent you a friend request', 2, '2024-09-20 14:30:00', TRUE), -(1, 4, 'friend_request', 'Valeria sent you a friend request', 3, '2024-09-28 16:45:00', TRUE), -(1, 5, 'friend_request', 'Valeria sent you a friend request', 4, '2024-10-05 11:00:00', TRUE), -(2, 3, 'friend_request', 'Tobi sent you a friend request', 5, '2024-10-06 13:10:00', TRUE), -(2, 4, 'friend_request', 'Tobi sent you a friend request', 6, '2024-10-07 14:25:00', TRUE), -(3, 5, 'friend_request', 'Shaeera sent you a friend request', 7, '2024-10-07 14:25:00', TRUE), -(4, 5, 'friend_request', 'Alessandro sent you a friend request', 8, '2024-10-09 09:45:00', TRUE); - --- Notifications for Messages -INSERT INTO notifications (sender_id, receiver_id, type, content, chat_id, created_at, is_read) VALUES -(1, 2, 'message', 'Valeria sent you a message: "Hey, how are you?"', 1, '2024-11-15 09:00:00', TRUE), -(2, 1, 'message', 'Tobi sent you a message: "I''m good! How about you?"', 1, '2024-11-15 09:05:00', TRUE), -(1, 2, 'message', 'Valeria sent you a message: "Doing well! Just got back from a trip."', 1, '2024-11-15 09:15:00', TRUE), -(2, 1, 'message', 'Tobi sent you a message: "That sounds awesome! Tell me more."', 1, '2024-11-15 09:20:00', TRUE), - -(1, 3, 'message', 'Valeria sent you a message: "Hey, just wanted to check in."', 2, '2024-11-10 08:00:00', TRUE), -(3, 1, 'message', 'Shaeera sent you a message: "Everything is great here! How are you?"', 2, '2024-11-10 08:10:00', TRUE), -(1, 3, 'message', 'Valeria sent you a message: "Can''t complain. Work is a bit hectic though."', 2, '2024-11-10 08:15:00', TRUE), -(3, 1, 'message', 'Shaeera sent you a message: "Same here! But we''ll get through it."', 2, '2024-11-10 08:30:00', TRUE), - -(4, 5, 'message', 'Alessandro sent you a message: "Hey, thanks for adding me! It was great meeting you last night."', 3, '2024-11-26 14:30:00', TRUE), -(5, 4, 'message', 'Jess sent you a message: "No problem! It was so fun meeting you too. How''s everything going?"', 3, '2024-11-26 14:35:00', FALSE); - diff --git a/src/main/resources/db/seeds/R__new_dev_seed.sql b/src/main/resources/db/seeds/R__new_dev_seed.sql index 4f9b6d317..dd9781a8f 100644 --- a/src/main/resources/db/seeds/R__new_dev_seed.sql +++ b/src/main/resources/db/seeds/R__new_dev_seed.sql @@ -1,3 +1,12 @@ +DROP TABLE IF EXISTS notifications CASCADE; +DROP TABLE IF EXISTS post_likes CASCADE; +DROP TABLE IF EXISTS posts CASCADE; +DROP TABLE IF EXISTS comment_likes CASCADE; +DROP TABLE IF EXISTS comments CASCADE; +DROP TABLE IF EXISTS messages CASCADE; +DROP TABLE IF EXISTS chats CASCADE; +DROP TABLE IF EXISTS friendships CASCADE; + --CREATE POSTS TABLE CREATE TABLE posts ( id bigserial PRIMARY KEY, From 752d19f017ccaf49fce300bca64191b294c937c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Wed, 27 Nov 2024 15:30:39 +0000 Subject: [PATCH 21/22] Add seeding instructions to readme file --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ed629b73e..532f8f448 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ Below, you'll find specific learning objectives for each tool. ## Running the tests - Install chromedriver using `brew install chromedriver` +- In the terminal, at the same level of the project run: `psql -U username -d acebook_springboot_development` + - And after: `\i src/main/resources/db/seeds/R__new_dev_seed.sql` - Start the server in a terminal session `mvn spring-boot:run` - Open a new terminal session and navigate to the Acebook directory - Run your tests in the second terminal session with `mvn test` From 14ec05d7d080a2f8c8116185f759aa548d6d2718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Calexagodzilla=E2=80=9D?= <“alexagozzino@gmail.com”> Date: Wed, 27 Nov 2024 15:49:41 +0000 Subject: [PATCH 22/22] I reintroduces the actual seeding (Sorry) --- .../resources/db/seeds/R__new_dev_seed.sql | 215 +++++++++++++++++- 1 file changed, 211 insertions(+), 4 deletions(-) diff --git a/src/main/resources/db/seeds/R__new_dev_seed.sql b/src/main/resources/db/seeds/R__new_dev_seed.sql index dd9781a8f..0956d9f8c 100644 --- a/src/main/resources/db/seeds/R__new_dev_seed.sql +++ b/src/main/resources/db/seeds/R__new_dev_seed.sql @@ -87,10 +87,10 @@ CREATE TABLE notifications ( type VARCHAR(50), content VARCHAR(255), is_read BOOLEAN DEFAULT FALSE, - post_id bigint, -- Change from INT to BIGINT - comment_id bigint, -- Change from INT to BIGINT - friendship_id bigint, -- Change from INT to BIGINT - chat_id bigint, -- Change from INT to BIGINT + post_id bigint null, -- Change from INT to BIGINT + comment_id bigint null, -- Change from INT to BIGINT + friendship_id bigint null, -- Change from INT to BIGINT + chat_id bigint null, -- Change from INT to BIGINT created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CONSTRAINT fk_notifications_sender FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE, CONSTRAINT fk_notifications_receiver FOREIGN KEY (receiver_id) REFERENCES users(id) ON DELETE CASCADE, @@ -99,3 +99,210 @@ CREATE TABLE notifications ( CONSTRAINT fk_notifications_friendship FOREIGN KEY (friendship_id) REFERENCES friendships(id) ON DELETE CASCADE, CONSTRAINT fk_notifications_chat FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE ); + +--INSERT POSTS SEEDS +INSERT INTO posts (content, photo_url, user_id, created_at) VALUES +('Sunday brunch 🥑🍞', 'https://plus.unsplash.com/premium_photo-1673581430690-0b42ab287ae9?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-11-25 08:00:00'), +('Anyone else obsessed with the new season of Stranger Things? Can’t stop watching! 📺🍿', NULL, 2, '2024-11-01 09:00:00'), +('Had the best weekend hike! Nature really does wonders for the soul. 🌲🌄', 'https://images.unsplash.com/photo-1501554728187-ce583db33af7?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 3, '2024-11-01 10:00:00'), +('First day at my new job today! Excited for this new chapter. ✨ #NewBeginnings', NULL, 1, '2024-11-02 08:00:00'), +('Halloween activities #Boo', 'https://plus.unsplash.com/premium_photo-1714618933590-febf07fce40c?q=80&w=2660&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-10-31 18:00:00'), +('Starting the weekend right 💪 #FitnessGoals #Crossfit', 'https://images.unsplash.com/photo-1623874514711-0f321325f318?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 2, '2024-11-22 09:30:00'), +('Caught a sunset that looked like it was straight out of a painting tonight. 🌅', 'https://plus.unsplash.com/premium_photo-1673002094195-f18084be89ce?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 3, '2024-11-02 10:45:00'), +('He just knocked over my coffee. Good job he''s cute. 🐱☕️', 'https://images.unsplash.com/photo-1513360371669-4adf3dd7dff8?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 4, '2024-11-02 12:00:00'), +('Tried a new recipe today: vegan meatballs! It was surprisingly delicious. 🍝 #CookingAdventures', 'https://images.unsplash.com/photo-1515516969-d4008cc6241a?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', 1, '2024-11-24 19:00:00'), +('Weekend plans: Netflix and pizza, obviously. 🍕🍿 #LazySaturday', NULL, 2, '2024-10-28 16:00:00'); + +--INSERT POST_LIKES SEEDS +INSERT INTO post_likes (user_id, post_id, created_at) VALUES +(5, 1, '2024-11-25 08:05:23'), +(2, 1, '2024-11-25 09:12:47'), +(3, 1, '2024-11-25 10:25:10'), +(4, 1, '2024-11-26 14:15:00'), +(1, 2, '2024-11-01 10:30:00'), +(3, 2, '2024-11-01 15:40:23'), +(5, 2, '2024-11-02 11:10:50'), +(2, 3, '2024-11-02 12:45:00'), +(4, 3, '2024-11-03 16:30:23'), +(2, 5, '2024-11-02 08:25:30'), +(1, 6, '2024-11-22 09:50:00'), +(5, 6, '2024-11-22 10:35:45'), +(3, 6, '2024-11-22 11:20:30'), +(4, 6, '2024-11-22 13:55:40'), +(4, 7, '2024-11-02 12:05:12'), +(1, 8, '2024-10-29 15:25:33'), +(5, 8, '2024-10-30 10:40:20'), +(2, 9, '2024-11-24 20:05:02'), +(1, 10, '2024-11-02 12:10:00'), +(3, 10, '2024-11-02 12:30:15'), +(4, 10, '2024-11-02 13:00:45'); + +--INSERT COMMENT SEEDS +INSERT INTO comments (post_id, content, commenter_id, created_at) VALUES +(1, 'Looks delicious! 🍽️', 2, '2024-11-25 08:10:00'), +(1, 'I love brunch! Can I join next time? 😅', 3, '2024-11-25 09:20:30'), +(2, 'I’m obsessed too! Just finished the new season. 😱', 1, '2024-11-01 10:10:00'), +(3, 'Sounds like an amazing hike! Where did you go?', 4, '2024-11-01 14:25:50'), +(3, 'I need to get outdoors more! 🥾', 1, '2024-11-03 08:00:00'), +(4, 'Congratulations! Wishing you all the best! 🎉', 2, '2024-11-02 08:15:00'), +(4, 'Exciting! What’s your new role? ✨', 5, '2024-11-02 09:00:00'), +(4, 'Good luck on your new journey! 👏', 3, '2024-11-02 10:30:30'), +(5, 'Love the Halloween spirit! 🎃👻', 2, '2024-11-01 18:15:00'), +(5, 'Halloween is my favorite time of year! 🎃', 1, '2024-11-02 09:00:00'), +(6, 'I need to start working out like you! 🤩', 5, '2024-11-22 11:10:20'), +(6, 'I love your motivation! 💯', 4, '2024-11-22 13:20:45'), +(7, 'That’s a breathtaking view! 🌅', 5, '2024-11-02 11:00:00'), +(8, 'Cats are the best troublemakers! 😹', 3, '2024-11-02 12:10:00'), +(8, 'Haha, my cat does the same thing. So cute though! 🐱', 5, '2024-11-02 12:25:30'), +(9, 'I need to try this recipe! Vegan meatballs sound amazing!', 3, '2024-11-24 20:10:00'), +(9, 'This looks so good! Can you share the recipe? 😍', 5, '2024-11-24 20:30:30'); + +--INSERT COMMENT LIKES +INSERT INTO comment_likes (user_id, comment_id, created_at) VALUES +(1, 1, '2024-11-25 08:15:00'), +(3, 1, '2024-11-25 08:25:00'), +(4, 2, '2024-11-25 09:30:00'), +(1, 2, '2024-11-25 09:40:00'), +(5, 3, '2024-11-25 10:00:00'), +(2, 5, '2024-11-01 14:15:00'), +(5, 5, '2024-11-01 15:00:00'), +(1, 6, '2024-11-01 14:40:00'), +(1, 7, '2024-11-01 15:00:00'), +(1, 8, '2024-11-02 11:00:00'), +(1, 9, '2024-11-02 09:15:00'), +(4, 9, '2024-11-02 09:30:00'), +(1, 10, '2024-11-22 11:15:00'), +(2, 10, '2024-11-22 12:00:00'), +(1, 11, '2024-11-02 11:10:00'), +(4, 12, '2024-11-02 12:30:00'), +(3, 13, '2024-11-02 12:30:00'), +(4, 13, '2024-11-02 12:35:00'), +(4, 14, '2024-11-24 20:40:00'), +(4, 15, '2024-11-24 20:45:00'); + +--INSERT CHATS +INSERT INTO chats (user_1_id, user_2_id) VALUES +(1, 2), +(1, 3), +(4, 5); + +--INSERT MESSAGES +INSERT INTO messages (sender_id, chat_id, message, created_at) VALUES +(1, 1, 'Hey, how are you?', '2024-11-15 09:00:00'), +(2, 1, 'I''m good! How about you?', '2024-11-15 09:05:00'), +(1, 1, 'Doing well! Just got back from a trip.', '2024-11-15 09:15:00'), +(2, 1, 'That sounds awesome! Tell me more.', '2024-11-15 09:20:00'), + +(1, 2, 'Hey, just wanted to check in.', '2024-11-10 08:00:00'), +(3, 2, 'Everything is great here! How are you?', '2024-11-10 08:10:00'), +(1, 2, 'Can''t complain. Work is a bit hectic though.', '2024-11-10 08:15:00'), +(3, 2, 'Same here! But we''ll get through it.', '2024-11-10 08:30:00'), + +(4, 3, 'Hey, thanks for adding me! It was great meeting you last night.', '2024-11-26 14:30:00'), +(5, 3, 'No problem! It was so fun meeting you too. How''s everything going?', '2024-11-26 14:35:00'); + +--INSERT FRIENDSHIP SEEDS +--only pending, confirmed or blocked +INSERT INTO friendships (sender_id, receiver_id, status, created_at) VALUES +(1, 2, 'confirmed', '2024-09-15 10:00:00'), +(1, 3, 'confirmed', '2024-09-20 14:30:00'), +(1, 4, 'blocked', '2024-09-25 09:00:00'), +(1, 5, 'confirmed', '2024-09-28 16:45:00'), +(2, 3, 'confirmed', '2024-10-05 11:00:00'), +(2, 4, 'confirmed', '2024-10-06 13:10:00'), +(3, 5, 'pending', '2024-10-07 14:25:00'), +(4, 5, 'confirmed', '2024-10-09 09:45:00'); + +--INSERT NOTIFICATION SEEDS +-- Notifications for Post Likes +INSERT INTO notifications (sender_id, receiver_id, type, content, post_id, created_at, is_read) VALUES +(5, 1, 'like', 'Jess liked your post', 1, '2024-11-25 08:05:23', TRUE), +(2, 1, 'like', 'Tobi liked your post', 1, '2024-11-25 09:12:47', TRUE), +(3, 1, 'like', 'Shaeera liked your post', 1, '2024-11-25 10:25:10', TRUE), +(4, 1, 'like', 'Alessandro liked your post', 1, '2024-11-26 14:15:00', FALSE), +(1, 2, 'like', 'Valeria liked your post', 2, '2024-11-01 10:30:00', TRUE), +(3, 2, 'like', 'Shaeera liked your post', 2, '2024-11-01 15:40:23', TRUE), +(5, 2, 'like', 'Jess liked your post', 2, '2024-11-02 11:10:50', TRUE), +(2, 3, 'like', 'Tobi liked your post', 3, '2024-11-02 12:45:00', TRUE), +(4, 3, 'like', 'Alessandro liked your post', 3, '2024-11-03 16:30:23', TRUE), +(2, 1, 'like', 'Tobi liked your post', 5, '2024-11-02 08:25:30', TRUE), +(1, 2, 'like', 'Valeria liked your post', 6, '2024-11-22 09:50:00', TRUE), +(5, 2, 'like', 'Jess liked your post', 6, '2024-11-22 10:35:45', TRUE), +(3, 2, 'like', 'Shaeera liked your post', 6, '2024-11-22 11:20:30', TRUE), +(4, 2, 'like', 'Alessandro liked your post', 6, '2024-11-22 13:55:40', TRUE), +(4, 3, 'like', 'Alessandro liked your post', 7, '2024-11-02 12:05:12', TRUE), +(1, 4, 'like', 'Valeria liked your post', 8, '2024-10-29 15:25:33', TRUE), +(5, 4, 'like', 'Jess liked your post', 8, '2024-10-30 10:40:20', TRUE), +(2, 1, 'like', 'Tobi liked your post', 9, '2024-11-24 20:05:02', TRUE), +(1, 2, 'like', 'Valeria liked your post', 10, '2024-11-02 12:10:00', TRUE), +(3, 2, 'like', 'Shaeera liked your post', 10, '2024-11-02 12:30:15', TRUE), +(4, 2, 'like', 'Alessandro liked your post', 10, '2024-11-02 13:00:45', TRUE); + +-- Notifications for Comments +INSERT INTO notifications (sender_id, receiver_id, type, content, post_id, created_at, is_read) VALUES +(2, 1, 'comment', 'Tobi commented on your post', 1, '2024-11-25 08:10:00', TRUE), +(3, 1, 'comment', 'Shaeera commented on your post', 1, '2024-11-25 09:20:30', TRUE), +(1, 2, 'comment', 'Valeria commented on your post', 2, '2024-11-01 10:10:00', TRUE), +(4, 3, 'comment', 'Alessandro commented on your post', 3, '2024-11-01 14:25:50', TRUE), +(1, 3, 'comment', 'Valeria commented on your post', 3, '2024-11-03 08:00:00', TRUE), +(2, 1, 'comment', 'Tobi commented on your post', 4, '2024-11-02 08:15:00', TRUE), +(5, 1, 'comment', 'Jess commented on your post', 4, '2024-11-02 09:00:00', TRUE), +(3, 1, 'comment', 'Shaeera commented on your post', 4, '2024-11-02 10:30:30', TRUE), +(2, 1, 'comment', 'Tobi commented on your post', 5, '2024-11-01 18:15:00', TRUE), +(1, 1, 'comment', 'Valeria commented on your post', 5, '2024-11-02 09:00:00', TRUE), +(5, 2, 'comment', 'Jess commented on your post', 6, '2024-11-22 11:10:20', TRUE), +(4, 2, 'comment', 'Alessandro commented on your post', 6, '2024-11-22 13:20:45', TRUE), +(5, 3, 'comment', 'Jess commented on your post', 7, '2024-11-02 11:00:00', TRUE), +(3, 4, 'comment', 'Shaeera commented on your post', 8, '2024-11-02 12:10:00', TRUE), +(5, 4, 'comment', 'Jess commented on your post', 8, '2024-11-02 12:25:30', TRUE), +(3, 1, 'comment', 'Shaeera commented on your post', 9, '2024-11-24 20:10:00', TRUE), +(5, 1, 'comment', 'Jess commented on your post', 9, '2024-11-24 20:30:30', TRUE); + +-- Notifications for Comment Likes +INSERT INTO notifications (sender_id, receiver_id, type, content, comment_id, created_at, is_read) VALUES +(1, 2, 'like', 'Valeria liked your comment', 1, '2024-11-25 08:15:00', TRUE), +(3, 2, 'like', 'Shaeera liked your comment', 1, '2024-11-25 08:25:00', TRUE), +(4, 3, 'like', 'Alessandro liked your comment', 2, '2024-11-25 09:30:00', TRUE), +(1, 3, 'like', 'Valeria liked your comment', 2, '2024-11-25 09:40:00', TRUE), +(5, 1, 'like', 'Jess liked your comment', 3, '2024-11-25 10:00:00', TRUE), +(2, 1, 'like', 'Tobi liked your comment', 5, '2024-11-01 14:15:00', TRUE), +(5, 1, 'like', 'Jess liked your comment', 5, '2024-11-01 15:00:00', TRUE), +(1, 2, 'like', 'Valeria liked your comment', 6, '2024-11-01 14:40:00', TRUE), +(1, 5, 'like', 'Valeria liked your comment', 7, '2024-11-01 15:00:00', TRUE), +(1, 3, 'like', 'Valeria liked your comment', 8, '2024-11-02 11:00:00', TRUE), +(1, 2, 'like', 'Valeria liked your comment', 9, '2024-11-02 09:15:00', TRUE), +(4, 2, 'like', 'Alessandro liked your comment', 9, '2024-11-02 09:30:00', TRUE), +(1, 1, 'like', 'Valeria liked your comment', 10, '2024-11-22 11:15:00', TRUE), +(2, 1, 'like', 'Valeria liked your comment', 10, '2024-11-22 12:00:00', TRUE), +(1, 5, 'like', 'Valeria liked your comment', 11, '2024-11-02 11:10:00', TRUE), +(4, 4, 'like', 'Alessandro liked your comment', 12, '2024-11-02 12:30:00', TRUE), +(3, 5, 'like', 'Shaeera liked your comment', 13, '2024-11-02 12:30:00', TRUE), +(4, 5, 'like', 'Alessandro liked your comment', 13, '2024-11-02 12:35:00', TRUE), +(4, 3, 'like', 'Alessandro liked your comment', 14, '2024-11-24 20:40:00', TRUE), +(4, 5, 'like', 'Alessandro liked your comment', 15, '2024-11-24 20:45:00', TRUE); + +-- Notifications for Friend Requests +INSERT INTO notifications (sender_id, receiver_id, type, content, friendship_id, created_at, is_read) VALUES +(1, 2, 'friend_request', 'Valeria sent you a friend request', 1, '2024-09-15 10:00:00', TRUE), +(1, 3, 'friend_request', 'Valeria sent you a friend request', 2, '2024-09-20 14:30:00', TRUE), +(1, 4, 'friend_request', 'Valeria sent you a friend request', 3, '2024-09-28 16:45:00', TRUE), +(1, 5, 'friend_request', 'Valeria sent you a friend request', 4, '2024-10-05 11:00:00', TRUE), +(2, 3, 'friend_request', 'Tobi sent you a friend request', 5, '2024-10-06 13:10:00', TRUE), +(2, 4, 'friend_request', 'Tobi sent you a friend request', 6, '2024-10-07 14:25:00', TRUE), +(3, 5, 'friend_request', 'Shaeera sent you a friend request', 7, '2024-10-07 14:25:00', TRUE), +(4, 5, 'friend_request', 'Alessandro sent you a friend request', 8, '2024-10-09 09:45:00', TRUE); + +-- Notifications for Messages +INSERT INTO notifications (sender_id, receiver_id, type, content, chat_id, created_at, is_read) VALUES +(1, 2, 'message', 'Valeria sent you a message: "Hey, how are you?"', 1, '2024-11-15 09:00:00', TRUE), +(2, 1, 'message', 'Tobi sent you a message: "I''m good! How about you?"', 1, '2024-11-15 09:05:00', TRUE), +(1, 2, 'message', 'Valeria sent you a message: "Doing well! Just got back from a trip."', 1, '2024-11-15 09:15:00', TRUE), +(2, 1, 'message', 'Tobi sent you a message: "That sounds awesome! Tell me more."', 1, '2024-11-15 09:20:00', TRUE), + +(1, 3, 'message', 'Valeria sent you a message: "Hey, just wanted to check in."', 2, '2024-11-10 08:00:00', TRUE), +(3, 1, 'message', 'Shaeera sent you a message: "Everything is great here! How are you?"', 2, '2024-11-10 08:10:00', TRUE), +(1, 3, 'message', 'Valeria sent you a message: "Can''t complain. Work is a bit hectic though."', 2, '2024-11-10 08:15:00', TRUE), +(3, 1, 'message', 'Shaeera sent you a message: "Same here! But we''ll get through it."', 2, '2024-11-10 08:30:00', TRUE), + +(4, 5, 'message', 'Alessandro sent you a message: "Hey, thanks for adding me! It was great meeting you last night."', 3, '2024-11-26 14:30:00', TRUE), +(5, 4, 'message', 'Jess sent you a message: "No problem! It was so fun meeting you too. How''s everything going?"', 3, '2024-11-26 14:35:00', FALSE); \ No newline at end of file