Skip to content
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

Up and running. #204

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
324bdf8
added Trelloboard link to README.md file
paulineldb Jun 10, 2024
dfb572a
created header and footer html files + added header and footer to pos…
paulineldb Jun 10, 2024
31d5e83
added username to posts
EthanDunwiddie Jun 11, 2024
da5c50b
Merge pull request #1 from Hakim-Kay/username-to-post
emilyhardy98 Jun 11, 2024
73a71c8
removed bug from user model
EthanDunwiddie Jun 11, 2024
18d0be1
Merge pull request #2 from Hakim-Kay/username-to-post
EthanDunwiddie Jun 11, 2024
389dca1
Added imageurl field to post model and added image_url field to post …
Zach-Deladev Jun 11, 2024
c599ee1
User can add profile picture on signup
EthanDunwiddie Jun 11, 2024
8e30382
Deleted test profile picture folder
EthanDunwiddie Jun 11, 2024
d8dfe6e
CSS files modified. Header and Footer applied to posts/index.html & u…
paulineldb Jun 11, 2024
20bf01d
Created pipeline and setup docker
Hakim-Kay Jun 11, 2024
521b4e6
Merge pull request #3 from Hakim-Kay/deployment-pipeline
Hakim-Kay Jun 11, 2024
bb957b1
Fixes to deployment errors in Dockerfile & yml
Hakim-Kay Jun 11, 2024
9629a27
Fixes to deployment bugs
Hakim-Kay Jun 11, 2024
c552b91
Merge pull request #4 from Hakim-Kay/header-implementation
emilyhardy98 Jun 11, 2024
917f48f
Revert CI/CD setup to allow collaborators to push changes comfortably
Hakim-Kay Jun 11, 2024
7ef6c8f
Set up CI/CD pipeline in deployment-pipeline branch
Hakim-Kay Jun 11, 2024
cc5a583
made changes to the main body of posts to match the style of the header
emilyhardy98 Jun 11, 2024
38b011d
Added chromedriver to the CI env
Hakim-Kay Jun 11, 2024
6144678
Merge pull request #6 from Hakim-Kay/body-css-changes
paulineldb Jun 11, 2024
cd28e53
Added upload button to HTML, added Amazon S3 storage to controller fo…
Zach-Deladev Jun 11, 2024
0ca2c4b
Fixed issue with env variables.
Zach-Deladev Jun 11, 2024
29a3fac
Updated brancg with main and resolved conflicts.
Zach-Deladev Jun 11, 2024
7de494b
Deployment - Deleted old CI/CD.yml file (#8)
Hakim-Kay Jun 11, 2024
b7c3186
Merge pull request #7 from Hakim-Kay/post-with-images
Zach-Deladev Jun 12, 2024
4d35d70
User can add profile picture on signup
EthanDunwiddie Jun 11, 2024
9fc298d
Deleted V4__create_comments_table.sql migration file
emilyhardy98 Jun 12, 2024
c2a1bf0
Deleted test profile picture folder
EthanDunwiddie Jun 11, 2024
0bf6037
Fix 1: Resolve conflicts
Hakim-Kay Jun 12, 2024
cb0cc8d
Add V7__create_comments_table.sql for creating comments table
emilyhardy98 Jun 12, 2024
b9a838c
Resolved Conflicts
Hakim-Kay Jun 12, 2024
30c1508
Merge pull request #5 from Hakim-Kay/deployment-pipeline
Zach-Deladev Jun 12, 2024
c0e1de7
fixed lyway migration
EthanDunwiddie Jun 12, 2024
b264464
"resolved merge conflicts"
EthanDunwiddie Jun 12, 2024
5f2ec47
"resolved things"Merge remote-tracking branch 'origin/main' into prof…
EthanDunwiddie Jun 12, 2024
a8b7954
db updates
EthanDunwiddie Jun 12, 2024
7e506a9
Completed adding profile picture to s3
EthanDunwiddie Jun 12, 2024
63c3add
Merge pull request #10 from Hakim-Kay/profile-picture-on-signup
Zach-Deladev Jun 12, 2024
d4cff3f
added timestamp to be saved to the database when a post is created
paulineldb Jun 13, 2024
943c0a6
Comments working in most simplistic form
emilyhardy98 Jun 13, 2024
6df3acf
added 'Newest post appears first' functionality
paulineldb Jun 13, 2024
907ec8b
Likes working in most simplistic form
emilyhardy98 Jun 13, 2024
f4dded5
Merge pull request #11 from Hakim-Kay/newest-post-appears-first
Zach-Deladev Jun 13, 2024
c767725
Updated db migration
emilyhardy98 Jun 13, 2024
bd6157c
Merge branch 'main' into comments-and-likes
paulineldb Jun 13, 2024
6988bc6
Merge pull request #13 from Hakim-Kay/comments-and-likes
paulineldb Jun 13, 2024
5d4ac15
Added user posts to profile.
Zach-Deladev Jun 13, 2024
b7b1ed9
Added user posts to profile.
Zach-Deladev Jun 13, 2024
674282c
fixed issues with sign up form appearing twice
paulineldb Jun 13, 2024
68e784e
Merge pull request #14 from Hakim-Kay/comments-and-likes
emilyhardy98 Jun 13, 2024
6a289d2
Fixed migration issues.
Zach-Deladev Jun 13, 2024
cd3c7df
Resolved merge conflicts
Zach-Deladev Jun 13, 2024
40215f0
Complete merge
Zach-Deladev Jun 13, 2024
e635c6c
modified 'new post' form styling to be more user-friendly + minor cha…
paulineldb Jun 13, 2024
b90d0b7
Added styling to profile page.
Zach-Deladev Jun 14, 2024
e7ae983
Changes to like button
emilyhardy98 Jun 14, 2024
734af1a
Styled posts section on profile page.
Zach-Deladev Jun 14, 2024
7cef70e
Merge pull request #16 from Hakim-Kay/profile-page
EthanDunwiddie Jun 14, 2024
446eaf3
added login page to app
EthanDunwiddie Jun 14, 2024
c83c6d6
fixed posts
EthanDunwiddie Jun 14, 2024
177d1d5
Tests added for comments and like button
emilyhardy98 Jun 14, 2024
902dd8a
fixed profile posts
EthanDunwiddie Jun 14, 2024
957bfe1
Merge pull request #17 from Hakim-Kay/login-page
Zach-Deladev Jun 14, 2024
d4fa893
modified main.css to make 'posts' page more readable
paulineldb Jun 14, 2024
4d97749
conflicts resolved + minor changes to profile.css & main.css
paulineldb Jun 14, 2024
790f3e0
Merge pull request #20 from Hakim-Kay/body-css-changes
Zach-Deladev Jun 14, 2024
2f209df
like changes
emilyhardy98 Jun 14, 2024
dc92188
added bio logic to profile page
EthanDunwiddie Jun 14, 2024
8811f48
fixed css with comments and likes
emilyhardy98 Jun 14, 2024
52b3f2a
Merge pull request #21 from Hakim-Kay/comments-and-likes
Zach-Deladev Jun 14, 2024
fda4c6c
Changes.
Zach-Deladev Jun 14, 2024
79e5c2b
"Merge with mina."Merge remote-tracking branch 'origin/main' into pro…
Zach-Deladev Jun 14, 2024
5a4207a
message
EthanDunwiddie Jun 14, 2024
857d34e
update css
EthanDunwiddie Jun 14, 2024
9059d29
Merge pull request #22 from Hakim-Kay/add-bio
Zach-Deladev Jun 14, 2024
fe65880
"Merge to main."Merge remote-tracking branch 'origin/main' into profi…
Zach-Deladev Jun 14, 2024
e3dd0ee
Added on error messages to profile pictures.
Zach-Deladev Jun 14, 2024
ed204fb
Configured for render.
Zach-Deladev Jun 14, 2024
94a5392
Fixed variables.
Zach-Deladev Jun 14, 2024
c108857
Still tinkering.
Zach-Deladev Jun 14, 2024
fe1370d
tinkering.
Zach-Deladev Jun 14, 2024
c597fd3
Fix database connection environment variables
Zach-Deladev Jun 14, 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.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Exclude the target directory, which contains the build output
target/

# Exclude git configuration and repository data
.git
.gitignore

# Exclude local configuration files (IDE settings, etc.)
.idea
*.iml
*.log
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ dependency-reduced-pom.xml
.factorypath
.project
.settings/
.env

.DS_STORE
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use Maven to build the JAR file
FROM maven:3.8.1-openjdk-17 AS build
WORKDIR /app
COPY . .
RUN mvn clean package

# Use the JAR file from the build stage
FROM openjdk:17
COPY --from=build /app/target/acebook-template-1.0-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
EXPOSE 8080
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'

services:
database:
image: postgres:latest
environment:
POSTGRES_DB: acebook_springboot_development
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data

app:
build: .
ports:
- "8080:8080"
depends_on:
- database
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://database:5432/acebook_springboot_development
SPRING_DATASOURCE_USERNAME:
SPRING_DATASOURCE_PASSWORD:
SPRING_JPA_HIBERNATE_DDL_AUTO: update
SPRING_JPA_DATABASE_PLATFORM: org.hibernate.dialect.PostgreSQL9Dialect

volumes:
postgres_data:
65 changes: 54 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

Expand All @@ -30,8 +50,8 @@

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>

Expand All @@ -40,14 +60,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version> <!-- Might not be necessary -->
</dependency>

<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
Expand All @@ -56,6 +83,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.20.25</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<version>2.20.25</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
Expand All @@ -67,7 +105,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -99,12 +137,17 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
</project>
30 changes: 30 additions & 0 deletions render.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
- type: web
name: acebook-api
env: docker
plan: free
dockerfilePath: Dockerfile
envVars:
- key: DATABASE_URL
fromService:
name: acebook-db
type: database
property: connectionString
- key: DB_HOST
value: dpg-cpm5nc2ju9rs738kt4ng-a
- key: DB_NAME
value: acebook_springboot_development_fpol
- key: DB_USER
value: acebook_springboot_development_fpol_user
- key: DB_PASS
value: wiXc8BpegUV52sdrqykindpYNTIFiNDH
buildCommand: "./mvnw clean package" # Ensure this matches your build command
startCommand: "java -jar app.jar"

- type: postgresql
name: acebook-db
plan: free
properties:
databaseName: acebook_springboot_development_fpol
user: acebook_springboot_development_fpol_user
password: wiXc8BpegUV52sdrqykindpYNTIFiNDH
20 changes: 16 additions & 4 deletions src/main/java/com/makersacademy/acebook/SecurityConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/posts").hasRole("USER")
.antMatchers("/users").permitAll()
.and().formLogin();
.antMatchers("/posts", "/profile", "/profile/**").hasRole("USER")
.antMatchers("/users", "/profile-pictures/**", "/login", "/users/new", "/css/**", "/js/**", "/images/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/posts", true)
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/login?logout")
.permitAll()
.and()
.csrf();
}

