Skip to content

Readme seed #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ac5c216
test
Nov 25, 2024
b1e9b58
test2
Nov 25, 2024
d3e89fb
update gitignore
ValeSer Nov 25, 2024
34511a6
Merge pull request #2 from ValeSer/new-gitignore
alexagodzilla Nov 25, 2024
a2abeb1
add credentials in env file and add that file in gitignore
ValeSer Nov 25, 2024
62025c2
Merge pull request #3 from ValeSer/test
jpates2 Nov 25, 2024
9fbebc4
env file update
Nov 25, 2024
65420c6
Merge pull request #4 from ValeSer/env-file-for-yml
alexagodzilla Nov 25, 2024
507a7a7
add part where we hide credentials
ValeSer Nov 26, 2024
bf1d6e4
db tables created
jpates2 Nov 26, 2024
45714e7
update
ValeSer Nov 26, 2024
2ab5579
create db tables
jpates2 Nov 26, 2024
65e97e4
Merge pull request #5 from ValeSer/db-seeds
jpates2 Nov 26, 2024
e9a185e
seed data for db
jpates2 Nov 27, 2024
b1a414d
Merge branch 'main' of https://github.com/ValeSer/acebook-the-bytes i…
ValeSer Nov 27, 2024
1502df6
update with indentation
ValeSer Nov 27, 2024
bc4cd32
Merge pull request #7 from ValeSer/readme_update
alexagodzilla Nov 27, 2024
6c0e331
Merge pull request #6 from ValeSer/db-seed-data
jpates2 Nov 27, 2024
e3710b6
edit seed file
Nov 27, 2024
61e4de4
edit seed file
Nov 27, 2024
1942243
add version 5 migration
ValeSer Nov 27, 2024
e7e107f
navbar and search results
jpates2 Nov 27, 2024
d4c5b8f
add version 5 migration
ValeSer Nov 27, 2024
9015498
typo
ValeSer Nov 27, 2024
f5dc96b
Merge pull request #8 from ValeSer/V5-migration
alexagodzilla Nov 27, 2024
751436f
Merge pull request #10 from ValeSer/fix_seed_file
ValeSer Nov 27, 2024
25c5ddc
Merge pull request #9 from ValeSer/navbar
alexagodzilla Nov 27, 2024
243ed7f
typos fixed
ValeSer Nov 27, 2024
4d8bd63
typos fixed
ValeSer Nov 27, 2024
80aec60
Merge pull request #11 from ValeSer/V6_migration_typos
alexagodzilla Nov 27, 2024
9f1aa7b
Add drop table
Nov 27, 2024
fc74a06
Merge pull request #12 from ValeSer/fix-seed-file
ValeSer Nov 27, 2024
752d19f
Add seeding instructions to readme file
Nov 27, 2024
14ec05d
I reintroduces the actual seeding (Sorry)
Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dependency-reduced-pom.xml
.factorypath
.project
.settings/
.env
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,40 @@ 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=<your-domain> <br>
OKTA_CLIENT_ID=<your-client-ID> <br>
OKTA_CLIENT_SECRET=<your_client_secret>

Make sure the naming matches the one on the file application.yml: <br>
issuer: ${OKTA_ISSUER} <br>
client-id: ${OKTA_CLIENT_ID} <br>
client-secret: ${OKTA_CLIENT_SECRET} <br>
<br>
- update your .gitignore with .env

- add dependencies in pom.xml: <br>
```xml
<dependency>
<groupId>com.okta.spring</groupId>
<artifactId>okta-spring-boot-starter</artifactId>
<version>3.0.7</version>
</dependency>
```
- 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

## 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`
Expand Down
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,23 @@
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<User> allUsers = (List<User>) userRepository.findAll();
searchView.addObject("users", allUsers);
return searchView;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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}
95 changes: 95 additions & 0 deletions src/main/resources/db/migration/V3__create_tables.sql
Original file line number Diff line number Diff line change
@@ -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
);
4 changes: 4 additions & 0 deletions src/main/resources/db/migration/V4__add_names_to_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--UPDATE EXISTING USERS TABLE
ALTER TABLE users
ADD first_name VARCHAR(100),
ADD last_name VARCHAR(100);
42 changes: 42 additions & 0 deletions src/main/resources/db/migration/V5__change_foreign_keys_type.sql
Original file line number Diff line number Diff line change
@@ -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;
42 changes: 42 additions & 0 deletions src/main/resources/db/migration/V6__fix_typos_commas.sql
Original file line number Diff line number Diff line change
@@ -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;
Loading