From e04b602ecbd7de1420bcd3e92e5f4ca349824bd7 Mon Sep 17 00:00:00 2001 From: CDBchan Date: Fri, 22 Sep 2023 14:28:02 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20=EC=83=81=ED=92=88=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=EC=A1=B0=ED=9A=8C=EC=8B=9C=20memberId=20null(?= =?UTF-8?q?=EB=B9=84=ED=9A=8C=EC=9B=90)=20=EC=9D=B8=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codesquad/secondhand/common/filter/CommonFilter.java | 3 ++- .../codesquad/secondhand/common/util/RequestParser.java | 8 +++++++- .../secondhand/domain/product/service/ProductService.java | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/secondhand/src/main/java/com/codesquad/secondhand/common/filter/CommonFilter.java b/secondhand/src/main/java/com/codesquad/secondhand/common/filter/CommonFilter.java index a59c4b37f..32abf0f81 100644 --- a/secondhand/src/main/java/com/codesquad/secondhand/common/filter/CommonFilter.java +++ b/secondhand/src/main/java/com/codesquad/secondhand/common/filter/CommonFilter.java @@ -39,7 +39,8 @@ public abstract class CommonFilter extends OncePerRequestFilter { new WhiteListUri("^/connect/[0-9]*$", Set.of("GET")), new WhiteListUri("^/oauth2/authorization/[^/]+$", Set.of("GET")), new WhiteListUri("^/login/oauth2/code/.*$", Set.of("GET")), - new WhiteListUri("^/api/regions$", Set.of("GET")) + new WhiteListUri("^/api/regions$", Set.of("GET")), + new WhiteListUri("^/api/products/[0-9]*/stat$", Set.of("GET")) ); protected JwtProvider jwtProvider; diff --git a/secondhand/src/main/java/com/codesquad/secondhand/common/util/RequestParser.java b/secondhand/src/main/java/com/codesquad/secondhand/common/util/RequestParser.java index a465769f5..bd4bd3772 100644 --- a/secondhand/src/main/java/com/codesquad/secondhand/common/util/RequestParser.java +++ b/secondhand/src/main/java/com/codesquad/secondhand/common/util/RequestParser.java @@ -16,7 +16,13 @@ public static String extractAccessToken(HttpServletRequest request) { } public static Long extractMemberId(HttpServletRequest request) { - return Long.valueOf(String.valueOf(request.getAttribute(MEMBER_ID))); + Object attribute = request.getAttribute(MEMBER_ID); + if (attribute == null) { + return null; + } + + String memberId = attribute.toString(); + return Long.valueOf(memberId); } public static String extractEmail(HttpServletRequest request) { diff --git a/secondhand/src/main/java/com/codesquad/secondhand/domain/product/service/ProductService.java b/secondhand/src/main/java/com/codesquad/secondhand/domain/product/service/ProductService.java index 30cee8b13..a1e9afe8d 100644 --- a/secondhand/src/main/java/com/codesquad/secondhand/domain/product/service/ProductService.java +++ b/secondhand/src/main/java/com/codesquad/secondhand/domain/product/service/ProductService.java @@ -131,7 +131,9 @@ public ProductStatResponse findStat(Long productId, Long memberId) { Long viewCount = redisUtil.getViewCount(productId) + product.getViewCount(); Long reactionCount = reactionQueryService.countByProduct(product); Long chattingCount = chatQueryService.countByProduct(product); - Boolean isLiked = reactionQueryService.isLiked(memberId, product); + + // memberId가 null이 아닐 때만 isLiked를 확인 + Boolean isLiked = (memberId != null) ? reactionQueryService.isLiked(memberId, product) : false; return ProductStatResponse.of(viewCount, reactionCount, chattingCount, isLiked); }