From 77c6246079a08fd8a8c324ad96068b3824a376fa Mon Sep 17 00:00:00 2001 From: JongKyeong Kim Date: Thu, 30 Nov 2023 12:37:00 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EC=9D=B5=EB=AA=85=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/Glog/service/ReplyService.java | 18 +++++++++++++++--- server/src/main/resources/data.sql | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/project/Glog/service/ReplyService.java b/server/src/main/java/com/project/Glog/service/ReplyService.java index 30e9f2bf..174041ba 100644 --- a/server/src/main/java/com/project/Glog/service/ReplyService.java +++ b/server/src/main/java/com/project/Glog/service/ReplyService.java @@ -54,17 +54,29 @@ public Long createReply(UserPrincipal userPrincipal, ReplyCreateRequest req) { public ReplyGetResponse getReplies(UserPrincipal userPrincipal, ReplyGetRequest req) { Post post = postRepository.findById(req.getPostId()).get(); - User currentUser = userRepository.findById(userPrincipal.getId()).get(); +// Optional currentUserOptional = userRepository.findById(userPrincipal.getId()); + Boolean imOwner; Long authorId = postRepository.findById(post.getId()).get().getUser().getId(); + User currentUser = null; + + if (userPrincipal == null){ + imOwner = false; + currentUser = userRepository.findUserByNickname("anonymous"); + } + else{ + imOwner = (authorId == userPrincipal.getId()); + currentUser = userRepository.findById(userPrincipal.getId()).get(); + } + + + - Boolean imOwner = (authorId == userPrincipal.getId()); PageRequest pageRequest = PageRequest.of(req.getPage(), 10, Sort.by(req.getOrder()).descending()); List replys = replyRepository.findRepliesByPost(post, pageRequest).getContent(); List replyDtos = new ArrayList<>(); for(Reply reply : replys){ ReplyDto replyDto = ReplyDto.of(reply); - Boolean isLiked = replyLikeRepository.findByReplyAndUser(reply.getId(), currentUser.getId()).isPresent(); replyDto.setIsLiked(isLiked); diff --git a/server/src/main/resources/data.sql b/server/src/main/resources/data.sql index 8eaa4c42..eb53f728 100644 --- a/server/src/main/resources/data.sql +++ b/server/src/main/resources/data.sql @@ -4,7 +4,7 @@ INSERT INTO user (id, email, email_verified, friend_count, image_url, introduction, nickname, provider, provider_id, skin) VALUES (1, 'doyeong32@gmail.com', 0, 0, 'https://lh3.googleusercontent.com/a/ACg8ocL0TM05twyPZ0eQsEWouix_zP5Kmz9z6TqY4Pm8VMyxkg=s96-c', NULL, 'Y eong', 'google', 104384823454308011759, 0), (2, 'yiyop@naver.com', 0, 0, 'https://avatars.githubusercontent.com/u/48638700?v=4', NULL, 'Due_it', 'github', 48638700, 0), - (3, 'oo7bangjk@gmail.com', 0, 0, 'https://lh3.googleusercontent.com/a/ACg8ocISaV9dG1q60VmzjW0_pxYAYYVg8T2-cVmGmxhmdNaRz4k=s96-c' , NULL, 'jk', 'google' ,105693697773599263104, 0), + (3, 'oo7bangjk@gmail.com', 0, 0, 'https://lh3.googleusercontent.com/a/ACg8ocISaV9dG1q60VmzjW0_pxYAYYVg8T2-cVmGmxhmdNaRz4k=s96-c' , NULL, 'anonymous', 'google' ,105693697773599263104, 0), (4, 'oo7bangjk@naver.com', 0, 0, 'https://avatars.githubusercontent.com/u/111286262?v=4' , NULL, 'JONG-KYEONG', 'github' ,111286262, 0); INSERT INTO blog(id, blog_name, blog_url, readme, user_id) From 19ed5e996cfc17455083aedd280b9b53021161db Mon Sep 17 00:00:00 2001 From: JongKyeong Kim Date: Thu, 30 Nov 2023 12:39:17 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main/resources/data.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/resources/data.sql b/server/src/main/resources/data.sql index eb53f728..8eaa4c42 100644 --- a/server/src/main/resources/data.sql +++ b/server/src/main/resources/data.sql @@ -4,7 +4,7 @@ INSERT INTO user (id, email, email_verified, friend_count, image_url, introduction, nickname, provider, provider_id, skin) VALUES (1, 'doyeong32@gmail.com', 0, 0, 'https://lh3.googleusercontent.com/a/ACg8ocL0TM05twyPZ0eQsEWouix_zP5Kmz9z6TqY4Pm8VMyxkg=s96-c', NULL, 'Y eong', 'google', 104384823454308011759, 0), (2, 'yiyop@naver.com', 0, 0, 'https://avatars.githubusercontent.com/u/48638700?v=4', NULL, 'Due_it', 'github', 48638700, 0), - (3, 'oo7bangjk@gmail.com', 0, 0, 'https://lh3.googleusercontent.com/a/ACg8ocISaV9dG1q60VmzjW0_pxYAYYVg8T2-cVmGmxhmdNaRz4k=s96-c' , NULL, 'anonymous', 'google' ,105693697773599263104, 0), + (3, 'oo7bangjk@gmail.com', 0, 0, 'https://lh3.googleusercontent.com/a/ACg8ocISaV9dG1q60VmzjW0_pxYAYYVg8T2-cVmGmxhmdNaRz4k=s96-c' , NULL, 'jk', 'google' ,105693697773599263104, 0), (4, 'oo7bangjk@naver.com', 0, 0, 'https://avatars.githubusercontent.com/u/111286262?v=4' , NULL, 'JONG-KYEONG', 'github' ,111286262, 0); INSERT INTO blog(id, blog_name, blog_url, readme, user_id)