From aeb866cc1bde7bdc191e34f5e186af647b183bb4 Mon Sep 17 00:00:00 2001 From: JongKyeong Kim Date: Wed, 29 Nov 2023 23:28:22 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EA=B0=80=EC=A0=81=EC=9D=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/project/Glog/repository/PostRepository.java | 3 ++- .../project/Glog/security/oauth2/CustomOAuth2UserService.java | 3 +-- .../src/main/java/com/project/Glog/service/BlogService.java | 2 +- .../src/main/java/com/project/Glog/service/PostService.java | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/com/project/Glog/repository/PostRepository.java b/server/src/main/java/com/project/Glog/repository/PostRepository.java index 401cc6de..b35ace7e 100644 --- a/server/src/main/java/com/project/Glog/repository/PostRepository.java +++ b/server/src/main/java/com/project/Glog/repository/PostRepository.java @@ -4,6 +4,7 @@ import com.project.Glog.domain.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -26,7 +27,7 @@ public interface PostRepository extends JpaRepository { @Query("SELECT p FROM Post p ORDER BY p.likesCount DESC") List findAllByOrderByLikesDesc(); - Page findAll(Pageable pageable); + Page findByisPrivate(boolean isPrivate, Pageable pageable); @Query(value = "SELECT * FROM post ORDER BY RAND() LIMIT 8", nativeQuery = true) List findPostsByRandom(); diff --git a/server/src/main/java/com/project/Glog/security/oauth2/CustomOAuth2UserService.java b/server/src/main/java/com/project/Glog/security/oauth2/CustomOAuth2UserService.java index 3b51e453..1d2dfd9c 100644 --- a/server/src/main/java/com/project/Glog/security/oauth2/CustomOAuth2UserService.java +++ b/server/src/main/java/com/project/Glog/security/oauth2/CustomOAuth2UserService.java @@ -75,7 +75,7 @@ private User registerNewUser(OAuth2UserRequest oAuth2UserRequest, OAuth2UserInfo user.setProviderId(oAuth2UserInfo.getId()); user.setNickname(oAuth2UserInfo.getName()); user.setEmail(oAuth2UserInfo.getEmail()); - user.setImageUrl(oAuth2UserInfo.getImageUrl()); + user.setImageUrl("https://elasticbeanstalk-us-east-1-064991853848.s3.amazonaws.com/profile/defaultImages.jpg"); if (registrationId.equalsIgnoreCase(AuthProvider.github.toString())) { user.setGithubID(oAuth2UserInfo.getName()); @@ -90,7 +90,6 @@ private User updateExistingUser(User existingUser, OAuth2UserInfo oAuth2UserInfo String registrationId = oAuth2UserRequest.getClientRegistration().getRegistrationId(); existingUser.setNickname(oAuth2UserInfo.getName()); - existingUser.setImageUrl(oAuth2UserInfo.getImageUrl()); if (registrationId.equalsIgnoreCase(AuthProvider.github.toString())) { existingUser.setGithubID(oAuth2UserInfo.getName()); existingUser.setGithubToken(token); diff --git a/server/src/main/java/com/project/Glog/service/BlogService.java b/server/src/main/java/com/project/Glog/service/BlogService.java index c1c65eb8..e358a04c 100644 --- a/server/src/main/java/com/project/Glog/service/BlogService.java +++ b/server/src/main/java/com/project/Glog/service/BlogService.java @@ -38,7 +38,7 @@ public String registerBlog(UserPrincipal userPrincipal, UserCreateRequest userCr blog.setBlogName(userCreateRequest.getBlogName()); blog.setBlogUrl(userCreateRequest.getBlogUrl()); user.setNickname(userCreateRequest.getNickname()); - user.setImageUrl("https://elasticbeanstalk-us-east-1-064991853848.s3.amazonaws.com/profile/defaultImages.jpg"); +// user.setImageUrl("https://elasticbeanstalk-us-east-1-064991853848.s3.amazonaws.com/profile/defaultImages.jpg"); Guestbook guestBook = new Guestbook(); guestBook.setBlog(blog); diff --git a/server/src/main/java/com/project/Glog/service/PostService.java b/server/src/main/java/com/project/Glog/service/PostService.java index 72854050..35133cd6 100644 --- a/server/src/main/java/com/project/Glog/service/PostService.java +++ b/server/src/main/java/com/project/Glog/service/PostService.java @@ -222,6 +222,7 @@ public PostPreviewResponse getCollect(int page) { public PostPreviewDtos getPreviews(String kind, int page) { if (!kind.equals("randoms")) { PageRequest pageRequest = null; + if (kind.equals("recent")) { pageRequest = PageRequest.of(page, 8, Sort.by("id").descending()); } else if (kind.equals("likes")) { @@ -229,7 +230,8 @@ public PostPreviewDtos getPreviews(String kind, int page) { } else if (kind.equals("views")) { pageRequest = PageRequest.of(page, 8, Sort.by("viewsCount").descending()); } - Page postsByPagination = postRepository.findAll(pageRequest); + + Page postsByPagination = postRepository.findByisPrivate(false,pageRequest); return new PostPreviewDtos(postsByPagination.getContent(), postsByPagination.getTotalPages()); } else if (kind.equals("randoms")) { List posts = postRepository.findPostsByRandom();