From b9d1b74aab3bed821cc2bec78b3dc1f81942fb03 Mon Sep 17 00:00:00 2001 From: hyunseo Date: Thu, 14 Nov 2024 20:03:43 +0900 Subject: [PATCH 1/9] =?UTF-8?q?[refactor]=20=EB=82=98=EC=9D=98=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20fetch=20join=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team7/inplace/review/application/ReviewService.java | 2 +- .../team7/inplace/review/persistence/ReviewRepository.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/team7/inplace/review/application/ReviewService.java b/src/main/java/team7/inplace/review/application/ReviewService.java index 9068b1a0..a50265d2 100644 --- a/src/main/java/team7/inplace/review/application/ReviewService.java +++ b/src/main/java/team7/inplace/review/application/ReviewService.java @@ -81,7 +81,7 @@ public void deleteReview(Long reviewId) { @Transactional(readOnly = true) public Page getMyReviews(Long userId, Pageable pageable) { - Page reviewPage = reviewRepository.findByUserId(userId, pageable); + Page reviewPage = reviewRepository.findByUserIdWithPlace(userId, pageable); return reviewPage.map(MyReviewInfo::from); } diff --git a/src/main/java/team7/inplace/review/persistence/ReviewRepository.java b/src/main/java/team7/inplace/review/persistence/ReviewRepository.java index 3ef4a7cf..aab01c00 100644 --- a/src/main/java/team7/inplace/review/persistence/ReviewRepository.java +++ b/src/main/java/team7/inplace/review/persistence/ReviewRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import team7.inplace.review.domain.Review; public interface ReviewRepository extends JpaRepository { @@ -11,5 +12,6 @@ public interface ReviewRepository extends JpaRepository { Page findByPlaceId(Long placeId, Pageable pageable); - Page findByUserId(Long userId, Pageable pageable); + @Query("SELECT r FROM Review r JOIN FETCH r.place WHERE r.user.id = :userId") + Page findByUserIdWithPlace(Long userId, Pageable pageable); } From a88cc451e418219a26bbd697fb70859144507224 Mon Sep 17 00:00:00 2001 From: suhyeon7497 Date: Thu, 14 Nov 2024 20:07:07 +0900 Subject: [PATCH 2/9] =?UTF-8?q?[fix]=20cors=20=EC=84=A4=EC=A0=953?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/team7/inplace/security/config/CorsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team7/inplace/security/config/CorsConfig.java b/src/main/java/team7/inplace/security/config/CorsConfig.java index 91c296b2..5d4d1a37 100644 --- a/src/main/java/team7/inplace/security/config/CorsConfig.java +++ b/src/main/java/team7/inplace/security/config/CorsConfig.java @@ -15,7 +15,7 @@ public CorsFilter corsFilter() { var source = new UrlBasedCorsConfigurationSource(); var config = new CorsConfiguration(); config.setAllowCredentials(true); - config.addAllowedOrigin("https://www.inplace.my"); + config.addAllowedOriginPattern("https://www.inplace.my"); config.addAllowedOriginPattern("https://api.inplace.my"); config.addAllowedHeader("Origin"); config.addAllowedHeader("Accept"); From d21dfe046e199c663e753d048666b33595aee87f Mon Sep 17 00:00:00 2001 From: dong_yxxn Date: Thu, 14 Nov 2024 20:12:36 +0900 Subject: [PATCH 3/9] =?UTF-8?q?[fix]:=20schema.sql=EC=97=90=20,=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - conflict merge하며 ,빠진 부분을 추가했습니다. --- src/main/resources/sql/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/sql/schema.sql b/src/main/resources/sql/schema.sql index f0b39453..c91e05f2 100644 --- a/src/main/resources/sql/schema.sql +++ b/src/main/resources/sql/schema.sql @@ -22,7 +22,7 @@ create table places latitude text not null, longitude text not null, menu_img_url text null, - category enum ('CAFE', 'JAPANESE', 'KOREAN', 'NONE', 'RESTAURANT', 'WESTERN') not null + category enum ('CAFE', 'JAPANESE', 'KOREAN', 'NONE', 'RESTAURANT', 'WESTERN') not null, FULLTEXT INDEX ft_name_ngram (name) WITH PARSER ngram, INDEX idx_long_lat (longitude(15), latitude(15)) From 0f3fea22e5083efc9320ea712c92025d201969af Mon Sep 17 00:00:00 2001 From: suhyeon7497 Date: Thu, 14 Nov 2024 20:42:31 +0900 Subject: [PATCH 4/9] =?UTF-8?q?[chore]=20log=20=EB=82=A8=EA=B2=A8=EC=84=9C?= =?UTF-8?q?=20cors=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/CustomAccessDeniedHandler.java | 8 +++++--- .../security/handler/CustomFailureHandler.java | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java b/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java index cc7d18a8..1eebcd8b 100644 --- a/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java +++ b/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java @@ -2,12 +2,13 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.web.access.AccessDeniedHandler; -import java.io.IOException; - +@Slf4j public class CustomAccessDeniedHandler implements AccessDeniedHandler { @Value("${spring.redirect.front-end-url}") @@ -15,7 +16,8 @@ public class CustomAccessDeniedHandler implements AccessDeniedHandler { @Override public void handle(HttpServletRequest request, HttpServletResponse response, - AccessDeniedException accessDeniedException) throws IOException { + AccessDeniedException accessDeniedException) throws IOException { + log.info("Access denied"); response.sendRedirect(frontEndUrl); } } diff --git a/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java b/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java index 1ba24dc0..e5deb740 100644 --- a/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java +++ b/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; @@ -13,8 +14,6 @@ import team7.inplace.global.exception.InplaceException; import team7.inplace.global.exception.code.AuthorizationErrorCode; -import java.io.IOException; - @Slf4j public class CustomFailureHandler implements AuthenticationFailureHandler { @@ -28,10 +27,11 @@ public CustomFailureHandler(ObjectMapper objectMapper) { @Override public void onAuthenticationFailure( - HttpServletRequest request, - HttpServletResponse response, - AuthenticationException exception + HttpServletRequest request, + HttpServletResponse response, + AuthenticationException exception ) throws IOException { + log.info("Authentication failure"); String accept = request.getHeader("Accept"); if (StringUtils.hasText(accept) && accept.contains("text/html")) { response.sendRedirect(frontEndUrl); @@ -40,13 +40,13 @@ public void onAuthenticationFailure( } private void setErrorResponse( - HttpServletResponse response, - InplaceException inplaceException + HttpServletResponse response, + InplaceException inplaceException ) throws IOException { response.setStatus(inplaceException.getHttpStatus().value()); response.setContentType(MediaType.APPLICATION_JSON_VALUE); ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail( - inplaceException.getHttpStatus(), inplaceException.getMessage()); + inplaceException.getHttpStatus(), inplaceException.getMessage()); response.getWriter().write(objectMapper.writeValueAsString(problemDetail)); } } From 249cf14c3a2ad6d143307bca12a497791c0295c4 Mon Sep 17 00:00:00 2001 From: hyunseo Date: Thu, 14 Nov 2024 20:55:43 +0900 Subject: [PATCH 5/9] =?UTF-8?q?[refactor]=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=9E=A5=EC=86=8C=20fetch=20join=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/LikedPlaceRepository.java | 9 +- .../place/application/PlaceService.java | 157 +++++++++--------- .../video/persistence/VideoRepository.java | 13 +- 3 files changed, 93 insertions(+), 86 deletions(-) diff --git a/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java b/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java index a310f7e5..0ae36e7f 100644 --- a/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java +++ b/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java @@ -9,14 +9,15 @@ import org.springframework.data.repository.query.Param; import team7.inplace.likedPlace.domain.LikedPlace; -import java.util.Optional; - public interface LikedPlaceRepository extends JpaRepository { Optional findByUserIdAndPlaceId(Long userId, Long placeId); - Page findByUserIdAndIsLikedTrue(Long userId, Pageable pageable); - @Query("SELECT l.place.id FROM LikedPlace l WHERE l.user.id = :userId AND l.isLiked = true") Set findPlaceIdsByUserIdAndIsLikedTrue(@Param("userId") Long userId); + + @Query("SELECT lp FROM LikedPlace lp JOIN FETCH lp.place WHERE lp.user.id = :userId AND lp.isLiked = true") + Page findByUserIdAndIsLikedTrueWithPlace(@Param("userId") Long userId, + Pageable pageable); + } diff --git a/src/main/java/team7/inplace/place/application/PlaceService.java b/src/main/java/team7/inplace/place/application/PlaceService.java index 2222c4f8..28eda529 100644 --- a/src/main/java/team7/inplace/place/application/PlaceService.java +++ b/src/main/java/team7/inplace/place/application/PlaceService.java @@ -1,5 +1,11 @@ package team7.inplace.place.application; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -28,9 +34,6 @@ import team7.inplace.video.domain.Video; import team7.inplace.video.persistence.VideoRepository; -import java.util.*; -import java.util.stream.Collectors; - @Service @RequiredArgsConstructor public class PlaceService { @@ -44,21 +47,21 @@ public class PlaceService { private final LikedPlaceRepository likedPlaceRepository; public Page getPlacesWithinRadius( - PlacesCoordinateCommand placesCoordinateCommand, - PlacesFilterParamsCommand placesFilterParamsCommand) { + PlacesCoordinateCommand placesCoordinateCommand, + PlacesFilterParamsCommand placesFilterParamsCommand) { // categories와 influencers 필터 처리 List categoryFilters = placesFilterParamsCommand.isCategoryFilterExists() - ? Arrays.stream(placesFilterParamsCommand.categories().split(",")).toList() - : null; + ? Arrays.stream(placesFilterParamsCommand.categories().split(",")).toList() + : null; List influencerFilters = placesFilterParamsCommand.isInfluencerFilterExists() - ? Arrays.stream(placesFilterParamsCommand.influencers().split(",")).toList() - : null; + ? Arrays.stream(placesFilterParamsCommand.influencers().split(",")).toList() + : null; // 주어진 좌표로 장소를 찾고, 해당 페이지의 결과를 가져옵니다. Page placesPage = getPlacesByDistance(placesCoordinateCommand, categoryFilters, - influencerFilters); + influencerFilters); // Place ID 목록 추출 List placeIds = getPlaceIds(placesPage); @@ -66,7 +69,7 @@ public Page getPlacesWithinRadius( // influencer 조회 => video->Map(placeId, influencerName) List