Skip to content

Sashas styling changes #241

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 212 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
96c13d7
Update README.md
sashaparkes Jun 2, 2025
f697244
altered existing tables and created new table migrations
Shanice598 Jun 3, 2025
3834bf4
Merge pull request #1 from sashaparkes/migrations
A-Schmigiel Jun 3, 2025
41456a4
updated user model and tests
sashaparkes Jun 3, 2025
7c3199f
Merge remote-tracking branch 'origin/main' into sign_up
sashaparkes Jun 3, 2025
3ce1025
pull
A-Schmigiel Jun 3, 2025
e56e6d0
update user model again
sashaparkes Jun 3, 2025
5db70b5
yml fix
Shanice598 Jun 3, 2025
781bcac
Merge pull request #3 from sashaparkes/migrations
A-Schmigiel Jun 3, 2025
2250297
Mid workflow
A-Schmigiel Jun 3, 2025
34bbbd7
Mid workflow
A-Schmigiel Jun 3, 2025
daff4b1
Auth0 taking name details etc
sashaparkes Jun 4, 2025
61e71b2
Notifications Model/Controller/Interface/HTML-- working except for th…
A-Schmigiel Jun 4, 2025
b7101f6
basic settings page
sashaparkes Jun 4, 2025
bb6eee9
settings page
sashaparkes Jun 4, 2025
065999b
settings
sashaparkes Jun 4, 2025
0bfd2c6
Merge pull request #4 from sashaparkes/sign_up
A-Schmigiel Jun 4, 2025
ff069be
friends
HarryMcconville Jun 4, 2025
9c0648c
Merge branch 'main' into notifications
sashaparkes Jun 4, 2025
686c28e
Merge pull request #5 from sashaparkes/notifications
sashaparkes Jun 4, 2025
0855208
Merge pull request #6 from sashaparkes/friend_list
sashaparkes Jun 4, 2025
968fb0c
image uploader updates
sashaparkes Jun 4, 2025
a275311
image uploader
sashaparkes Jun 4, 2025
9563f2c
fixed friends template
HarryMcconville Jun 4, 2025
259c2ad
Updated PostController, Posts index.html, and individual post html, a…
A-Schmigiel Jun 4, 2025
9410fad
Notifications now correctly marking as read when clicked.
A-Schmigiel Jun 4, 2025
ab964d3
image uploader updated
sashaparkes Jun 4, 2025
b072ba0
updated friends page
HarryMcconville Jun 4, 2025
c83931e
Merge pull request #9 from sashaparkes/friend_list
Jordan-Gill Jun 4, 2025
8ac358c
Merge pull request #8 from sashaparkes/notifications
Jordan-Gill Jun 4, 2025
8897fef
Merge pull request #10 from sashaparkes/sign_up
HarryMcconville Jun 4, 2025
f2de4ac
Notifications now (actually) correctly marking as read when clicked.
A-Schmigiel Jun 4, 2025
7319078
adding dsstore
Shanice598 Jun 5, 2025
677bb02
users can comment on posts and like comments MVC's only
Shanice598 Jun 5, 2025
753e3b8
adding controller for comments
Shanice598 Jun 5, 2025
cf12eff
corrected errors for commentlike stuff, small change in user.java
Shanice598 Jun 5, 2025
38de3c7
settings page tests
sashaparkes Jun 5, 2025
3efaeb1
Navbar up and running
A-Schmigiel Jun 5, 2025
80b2a40
Navbar, Notifications, and Posts updates
A-Schmigiel Jun 5, 2025
ff5bbb9
Merge pull request #11 from sashaparkes/usercommentonposts
A-Schmigiel Jun 5, 2025
6a97af7
settings.html fix
A-Schmigiel Jun 5, 2025
e8c1d06
settings.html merge fix
A-Schmigiel Jun 5, 2025
93927cf
Merge pull request #13 from sashaparkes/notifications
Jordan-Gill Jun 5, 2025
eddb8b1
Temporary comment fix :(
A-Schmigiel Jun 5, 2025
bc98908
partway through testing settings page
sashaparkes Jun 5, 2025
753e8e7
Merge pull request #14 from sashaparkes/notifications
Jordan-Gill Jun 5, 2025
47a7611
completed feature tests for settings page
sashaparkes Jun 5, 2025
dd4de01
Friend requests can be accepted/rejected
HarryMcconville Jun 5, 2025
edf5d50
creating comment like functionality, and display name for comments
Shanice598 Jun 5, 2025
67191c6
added V12 migration to add friends since...
HarryMcconville Jun 5, 2025
27df91b
First commit
Jordan-Gill Jun 5, 2025
d9f1045
changed v12 to v13
HarryMcconville Jun 5, 2025
88ec736
changed name again whoops
HarryMcconville Jun 5, 2025
797a3e4
Merge pull request #15 from sashaparkes/friend_list
A-Schmigiel Jun 5, 2025
ab30d5b
Merge pull request #17 from sashaparkes/user_details_with_post
A-Schmigiel Jun 5, 2025
ccc6c9f
settings page tests without images
sashaparkes Jun 6, 2025
56d9dbb
Making some edits and adding comments to User class that I needed to …
Shanice598 Jun 6, 2025
29306a6
Html navbarfix
A-Schmigiel Jun 6, 2025
f0e9b24
removed images
sashaparkes Jun 6, 2025
a98b30c
Merge pull request #16 from sashaparkes/testing_user_controller
A-Schmigiel Jun 6, 2025
1dfdf91
ShanniCode merge
A-Schmigiel Jun 6, 2025
42f3ee3
Ordering requests and friends
HarryMcconville Jun 6, 2025
3fde400
Merge branch 'main' into friend_list
HarryMcconville Jun 6, 2025
2556ea7
ShanniCode merge
A-Schmigiel Jun 6, 2025
8feaadf
ShanniCode merge
A-Schmigiel Jun 6, 2025
1506295
added db migration V13
sashaparkes Jun 6, 2025
8e0a4e0
post upload merged with main functionality
sashaparkes Jun 6, 2025
9ab2e0f
deleted images
sashaparkes Jun 6, 2025
4240fe9
Remove friends route added and add friends route added but not tested
HarryMcconville Jun 6, 2025
e19b3f5
Comments/Likes patch completed
A-Schmigiel Jun 6, 2025
51eb61b
Merge pull request #20 from sashaparkes/image_upload_retry
Jordan-Gill Jun 6, 2025
02cc3fd
First commit
Jordan-Gill Jun 6, 2025
3d2e4ae
Merge pull request #21 from sashaparkes/friend_list
Jordan-Gill Jun 6, 2025
9d907f2
links
A-Schmigiel Jun 6, 2025
4d907ad
Comment/like merge patch
A-Schmigiel Jun 6, 2025
7407702
Comment/like merge patch
A-Schmigiel Jun 6, 2025
179098e
Merge pull request #22 from sashaparkes/temp
Jordan-Gill Jun 6, 2025
d3301ec
basic profile page
sashaparkes Jun 6, 2025
3e63ca7
Second commit
Jordan-Gill Jun 6, 2025
81a0937
merging in updates
A-Schmigiel Jun 6, 2025
b4153c2
merging in updates
A-Schmigiel Jun 6, 2025
ec541f3
profile page prep
sashaparkes Jun 6, 2025
c5afe45
added links to posts/users in html for posts and post pages
A-Schmigiel Jun 6, 2025
cfb7559
Third commit
Jordan-Gill Jun 6, 2025
37b212b
Merged main commit
Jordan-Gill Jun 6, 2025
8e09c57
Monday Commit
Jordan-Gill Jun 9, 2025
f0191f2
Merge pull request #23 from sashaparkes/notifications
sashaparkes Jun 9, 2025
a31e649
Merge branch 'main' into basic_html
sashaparkes Jun 9, 2025
0d7a3bb
Merge pull request #24 from sashaparkes/basic_html
sashaparkes Jun 9, 2025
6561c35
profile page initial stuff
sashaparkes Jun 9, 2025
9c343aa
bug fix for image uploading
sashaparkes Jun 9, 2025
f3c53f4
Merge pull request #25 from sashaparkes/profile_image_bug_fix
HarryMcconville Jun 9, 2025
d899604
test files
sashaparkes Jun 9, 2025
0c77e87
Merge pull request #26 from sashaparkes/adding_image_directories
A-Schmigiel Jun 9, 2025
d439f60
remove test files
sashaparkes Jun 9, 2025
2092831
Merge pull request #27 from sashaparkes/adding_image_directories
A-Schmigiel Jun 9, 2025
ef61b4f
files added again
sashaparkes Jun 9, 2025
819848c
Merge pull request #28 from sashaparkes/adding_image_directories
A-Schmigiel Jun 9, 2025
ffd24e8
commit before resuming work
sashaparkes Jun 9, 2025
86d1db0
Creation of comments, comment likes, and post likes now linked to not…
A-Schmigiel Jun 9, 2025
d967f7b
Passing through grammar for different notification types.
A-Schmigiel Jun 9, 2025
125f79f
quite functional profile page
sashaparkes Jun 9, 2025
57c1a2a
Navbar friends and notifications
Jordan-Gill Jun 9, 2025
82e09d0
Navbar friends and notificationss
Jordan-Gill Jun 9, 2025
a9e6249
remove images
sashaparkes Jun 9, 2025
eee793a
Merge pull request #30 from sashaparkes/profile_page
Jordan-Gill Jun 9, 2025
4d0eb8d
Merge branch 'main' into basic_html
sashaparkes Jun 9, 2025
d966044
Merge pull request #29 from sashaparkes/basic_html
sashaparkes Jun 9, 2025
966e12f
adding profile page link to navbar dropdown on additional pages
sashaparkes Jun 9, 2025
c1f236d
attempt to fix merge issues
HarryMcconville Jun 9, 2025
4215264
Merge pull request #32 from sashaparkes/temp
A-Schmigiel Jun 9, 2025
eaad2bc
Friends Notifications and Profile html
Jordan-Gill Jun 9, 2025
2b51d73
Wall 'comment' links to individual post
A-Schmigiel Jun 9, 2025
5d662fa
Merged with main branch.
A-Schmigiel Jun 9, 2025
ca00051
Merged with main branch.
A-Schmigiel Jun 9, 2025
eeab13f
Fixing individual post page images.
A-Schmigiel Jun 9, 2025
2e24f00
bug fix on post index page
sashaparkes Jun 10, 2025
cb35bef
updating profile page links across new HTML
sashaparkes Jun 10, 2025
f01c6cc
updating profile links on other pages
sashaparkes Jun 10, 2025
a354f64
Seed Images
HarryMcconville Jun 10, 2025
7a136b4
Merge pull request #33 from sashaparkes/notifications
Jordan-Gill Jun 10, 2025
421888d
Merge branch 'main' into basic_html
A-Schmigiel Jun 10, 2025
617ddf0
Merge pull request #34 from sashaparkes/basic_html
A-Schmigiel Jun 10, 2025
46bdffb
Merge pull request #36 from sashaparkes/temp
sashaparkes Jun 10, 2025
885c1e0
Notifications icon copied across all html pages
A-Schmigiel Jun 10, 2025
f2291c7
merged my branch with main to solve DS Store issue
sashaparkes Jun 10, 2025
5ae1c51
HTML bug fixing
Jordan-Gill Jun 10, 2025
f028257
adding friend request buttons to profile page
sashaparkes Jun 10, 2025
8fe42c3
Poster names on main wall now link to individual profiles
A-Schmigiel Jun 10, 2025
9bc5b80
Merge pull request #38 from sashaparkes/updating_nav_bar_for_profile_…
Jordan-Gill Jun 10, 2025
aeea52f
Poster names on main wall now link to individual profiles
A-Schmigiel Jun 10, 2025
89f76d2
Merge branch 'main' into basic_html
sashaparkes Jun 10, 2025
b1e64ec
Merge pull request #39 from sashaparkes/basic_html
sashaparkes Jun 10, 2025
679eec0
Poster names on main wall now link to individual profiles
A-Schmigiel Jun 10, 2025
247f403
friend request
HarryMcconville Jun 10, 2025
9658765
Merge branch 'main' into notifications
sashaparkes Jun 10, 2025
68bd1bd
Merge pull request #41 from sashaparkes/notifications
sashaparkes Jun 10, 2025
1da471f
Merge pull request #42 from sashaparkes/add_friend
sashaparkes Jun 10, 2025
d57ce6c
fix for notifications link navbar
A-Schmigiel Jun 10, 2025
ac2d4d3
merged in main
sashaparkes Jun 10, 2025
2cdb2b0
- Fixed missing ; in sql file
A-Schmigiel Jun 10, 2025
c26b82b
- Fixed missing ; in sql file
A-Schmigiel Jun 10, 2025
76bfecf
add friend functionality on profile page
sashaparkes Jun 10, 2025
b31e15b
- User Search Page
A-Schmigiel Jun 10, 2025
e58e728
General HTML updates
Jordan-Gill Jun 10, 2025
020acdf
temporary commit
Jordan-Gill Jun 11, 2025
baef0f4
temporary commit2
Jordan-Gill Jun 11, 2025
1fe39be
merge with main
Jordan-Gill Jun 11, 2025
b17c1d4
navbar update for the search bar (only notifications page for now)
A-Schmigiel Jun 11, 2025
115c502
Index and friends update
Jordan-Gill Jun 11, 2025
a7e33d3
Index and friends updates
Jordan-Gill Jun 11, 2025
cf075af
Merge pull request #43 from sashaparkes/notifications
Shanice598 Jun 11, 2025
125a443
index and friends page update
Jordan-Gill Jun 11, 2025
8d7f8cc
index and friends page updates and dog image
Jordan-Gill Jun 11, 2025
22e7e2f
index and friends page updateeee
Jordan-Gill Jun 11, 2025
a837354
index and friends page updateee
Jordan-Gill Jun 11, 2025
d2bea3e
Merge pull request #46 from sashaparkes/test_merge
Shanice598 Jun 11, 2025
cd4b269
adding titles to profile page
sashaparkes Jun 11, 2025
33d4216
merge with main
sashaparkes Jun 11, 2025
6a98df5
adding profile friends page
sashaparkes Jun 11, 2025
c0925eb
route for other users friends now in place
sashaparkes Jun 11, 2025
ca513dd
- Moved getNotifications to NotificationService
A-Schmigiel Jun 11, 2025
109b529
Added footer
A-Schmigiel Jun 11, 2025
84ff630
Adding footer html fix
A-Schmigiel Jun 11, 2025
770b412
Adding footer html fix
A-Schmigiel Jun 11, 2025
86cdf42
final tweaks to profile page
sashaparkes Jun 11, 2025
66d3421
notifications page update
Jordan-Gill Jun 11, 2025
cffe53e
Merge pull request #48 from sashaparkes/prof_page_more_updates
Jordan-Gill Jun 11, 2025
1a9d560
Merge branch 'main' into notifications
Jordan-Gill Jun 11, 2025
8f12906
Merge pull request #47 from sashaparkes/notifications
Jordan-Gill Jun 11, 2025
69cd5e3
Merge branch 'main' into more_html
HarryMcconville Jun 11, 2025
bf1abc2
Merge pull request #49 from sashaparkes/more_html
HarryMcconville Jun 11, 2025
406182a
NOT FUNCTIONAL mid workflow friends' posts
A-Schmigiel Jun 11, 2025
ed1141d
html merge fix
A-Schmigiel Jun 11, 2025
826af0b
Merge pull request #51 from sashaparkes/notifications-merge
Jordan-Gill Jun 11, 2025
1c4dcdf
index changes, counter parts only
Shanice598 Jun 11, 2025
4faddc2
Merge branch 'notifications' into friends-sort
A-Schmigiel Jun 11, 2025
abda83d
Merge pull request #52 from sashaparkes/newindex
Jordan-Gill Jun 11, 2025
9b7acdb
adding friend count
sashaparkes Jun 11, 2025
8ac4045
added comment/like count for profile page
Shanice598 Jun 11, 2025
dc7f89e
make profile page language conditional
sashaparkes Jun 11, 2025
079e23b
Friends and notifications page bug fixes
Jordan-Gill Jun 11, 2025
6849e11
Friends wall filter
A-Schmigiel Jun 11, 2025
aa1fed6
Friends wall filter
A-Schmigiel Jun 11, 2025
aa7fe19
Merge pull request #53 from sashaparkes/profile_friends_additions
Jordan-Gill Jun 11, 2025
2432ab8
Merge pull request #54 from sashaparkes/profilepagecounters
Jordan-Gill Jun 11, 2025
e761140
Merge branch 'main' into friends-sort
Jordan-Gill Jun 11, 2025
287c5f8
Merge pull request #56 from sashaparkes/friends-sort
Jordan-Gill Jun 11, 2025
81c820c
wall fix
A-Schmigiel Jun 11, 2025
0160984
Merge branch 'main' into more_html
A-Schmigiel Jun 11, 2025
089b807
Merge pull request #55 from sashaparkes/more_html
A-Schmigiel Jun 11, 2025
8b0ab0f
- submitting a post now redirects to the same friends or global wall
A-Schmigiel Jun 11, 2025
552ce50
- submitting a post now redirects to the same friends or global wall
A-Schmigiel Jun 11, 2025
db04789
- submitting a post now redirects to the same friends or global wall
A-Schmigiel Jun 11, 2025
bc3a5d8
Search bar and footer
Jordan-Gill Jun 12, 2025
89984e0
Merge pull request #57 from sashaparkes/friends-sort
sashaparkes Jun 12, 2025
25acc9c
Merge pull request #58 from sashaparkes/more_html
sashaparkes Jun 12, 2025
f96ae20
seeds and further changes
HarryMcconville Jun 12, 2025
107562b
Merge branch 'main' into seeds_and_friends
sashaparkes Jun 12, 2025
fafb2a7
Merge pull request #59 from sashaparkes/seeds_and_friends
sashaparkes Jun 12, 2025
875c913
like comment on post changes
sashaparkes Jun 12, 2025
d567713
merged with main
sashaparkes Jun 12, 2025
692a834
users friends page and friends search page changes
Jordan-Gill Jun 12, 2025
eb2f0f4
styling updates to index page
sashaparkes Jun 12, 2025
9cf1d3f
style updates friends page
sashaparkes Jun 12, 2025
77f6db7
Merge pull request #60 from sashaparkes/sashas_styling_changes
Jordan-Gill Jun 12, 2025
b3da792
Merge pull request #61 from sashaparkes/finishing_touches
sashaparkes Jun 12, 2025
33d2053
styling tweaks notifications page
sashaparkes Jun 12, 2025
7dffa02
updating like format on individual post page
sashaparkes Jun 12, 2025
ab03ae7
individual posts
Jordan-Gill Jun 12, 2025
3728ffc
Merge pull request #62 from sashaparkes/finishing_touches
Jordan-Gill Jun 12, 2025
8edf28a
Merge branch 'main' into sashas_styling_changes
Jordan-Gill Jun 12, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dependency-reduced-pom.xml
.factorypath
.project
.settings/
application.yml
.DS_Store
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Acebook

https://trello.com/b/VidgaAkH/acebook-engineering-project-2

The application uses:
- `maven` to build the project
- `thymeleaf` for templating
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -102,6 +103,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -114,6 +116,7 @@
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/java/.DS_Store
Binary file not shown.
Binary file added src/main/java/com/.DS_Store
Binary file not shown.
Binary file added src/main/java/com/makersacademy/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public SecurityFilterChain configure(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/", "/images/**").permitAll()
.requestMatchers("/",
"/main.css",
"/images/**",
"/favicon.png").permitAll()
.anyRequest().authenticated()
)
.oauth2Login(oauth2 -> oauth2
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/makersacademy/acebook/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.makersacademy.acebook.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// This class customises how the app serves static resources (e.g. images) from the file system
// Resource handlers map URL paths to filesystem directories so static files (e.g. images) can be served via HTTP
// This is required for image storage outside the classpath (src) on uploading

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Handler for profile images
registry.addResourceHandler("/uploads/user_profile/**")
.addResourceLocations("file:uploads/user_profile/");

// Handler for post images
registry.addResourceHandler("/uploads/post_images/**")
.addResourceLocations("file:uploads/post_images/");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.makersacademy.acebook.controller;

import com.makersacademy.acebook.dto.CommentRequest;
import com.makersacademy.acebook.model.Comment;
import com.makersacademy.acebook.model.Post;
import com.makersacademy.acebook.model.User;
import com.makersacademy.acebook.repository.CommentRepository;
import com.makersacademy.acebook.repository.NotificationRepository;
import com.makersacademy.acebook.repository.PostRepository;
import com.makersacademy.acebook.repository.UserRepository;
import com.makersacademy.acebook.service.CommentService;
import com.makersacademy.acebook.service.NotificationService;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

import java.util.List;
import jakarta.transaction.Transactional;


@Controller
@RequestMapping("/posts/comments")
public class CommentController {

private final CommentService commentService;
private final PostRepository postRepository;
private final UserRepository userRepository;
private final NotificationService notificationService;
private final CommentRepository commentRepository;

public CommentController(CommentService commentService, PostRepository postRepository, UserRepository userRepository,NotificationRepository notificationRepository, NotificationService notificationService, CommentRepository commentRepository) {
this.commentService = commentService;
this.postRepository = postRepository;
this.userRepository = userRepository;
this.notificationService = notificationService;
this.commentRepository = commentRepository;
}


// Show comments for specific post
@GetMapping("/post/{postId}")
@ResponseBody
public List<Comment> getCommentsByPost(@PathVariable Long postId) {
return commentService.getCommentsForPost(postId);
}

// This will POST to add a comment and then redirect back to the post with the updated comment for that post
@PostMapping
public RedirectView createComment(@ModelAttribute CommentRequest request,
@AuthenticationPrincipal(expression = "attributes['email']") String email) {
Post post = postRepository.findById(request.getPostId())
.orElseThrow(() -> new RuntimeException("Post not found"));

User user = userRepository.findUserByUsername(email)
.orElseThrow(() -> new RuntimeException("User not found"));

Comment comment = new Comment();
comment.setPost(post);
comment.setUser(user);
comment.setContent(request.getContent());

commentService.addComment(comment);
notificationService.newNotification(user.getId(), "comment", comment, null, null);
return new RedirectView("/posts/" + post.getId());
}


@Transactional
@PostMapping("/{commentId}/delete")
public RedirectView deleteComment(@PathVariable Long commentId,
@RequestParam Long postId,
@AuthenticationPrincipal(expression = "attributes['email']") String email) {

if (userRepository.findUserByUsername(email).get().getId() == commentRepository.findById(commentId).get().getUser().getId()) {
commentService.deleteComment(commentId);
return new RedirectView("/posts/" + postId);
} else {
return new RedirectView("/profile");
}
}
}

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

import com.makersacademy.acebook.service.CommentLikeService;
import jakarta.transaction.Transactional;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

@Controller
@RequestMapping("/posts/comments")
public class CommentLikeController {
private final CommentLikeService commentLikeService;
public CommentLikeController(CommentLikeService commentLikeService) {
this.commentLikeService = commentLikeService;
}

@Transactional
@PostMapping("/{commentId}/like")
public RedirectView likeComment(@PathVariable Long commentId,
@RequestParam Long postId,
@AuthenticationPrincipal(expression = "attributes['email']") String email) {
commentLikeService.likeComment(commentId, email);
return new RedirectView("/posts/" + postId);
}

@Transactional
@PostMapping("/{commentId}/unlike")
public RedirectView unlikeComment(@PathVariable Long commentId,
@RequestParam Long postId,
@AuthenticationPrincipal(expression = "attributes['email']") String email) {
commentLikeService.unlikeComment(commentId, email);
return new RedirectView("/posts/" + postId);
}
}
Loading