@Bean
public PasswordEncoder getPasswordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/makersacademy/acebook/auth/AuthService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.makersacademy.acebook.auth;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@Service
public class AuthService {

public Boolean isLoggedIn() {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
return !username.equals("anonymousUser");
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/makersacademy/acebook/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.makersacademy.acebook.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

@Configuration
public class S3Config {

@Bean
public S3Client s3Client() {
return S3Client.builder()
.region(Region.US_EAST_1)
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.makersacademy.acebook.controller;

import com.makersacademy.acebook.auth.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/auth")
public class AuthController {

@Autowired
private AuthService authService;

@GetMapping("/userLoggedIn")
public Map<String, Boolean> userLoggedIn() {
Map<String, Boolean> response = new HashMap<>();
response.put("loggedIn", authService.isLoggedIn());
return response;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.makersacademy.acebook.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class LoginController {

@GetMapping("/login")
public String login(){
return "login";
}

}
Original file line number Diff line number Diff line change
@@ -1,32 +1,70 @@
package com.makersacademy.acebook.controller;

import com.makersacademy.acebook.model.Comment;
import com.makersacademy.acebook.model.Post;
import com.makersacademy.acebook.repository.PostRepository;
import com.makersacademy.acebook.model.User;
import com.makersacademy.acebook.repository.UserRepository;
import com.makersacademy.acebook.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.io.IOException;

@Controller
public class PostsController {

@Autowired
PostRepository repository;
private UserRepository userRepository;

@Autowired
private PostService postService;

@GetMapping("/posts")
public String index(Model model) {
Iterable<Post> posts = repository.findAll();
Iterable<Post> posts = postService.getAllPostsFromNewestToOldest();
model.addAttribute("posts", posts);
model.addAttribute("post", new Post());
model.addAttribute("newComment", new Comment());
return "posts/index";
}

@PostMapping("/posts")
public RedirectView create(@ModelAttribute Post post) {
repository.save(post);
return new RedirectView("/posts");
public RedirectView create(Post post, @RequestParam("image") MultipartFile image, @RequestParam(required = false) String redirectUrl, Authentication authentication) {
String username = authentication.getName();
User user = userRepository.findByUsername(username);
post.setUser(user);

try {
postService.savePost(post, image);
} catch (IOException e) {
e.printStackTrace();
return new RedirectView(redirectUrl != null ? redirectUrl + "?error" : "/posts?error");
}

return new RedirectView(redirectUrl != null ? redirectUrl : "/posts");
}
@PostMapping("/posts/{postId}/comments")
public String addComment(@PathVariable Long postId, @RequestParam String content, Authentication authentication) {
String username = authentication.getName();
User user = userRepository.findByUsername(username);
postService.addComment(postId, content, user);
return "redirect:/posts";
}
}

@PostMapping("/posts/{postId}/toggleLike")
public String toggleLikePost(@PathVariable Long postId, Authentication authentication) {
String username = authentication.getName();
User user = userRepository.findByUsername(username);
postService.toggleLike(postId, user);
return "redirect:/posts";
}

}
Loading