Skip to content

Commit

Permalink
fix: use current user id instead of 1
Browse files Browse the repository at this point in the history
  • Loading branch information
gutche committed Mar 8, 2023
1 parent ce6de95 commit 07ee91d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package net.daw.alist.controllers;

import net.daw.alist.models.Post;

import net.daw.alist.models.User;
import net.daw.alist.services.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.data.domain.Page;
import org.springframework.security.core.Authentication;

@Controller
public class PostController {
Expand All @@ -32,9 +33,11 @@ public String getNewPosts(Model model, @RequestParam int page) {
}

@GetMapping("/followed-users/posts")
public String getFollowedUsersPosts(Model model, @RequestParam int page) {
public String getFollowedUsersPosts(Model model, Authentication authentication, @RequestParam int page) {

User currentUser = (User) authentication.getPrincipal();

Page<Post> starredPost = postService.getStarredPosts(page, 1);
Page<Post> starredPost = postService.getStarredPosts(page,currentUser.getId().intValue());

model.addAttribute("posts", starredPost);

Expand Down
4 changes: 4 additions & 0 deletions back/src/main/java/net/daw/alist/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,8 @@ public void unFollow(User user) {
}
}

public Long getId() {
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ protected void configure(HttpSecurity http) throws Exception {
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/admin-panel").hasAnyRole("ADMIN")
.antMatchers("/profile").hasAnyRole("USER", "ADMIN")
.antMatchers("/profile").hasAnyRole("USER", "ADMIN")
.antMatchers("/followed-users/").hasAnyRole("USER", "ADMIN")
.antMatchers("/create-list").hasAnyRole("USER", "ADMIN")
.antMatchers("/create").hasAnyRole("USER", "ADMIN")
.antMatchers("/register").permitAll()
Expand Down
1 change: 0 additions & 1 deletion back/src/main/java/net/daw/alist/services/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
Expand Down

0 comments on commit 07ee91d

Please sign in to comment.