From 22bef0d9cd39c1d764f7aec539ea8112d53af673 Mon Sep 17 00:00:00 2001 From: jeongyeon0208 Date: Sun, 15 Dec 2024 23:09:36 +0900 Subject: [PATCH 1/7] =?UTF-8?q?#231=20Refactor:=20=EC=99=80=EC=9D=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4,=20=EB=A6=AC=EB=B7=B0=20=EB=B3=BC=20?= =?UTF-8?q?=EB=95=8C=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EA=B0=99=EC=9D=B4=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wine/controller/WineController.java | 15 ++++---- .../wine/dto/response/WineResponseDTO.java | 6 +++- .../WineResponseWithThreeReviewsDTO.java | 5 ++- .../wine/dto/response/WineReviewDTO.java | 26 ++++++++++++++ .../dto/response/WineReviewResponseDTO.java | 27 +++++++------- .../wine/repository/WineRepositoryCustom.java | 7 ++-- .../wine/repository/WineRepositoryImpl.java | 35 +++++++++++++------ .../drinkeg/wine/service/WineService.java | 9 ++--- .../drinkeg/wine/service/WineServiceImpl.java | 18 +++++++--- 9 files changed, 101 insertions(+), 47 deletions(-) create mode 100644 src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java diff --git a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java index 7f5d56d..4f46fdb 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java @@ -4,8 +4,9 @@ import com.drinkeg.drinkeg.apipayLoad.ApiResponse; import com.drinkeg.drinkeg.wine.dto.response.SearchWineResponseDTO; import com.drinkeg.drinkeg.wine.dto.response.WineResponseWithThreeReviewsDTO; -import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; +import com.drinkeg.drinkeg.wine.dto.response.WineReviewDTO; import com.drinkeg.drinkeg.dto.loginDTO.commonDTO.PrincipalDetail; +import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; import com.drinkeg.drinkeg.wine.service.WineService; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; @@ -35,9 +36,10 @@ public ApiResponse> searchWine(@AuthenticationPrinci // 선택한 와인 정보 출력 @GetMapping("/{wineId}") @Operation(summary = "선택 와인 정보 열람", description = "선택한 와인의 정보를 wineResponseDTO에 담아 반환") - public ApiResponse showWine(@PathVariable("wineId") Long wineId) { + public ApiResponse showWine(@AuthenticationPrincipal PrincipalDetail principalDetail, + @PathVariable("wineId") Long wineId) { - WineResponseWithThreeReviewsDTO wineResponseWithThreeReviewsDTO = wineService.getWineResponseByWineId(wineId); + WineResponseWithThreeReviewsDTO wineResponseWithThreeReviewsDTO = wineService.getWineResponseByWineId(wineId, principalDetail); return ApiResponse.onSuccess(wineResponseWithThreeReviewsDTO); } @@ -45,11 +47,12 @@ public ApiResponse showWine(@PathVariable("wine // 와인 리뷰 보기 @GetMapping("/review/{wineId}") @Operation(summary = "선택 와인 리뷰 열람", description = "선택한 와인 리뷰를 List로 반환") - public ApiResponse> showWineReview(@PathVariable("wineId") Long wineId) { + public ApiResponse showWineReview(@AuthenticationPrincipal PrincipalDetail principalDetail, + @PathVariable("wineId") Long wineId) { - List wineReviews = wineService.getWineReviewsByWineId(wineId); + WineReviewResponseDTO wineReviewResponseDTO = wineService.getWineReviewsByWineId(wineId, principalDetail); - return ApiResponse.onSuccess(wineReviews); + return ApiResponse.onSuccess(wineReviewResponseDTO); } // 와인 이미지 업로드 diff --git a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseDTO.java b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseDTO.java index 9e80731..362bdd8 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseDTO.java @@ -31,12 +31,14 @@ public class WineResponseDTO { private float avgSatisfaction; + private boolean isLiked; + @QueryProjection public WineResponseDTO( Long wineId, String name, String imageUrl, int price, String sort, String area, float satisfaction, float avgSugarContent, float avgAcidity, float avgTannin, float avgBody, float avgAlcohol, - WineNoteNose wineNoteNose, float avgSatisfaction) { + WineNoteNose wineNoteNose, float avgSatisfaction, boolean isLiked) { this.wineId = wineId; this.name = name; @@ -54,6 +56,8 @@ public WineResponseDTO( this.wineNoteNose = wineNoteNose; this.avgSatisfaction = avgSatisfaction; + + this.isLiked = isLiked; } } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseWithThreeReviewsDTO.java b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseWithThreeReviewsDTO.java index ff21570..b5deeb8 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseWithThreeReviewsDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineResponseWithThreeReviewsDTO.java @@ -1,7 +1,6 @@ package com.drinkeg.drinkeg.wine.dto.response; import com.querydsl.core.annotations.QueryProjection; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,10 +10,10 @@ @NoArgsConstructor public class WineResponseWithThreeReviewsDTO { WineResponseDTO wineResponseDTO; - List recentReviews; + List recentReviews; @QueryProjection - public WineResponseWithThreeReviewsDTO(WineResponseDTO wineResponseDTO, List recentReviews) { + public WineResponseWithThreeReviewsDTO(WineResponseDTO wineResponseDTO, List recentReviews) { this.wineResponseDTO = wineResponseDTO; this.recentReviews = recentReviews; } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java new file mode 100644 index 0000000..f700fc3 --- /dev/null +++ b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java @@ -0,0 +1,26 @@ +package com.drinkeg.drinkeg.wine.dto.response; + +import com.querydsl.core.annotations.QueryProjection; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class WineReviewDTO { + + // 회원이 설정한 이름 + private String name; + + private String review; + + private float satisfaction; + + + @QueryProjection + public WineReviewDTO(String name, String review, float satisfaction) { + this.name = name; + this.review = review; + this.satisfaction = satisfaction; + } + +} diff --git a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java index d3c990d..a304977 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java @@ -1,28 +1,31 @@ package com.drinkeg.drinkeg.wine.dto.response; +import com.drinkeg.drinkeg.tastingNote.dto.response.TastingNotePreviewResponseDTO; import com.querydsl.core.annotations.QueryProjection; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + @Getter @NoArgsConstructor +@Builder public class WineReviewResponseDTO { - // 회원이 설정한 이름 - private String name; - - private String review; - - private float satisfaction; - + List wineReviews; + boolean isLiked; @QueryProjection - public WineReviewResponseDTO(String name, String review, float satisfaction) { - this.name = name; - this.review = review; - this.satisfaction = satisfaction; + public WineReviewResponseDTO(List wineReviews, boolean isLiked) { + this.wineReviews = wineReviews; + this.isLiked = isLiked; } + public static WineReviewResponseDTO create(List wineReviews, boolean isLiked){ + return WineReviewResponseDTO.builder() + .wineReviews(wineReviews) + .isLiked(isLiked) + .build(); + } } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java index 3e99ce3..b301551 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java @@ -9,9 +9,10 @@ import java.util.List; public interface WineRepositoryCustom { - List findWineReviewsById(Long wineId); + List findWinesWithLikeStatus(String searchName, Long memberId); + + WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId, Long memberID); + WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId); - WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId); List findRecommendWines(Member member); - List findWinesWithLikeStatus(String searchName, Long memberId); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java index 4bada09..fa96bd9 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java @@ -5,7 +5,6 @@ import com.drinkeg.drinkeg.dto.HomeDTO.RecommendWineDTO; import com.drinkeg.drinkeg.wine.dto.response.*; import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.CaseBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -27,23 +26,34 @@ public class WineRepositoryImpl implements WineRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public List findWineReviewsById(Long wineId) { - return queryFactory - .select(new QWineReviewResponseDTO( + public WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId) { + + Boolean isLiked = queryFactory + .select(wineWishlist.id.isNotNull().or(wineWishlist.id.isNull())) // memberId와 wineId에 따라 isLiked 여부 + .from(wineWishlist) + .where(wineWishlist.wine.id.eq(wineId).and(wineWishlist.member.id.eq(memberId))) + .fetchOne(); + + + // 최근 생성된 3개의 TastingNote + Optional> recentReviews = Optional.ofNullable(queryFactory + .select(new QWineReviewDTO( tastingNote.member.name, tastingNote.review, tastingNote.satisfaction )) .from(tastingNote) - .join(tastingNote.wine, wine) - .where(wine.id.eq(wineId)) - .fetch(); + .where(tastingNote.wine.id.eq(wineId)) + .orderBy(tastingNote.createdAt.desc()) // 최신순 정렬 + .fetch()); + + return WineReviewResponseDTO.create(recentReviews.get(), Boolean.TRUE.equals(isLiked)); } @Override - public WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId) { + public WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId, Long memberId) { // Wine 데이터를 가져옴 WineResponseDTO wineResponseDTO = queryFactory @@ -64,16 +74,19 @@ public WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId) { wine.wineNote.wineNoteNose, - wine.wineNote.avgSatisfaction.as("avgSatisfaction") + wine.wineNote.avgSatisfaction.as("avgSatisfaction"), + wineWishlist.id.isNotNull().as("isLiked") // memberId와 wineId에 따라 isLiked 여부 )) .from(wine) .leftJoin(wine.wineNote) + .leftJoin(wineWishlist) + .on(wineWishlist.wine.eq(wine).and(wineWishlist.member.id.eq(memberId))) .where(wine.id.eq(wineId)) .fetchOne(); // 최근 생성된 3개의 TastingNote - Optional> recentReviews = Optional.ofNullable(queryFactory - .select(new QWineReviewResponseDTO( + Optional> recentReviews = Optional.ofNullable(queryFactory + .select(new QWineReviewDTO( tastingNote.member.name, tastingNote.review, tastingNote.satisfaction diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java index 41a3682..00b6a2c 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java @@ -1,11 +1,8 @@ package com.drinkeg.drinkeg.wine.service; -import com.drinkeg.drinkeg.domain.Member; import com.drinkeg.drinkeg.wine.domain.Wine; import com.drinkeg.drinkeg.dto.HomeDTO.HomeResponseDTO; -import com.drinkeg.drinkeg.wine.dto.response.SearchWineResponseDTO; -import com.drinkeg.drinkeg.wine.dto.response.WineResponseWithThreeReviewsDTO; -import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; +import com.drinkeg.drinkeg.wine.dto.response.*; import com.drinkeg.drinkeg.dto.loginDTO.commonDTO.PrincipalDetail; import java.io.IOException; @@ -17,9 +14,9 @@ public interface WineService { public Wine findWineById(Long wineId); - public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId); + public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId, PrincipalDetail principalDetail); - public List getWineReviewsByWineId(Long wineId); + public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail); public HomeResponseDTO getHomeResponse(PrincipalDetail principalDetail); diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java index 4232000..6d61c48 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java @@ -9,9 +9,9 @@ import com.drinkeg.drinkeg.dto.HomeDTO.RecommendWineDTO; import com.drinkeg.drinkeg.wine.dto.response.SearchWineResponseDTO; import com.drinkeg.drinkeg.wine.dto.response.WineResponseWithThreeReviewsDTO; -import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; import com.drinkeg.drinkeg.dto.loginDTO.commonDTO.PrincipalDetail; import com.drinkeg.drinkeg.exception.GeneralException; +import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; import com.drinkeg.drinkeg.wine.repository.WineRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -51,13 +51,21 @@ public Wine findWineById(Long wineId) { } @Override - public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId){ - return wineRepository.findWineResponseByWineId(wineId); + public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId, PrincipalDetail principalDetail){ + // 회원을 조회한다. + Member member = memberRepository.findByUsername(principalDetail.getUsername()).orElseThrow( + () -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); + + return wineRepository.findWineResponseByWineId(wineId, member.getId()); } @Override - public List getWineReviewsByWineId(Long wineId){ - return wineRepository.findWineReviewsById(wineId); + public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail){ + // 회원을 조회한다. + Member member = memberRepository.findByUsername(principalDetail.getUsername()).orElseThrow( + () -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); + + return wineRepository.findWineReviewsAndLikeStatusByWineIdAndMemberId(wineId, member.getId()); } @Override From dfef40ddf574d62d163cea330ce12505d6353008 Mon Sep 17 00:00:00 2001 From: jeongyeon0208 Date: Sun, 15 Dec 2024 23:19:21 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#231=20Refactor:=20=EB=A6=AC=EB=B7=B0,=20?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=97=86=EC=9D=84=20=EB=95=8C=20?= =?UTF-8?q?null=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wine/dto/response/WineReviewDTO.java | 8 ++++++- .../wine/repository/WineRepositoryImpl.java | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java index f700fc3..0ff3261 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewDTO.java @@ -4,6 +4,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; + @Getter @NoArgsConstructor public class WineReviewDTO { @@ -15,12 +17,16 @@ public class WineReviewDTO { private float satisfaction; + private LocalDateTime createdAt; + @QueryProjection - public WineReviewDTO(String name, String review, float satisfaction) { + public WineReviewDTO(String name, String review, float satisfaction, LocalDateTime createdAt) { this.name = name; this.review = review; this.satisfaction = satisfaction; + this.createdAt = createdAt; + } } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java index fa96bd9..1df14e8 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java @@ -28,26 +28,28 @@ public class WineRepositoryImpl implements WineRepositoryCustom { @Override public WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId) { - Boolean isLiked = queryFactory - .select(wineWishlist.id.isNotNull().or(wineWishlist.id.isNull())) // memberId와 wineId에 따라 isLiked 여부 - .from(wineWishlist) - .where(wineWishlist.wine.id.eq(wineId).and(wineWishlist.member.id.eq(memberId))) - .fetchOne(); - + // wineWishlist에 해당하는 데이터가 존재하면 true, 존재하지 않으면 false + Optional isLiked = Optional.ofNullable( + queryFactory + .select(wineWishlist.id.isNotNull()) // wineWishlist가 존재하는지 여부를 체크 + .from(wineWishlist) + .where(wineWishlist.wine.id.eq(wineId).and(wineWishlist.member.id.eq(memberId))) + .fetchOne() + ); - // 최근 생성된 3개의 TastingNote Optional> recentReviews = Optional.ofNullable(queryFactory .select(new QWineReviewDTO( tastingNote.member.name, tastingNote.review, - tastingNote.satisfaction + tastingNote.satisfaction, + tastingNote.createdAt )) .from(tastingNote) .where(tastingNote.wine.id.eq(wineId)) .orderBy(tastingNote.createdAt.desc()) // 최신순 정렬 .fetch()); - return WineReviewResponseDTO.create(recentReviews.get(), Boolean.TRUE.equals(isLiked)); + return WineReviewResponseDTO.create(recentReviews.orElse(null), isLiked.orElse(false)); } @@ -89,7 +91,8 @@ public WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId, Lon .select(new QWineReviewDTO( tastingNote.member.name, tastingNote.review, - tastingNote.satisfaction + tastingNote.satisfaction, + tastingNote.createdAt )) .from(tastingNote) .where(tastingNote.wine.id.eq(wineId)) From da238064b50c922b9c8e270b386759fa011eb9e8 Mon Sep 17 00:00:00 2001 From: jeongyeon0208 Date: Sun, 15 Dec 2024 23:27:39 +0900 Subject: [PATCH 3/7] =?UTF-8?q?#231=20Refactor:=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EA=B8=B0=EC=A4=80=20=EC=B5=9C=EC=8B=A0?= =?UTF-8?q?=EC=88=9C,=20=EB=B3=84=EC=A0=90=EC=88=9C=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/drinkeg/drinkeg/wine/controller/WineController.java | 4 ++-- .../drinkeg/wine/repository/WineRepositoryCustom.java | 2 +- .../drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java | 5 +++-- .../java/com/drinkeg/drinkeg/wine/service/WineService.java | 2 +- .../com/drinkeg/drinkeg/wine/service/WineServiceImpl.java | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java index 4f46fdb..417cbec 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java @@ -48,9 +48,9 @@ public ApiResponse showWine(@AuthenticationPrin @GetMapping("/review/{wineId}") @Operation(summary = "선택 와인 리뷰 열람", description = "선택한 와인 리뷰를 List로 반환") public ApiResponse showWineReview(@AuthenticationPrincipal PrincipalDetail principalDetail, - @PathVariable("wineId") Long wineId) { + @PathVariable("wineId") Long wineId, @RequestParam Boolean orderByLatest) { - WineReviewResponseDTO wineReviewResponseDTO = wineService.getWineReviewsByWineId(wineId, principalDetail); + WineReviewResponseDTO wineReviewResponseDTO = wineService.getWineReviewsByWineId(wineId, principalDetail, orderByLatest); return ApiResponse.onSuccess(wineReviewResponseDTO); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java index b301551..1b2880e 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java @@ -12,7 +12,7 @@ public interface WineRepositoryCustom { List findWinesWithLikeStatus(String searchName, Long memberId); WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId, Long memberID); - WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId); + WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId, boolean orderByLatest); List findRecommendWines(Member member); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java index 1df14e8..932f28d 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java @@ -26,7 +26,7 @@ public class WineRepositoryImpl implements WineRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId) { + public WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId, boolean orderByLatest) { // wineWishlist에 해당하는 데이터가 존재하면 true, 존재하지 않으면 false Optional isLiked = Optional.ofNullable( @@ -46,7 +46,8 @@ public WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Lon )) .from(tastingNote) .where(tastingNote.wine.id.eq(wineId)) - .orderBy(tastingNote.createdAt.desc()) // 최신순 정렬 + .orderBy(orderByLatest? tastingNote.createdAt.desc() + : tastingNote.satisfaction.desc()) // 최신순 정렬 .fetch()); return WineReviewResponseDTO.create(recentReviews.orElse(null), isLiked.orElse(false)); diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java index 00b6a2c..e051323 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java @@ -16,7 +16,7 @@ public interface WineService { public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId, PrincipalDetail principalDetail); - public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail); + public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail, boolean orderByLatest); public HomeResponseDTO getHomeResponse(PrincipalDetail principalDetail); diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java index 6d61c48..fd678db 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java @@ -60,12 +60,12 @@ public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId, Prin } @Override - public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail){ + public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail, boolean orderByLatest){ // 회원을 조회한다. Member member = memberRepository.findByUsername(principalDetail.getUsername()).orElseThrow( () -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); - return wineRepository.findWineReviewsAndLikeStatusByWineIdAndMemberId(wineId, member.getId()); + return wineRepository.findWineReviewsAndLikeStatusByWineIdAndMemberId(wineId, member.getId(), orderByLatest); } @Override From 0c86e1ba3330cc77a16e52366b87eef13fe8512d Mon Sep 17 00:00:00 2001 From: jeongyeon0208 Date: Wed, 18 Dec 2024 14:31:13 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#231=20Refactor:=20=EC=99=80=EC=9D=B8=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8B=9C,=20=EC=99=80=EC=9D=B8=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=99=80=20?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/WineWishlistRepository.java | 2 +- .../WineWishlistRepositoryCustom.java | 6 ++++ .../WineWishlistRepositoryImpl.java | 33 +++++++++++++++++++ .../WineWishlistService.java | 4 --- .../WineWishlistServiceImpl.java | 5 --- .../wine/controller/WineController.java | 1 + .../dto/response/WineReviewResponseDTO.java | 6 +++- .../wine/repository/WineRepositoryCustom.java | 4 +-- .../wine/repository/WineRepositoryImpl.java | 13 ++------ .../drinkeg/wine/service/WineServiceImpl.java | 8 ++++- 10 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryCustom.java create mode 100644 src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryImpl.java diff --git a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepository.java b/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepository.java index 03a8658..7448f25 100644 --- a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepository.java +++ b/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepository.java @@ -8,7 +8,7 @@ import java.util.List; -public interface WineWishlistRepository extends JpaRepository { +public interface WineWishlistRepository extends JpaRepository, WineWishlistRepositoryCustom { List findAllByMember(Member member); diff --git a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryCustom.java b/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryCustom.java new file mode 100644 index 0000000..8053ce2 --- /dev/null +++ b/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryCustom.java @@ -0,0 +1,6 @@ +package com.drinkeg.drinkeg.repository; + +public interface WineWishlistRepositoryCustom { + + Boolean existsByMemberIdAndWineId(Long memberId, Long wineId); +} diff --git a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryImpl.java new file mode 100644 index 0000000..583a6aa --- /dev/null +++ b/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryImpl.java @@ -0,0 +1,33 @@ +package com.drinkeg.drinkeg.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +import static com.drinkeg.drinkeg.domain.QWineWishlist.wineWishlist; + +@Repository +@RequiredArgsConstructor +@Transactional +public class WineWishlistRepositoryImpl implements WineWishlistRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + + @Override + public Boolean existsByMemberIdAndWineId(Long memberId, Long wineId) { + // wineWishlist에 해당하는 데이터가 존재하면 true, 존재하지 않으면 false + Optional isLiked = Optional.ofNullable( + queryFactory + .select(wineWishlist.id.isNotNull()) // wineWishlist가 존재하는지 여부를 체크 + .from(wineWishlist) + .where(wineWishlist.wine.id.eq(wineId).and(wineWishlist.member.id.eq(memberId))) + .fetchOne() + ); + + return isLiked.orElse(false); + } +} diff --git a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistService.java b/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistService.java index 89437c6..d05401b 100644 --- a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistService.java +++ b/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistService.java @@ -1,7 +1,5 @@ package com.drinkeg.drinkeg.service.wineWishlistService; -import com.drinkeg.drinkeg.domain.Member; -import com.drinkeg.drinkeg.wine.domain.Wine; import com.drinkeg.drinkeg.dto.WineWishlistDTO.request.WineWishlistRequestDTO; import com.drinkeg.drinkeg.dto.WineWishlistDTO.response.WineWishlistResponseDTO; @@ -13,6 +11,4 @@ public interface WineWishlistService { List getAllWineWishlistByMember(String username); void deleteWineWishlistById(Long wineWishlistId, String username); - - public boolean isLiked(Member member, Wine wine); } diff --git a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistServiceImpl.java index b6b9d3b..eff9716 100644 --- a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistServiceImpl.java @@ -61,9 +61,4 @@ public void deleteWineWishlistById(Long wineWishlistId, String username) { wineWishlistRepository.deleteById(wineWishlistId); } - - @Override - public boolean isLiked(Member member, Wine wine) { - return wineWishlistRepository.existsByMemberAndWine(member, wine); - } } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java index 417cbec..def4934 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java @@ -52,6 +52,7 @@ public ApiResponse showWineReview(@AuthenticationPrincipa WineReviewResponseDTO wineReviewResponseDTO = wineService.getWineReviewsByWineId(wineId, principalDetail, orderByLatest); + return ApiResponse.onSuccess(wineReviewResponseDTO); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java index a304977..3f87ac3 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java @@ -19,7 +19,6 @@ public class WineReviewResponseDTO { @QueryProjection public WineReviewResponseDTO(List wineReviews, boolean isLiked) { this.wineReviews = wineReviews; - this.isLiked = isLiked; } public static WineReviewResponseDTO create(List wineReviews, boolean isLiked){ @@ -28,4 +27,9 @@ public static WineReviewResponseDTO create(List wineReviews, bool .isLiked(isLiked) .build(); } + + // 좋아요 여부 업데이트 + public void setLiked(boolean isLiked) { + this.isLiked = isLiked; + } } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java index 1b2880e..06519e0 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryCustom.java @@ -4,7 +4,7 @@ import com.drinkeg.drinkeg.dto.HomeDTO.RecommendWineDTO; import com.drinkeg.drinkeg.wine.dto.response.SearchWineResponseDTO; import com.drinkeg.drinkeg.wine.dto.response.WineResponseWithThreeReviewsDTO; -import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; +import com.drinkeg.drinkeg.wine.dto.response.WineReviewDTO; import java.util.List; @@ -12,7 +12,7 @@ public interface WineRepositoryCustom { List findWinesWithLikeStatus(String searchName, Long memberId); WineResponseWithThreeReviewsDTO findWineResponseByWineId(Long wineId, Long memberID); - WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId, boolean orderByLatest); + List findWineReviewsByWineIdAndMemberId(Long wineId, boolean orderByLatest); List findRecommendWines(Member member); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java index 932f28d..f514703 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java @@ -26,16 +26,7 @@ public class WineRepositoryImpl implements WineRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Long wineId, Long memberId, boolean orderByLatest) { - - // wineWishlist에 해당하는 데이터가 존재하면 true, 존재하지 않으면 false - Optional isLiked = Optional.ofNullable( - queryFactory - .select(wineWishlist.id.isNotNull()) // wineWishlist가 존재하는지 여부를 체크 - .from(wineWishlist) - .where(wineWishlist.wine.id.eq(wineId).and(wineWishlist.member.id.eq(memberId))) - .fetchOne() - ); + public List findWineReviewsByWineIdAndMemberId(Long wineId, boolean orderByLatest) { Optional> recentReviews = Optional.ofNullable(queryFactory .select(new QWineReviewDTO( @@ -50,7 +41,7 @@ public WineReviewResponseDTO findWineReviewsAndLikeStatusByWineIdAndMemberId(Lon : tastingNote.satisfaction.desc()) // 최신순 정렬 .fetch()); - return WineReviewResponseDTO.create(recentReviews.orElse(null), isLiked.orElse(false)); + return recentReviews.orElse(null); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java index fd678db..33288dd 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java @@ -4,6 +4,7 @@ import com.drinkeg.drinkeg.apipayLoad.code.status.ErrorStatus; import com.drinkeg.drinkeg.domain.Member; import com.drinkeg.drinkeg.repository.MemberRepository; +import com.drinkeg.drinkeg.repository.WineWishlistRepository; import com.drinkeg.drinkeg.wine.domain.Wine; import com.drinkeg.drinkeg.dto.HomeDTO.HomeResponseDTO; import com.drinkeg.drinkeg.dto.HomeDTO.RecommendWineDTO; @@ -11,6 +12,7 @@ import com.drinkeg.drinkeg.wine.dto.response.WineResponseWithThreeReviewsDTO; import com.drinkeg.drinkeg.dto.loginDTO.commonDTO.PrincipalDetail; import com.drinkeg.drinkeg.exception.GeneralException; +import com.drinkeg.drinkeg.wine.dto.response.WineReviewDTO; import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; import com.drinkeg.drinkeg.wine.repository.WineRepository; import lombok.RequiredArgsConstructor; @@ -31,6 +33,7 @@ public class WineServiceImpl implements WineService { private final MemberRepository memberRepository; private final S3Service s3Service; + private final WineWishlistRepository wineWishlistRepository; @Override public List searchWinesByName(String searchName, PrincipalDetail principalDetail) { @@ -65,7 +68,10 @@ public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail Member member = memberRepository.findByUsername(principalDetail.getUsername()).orElseThrow( () -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); - return wineRepository.findWineReviewsAndLikeStatusByWineIdAndMemberId(wineId, member.getId(), orderByLatest); + List wineReviews = wineRepository.findWineReviewsByWineIdAndMemberId(wineId, orderByLatest); + boolean liked = wineWishlistRepository.existsByMemberIdAndWineId(member.getId(), wineId); + + return WineReviewResponseDTO.create(wineReviews, liked); } @Override From d4bb19de0f18fdaa2a3b4dcafde0bd713e00166d Mon Sep 17 00:00:00 2001 From: jeongyeon0208 Date: Wed, 18 Dec 2024 14:34:24 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#231=20Refactor:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20setLiked=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drinkeg/wine/dto/response/WineReviewResponseDTO.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java index 3f87ac3..78d4e40 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/dto/response/WineReviewResponseDTO.java @@ -27,9 +27,4 @@ public static WineReviewResponseDTO create(List wineReviews, bool .isLiked(isLiked) .build(); } - - // 좋아요 여부 업데이트 - public void setLiked(boolean isLiked) { - this.isLiked = isLiked; - } } From d7e5999229ca75569c5ebfe85f88f108db7d987e Mon Sep 17 00:00:00 2001 From: jeongyeon0208 Date: Wed, 18 Dec 2024 14:38:00 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#231=20Refactor:=20=EC=99=80=EC=9D=B8=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/drinkeg/drinkeg/wine/controller/WineController.java | 4 +--- .../java/com/drinkeg/drinkeg/wine/service/WineService.java | 2 +- .../com/drinkeg/drinkeg/wine/service/WineServiceImpl.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java index def4934..e543330 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/controller/WineController.java @@ -4,7 +4,6 @@ import com.drinkeg.drinkeg.apipayLoad.ApiResponse; import com.drinkeg.drinkeg.wine.dto.response.SearchWineResponseDTO; import com.drinkeg.drinkeg.wine.dto.response.WineResponseWithThreeReviewsDTO; -import com.drinkeg.drinkeg.wine.dto.response.WineReviewDTO; import com.drinkeg.drinkeg.dto.loginDTO.commonDTO.PrincipalDetail; import com.drinkeg.drinkeg.wine.dto.response.WineReviewResponseDTO; import com.drinkeg.drinkeg.wine.service.WineService; @@ -50,8 +49,7 @@ public ApiResponse showWine(@AuthenticationPrin public ApiResponse showWineReview(@AuthenticationPrincipal PrincipalDetail principalDetail, @PathVariable("wineId") Long wineId, @RequestParam Boolean orderByLatest) { - WineReviewResponseDTO wineReviewResponseDTO = wineService.getWineReviewsByWineId(wineId, principalDetail, orderByLatest); - + WineReviewResponseDTO wineReviewResponseDTO = wineService.getWineReviewsAndIsLikedByWineId(wineId, principalDetail, orderByLatest); return ApiResponse.onSuccess(wineReviewResponseDTO); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java index e051323..e7e58f4 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineService.java @@ -16,7 +16,7 @@ public interface WineService { public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId, PrincipalDetail principalDetail); - public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail, boolean orderByLatest); + public WineReviewResponseDTO getWineReviewsAndIsLikedByWineId(Long wineId, PrincipalDetail principalDetail, boolean orderByLatest); public HomeResponseDTO getHomeResponse(PrincipalDetail principalDetail); diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java index 33288dd..4993fc7 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java @@ -63,7 +63,7 @@ public WineResponseWithThreeReviewsDTO getWineResponseByWineId(Long wineId, Prin } @Override - public WineReviewResponseDTO getWineReviewsByWineId(Long wineId, PrincipalDetail principalDetail, boolean orderByLatest){ + public WineReviewResponseDTO getWineReviewsAndIsLikedByWineId(Long wineId, PrincipalDetail principalDetail, boolean orderByLatest){ // 회원을 조회한다. Member member = memberRepository.findByUsername(principalDetail.getUsername()).orElseThrow( () -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); From f73b4cdbab99051bb012adc9c752c27800779022 Mon Sep 17 00:00:00 2001 From: jeongyeon0208 Date: Wed, 18 Dec 2024 20:01:40 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#233=20Refactor:=20WineWishlist=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/drinkeg/drinkeg/controller/WineWishlist.java | 7 +++---- .../drinkeg/converter/WineWishlistConverter.java | 4 ++-- .../drinkeg/wine/repository/WineRepositoryImpl.java | 2 +- .../drinkeg/drinkeg/wine/service/WineServiceImpl.java | 2 +- .../{ => wineWishlist}/domain/WineWishlist.java | 3 ++- .../dto}/request/WineWishlistRequestDTO.java | 2 +- .../dto}/response/WineWishlistResponseDTO.java | 2 +- .../repository/WineWishlistRepository.java | 4 ++-- .../repository/WineWishlistRepositoryCustom.java | 2 +- .../repository/WineWishlistRepositoryImpl.java | 5 +++-- .../service}/WineWishlistService.java | 6 +++--- .../service}/WineWishlistServiceImpl.java | 10 +++++----- 12 files changed, 25 insertions(+), 24 deletions(-) rename src/main/java/com/drinkeg/drinkeg/{ => wineWishlist}/domain/WineWishlist.java (86%) rename src/main/java/com/drinkeg/drinkeg/{dto/WineWishlistDTO => wineWishlist/dto}/request/WineWishlistRequestDTO.java (80%) rename src/main/java/com/drinkeg/drinkeg/{dto/WineWishlistDTO => wineWishlist/dto}/response/WineWishlistResponseDTO.java (85%) rename src/main/java/com/drinkeg/drinkeg/{ => wineWishlist}/repository/WineWishlistRepository.java (78%) rename src/main/java/com/drinkeg/drinkeg/{ => wineWishlist}/repository/WineWishlistRepositoryCustom.java (69%) rename src/main/java/com/drinkeg/drinkeg/{ => wineWishlist}/repository/WineWishlistRepositoryImpl.java (88%) rename src/main/java/com/drinkeg/drinkeg/{service/wineWishlistService => wineWishlist/service}/WineWishlistService.java (60%) rename src/main/java/com/drinkeg/drinkeg/{service/wineWishlistService => wineWishlist/service}/WineWishlistServiceImpl.java (88%) diff --git a/src/main/java/com/drinkeg/drinkeg/controller/WineWishlist.java b/src/main/java/com/drinkeg/drinkeg/controller/WineWishlist.java index 52e6a2d..c268229 100644 --- a/src/main/java/com/drinkeg/drinkeg/controller/WineWishlist.java +++ b/src/main/java/com/drinkeg/drinkeg/controller/WineWishlist.java @@ -1,12 +1,11 @@ package com.drinkeg.drinkeg.controller; import com.drinkeg.drinkeg.apipayLoad.ApiResponse; -import com.drinkeg.drinkeg.domain.Member; -import com.drinkeg.drinkeg.dto.WineWishlistDTO.request.WineWishlistRequestDTO; -import com.drinkeg.drinkeg.dto.WineWishlistDTO.response.WineWishlistResponseDTO; +import com.drinkeg.drinkeg.wineWishlist.dto.request.WineWishlistRequestDTO; +import com.drinkeg.drinkeg.wineWishlist.dto.response.WineWishlistResponseDTO; import com.drinkeg.drinkeg.dto.loginDTO.commonDTO.PrincipalDetail; import com.drinkeg.drinkeg.service.memberService.MemberService; -import com.drinkeg.drinkeg.service.wineWishlistService.WineWishlistService; +import com.drinkeg.drinkeg.wineWishlist.service.WineWishlistService; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/drinkeg/drinkeg/converter/WineWishlistConverter.java b/src/main/java/com/drinkeg/drinkeg/converter/WineWishlistConverter.java index 69943c9..650abed 100644 --- a/src/main/java/com/drinkeg/drinkeg/converter/WineWishlistConverter.java +++ b/src/main/java/com/drinkeg/drinkeg/converter/WineWishlistConverter.java @@ -2,8 +2,8 @@ import com.drinkeg.drinkeg.domain.Member; import com.drinkeg.drinkeg.wine.domain.Wine; -import com.drinkeg.drinkeg.domain.WineWishlist; -import com.drinkeg.drinkeg.dto.WineWishlistDTO.response.WineWishlistResponseDTO; +import com.drinkeg.drinkeg.wineWishlist.domain.WineWishlist; +import com.drinkeg.drinkeg.wineWishlist.dto.response.WineWishlistResponseDTO; import com.drinkeg.drinkeg.wine.dto.response.SearchWineResponseDTO; public class WineWishlistConverter { diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java index f514703..e370955 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java @@ -14,9 +14,9 @@ import java.util.List; import java.util.Optional; -import static com.drinkeg.drinkeg.domain.QWineWishlist.wineWishlist; import static com.drinkeg.drinkeg.tastingNote.domain.QTastingNote.tastingNote; import static com.drinkeg.drinkeg.wine.domain.QWine.wine; +import static com.drinkeg.drinkeg.wineWishlist.domain.QWineWishlist.wineWishlist; @Repository @RequiredArgsConstructor diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java index 4993fc7..7e97e5b 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java @@ -4,7 +4,7 @@ import com.drinkeg.drinkeg.apipayLoad.code.status.ErrorStatus; import com.drinkeg.drinkeg.domain.Member; import com.drinkeg.drinkeg.repository.MemberRepository; -import com.drinkeg.drinkeg.repository.WineWishlistRepository; +import com.drinkeg.drinkeg.wineWishlist.repository.WineWishlistRepository; import com.drinkeg.drinkeg.wine.domain.Wine; import com.drinkeg.drinkeg.dto.HomeDTO.HomeResponseDTO; import com.drinkeg.drinkeg.dto.HomeDTO.RecommendWineDTO; diff --git a/src/main/java/com/drinkeg/drinkeg/domain/WineWishlist.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/domain/WineWishlist.java similarity index 86% rename from src/main/java/com/drinkeg/drinkeg/domain/WineWishlist.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/domain/WineWishlist.java index e51382f..41e5fd6 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/WineWishlist.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/domain/WineWishlist.java @@ -1,5 +1,6 @@ -package com.drinkeg.drinkeg.domain; +package com.drinkeg.drinkeg.wineWishlist.domain; +import com.drinkeg.drinkeg.domain.Member; import com.drinkeg.drinkeg.wine.domain.Wine; import jakarta.persistence.*; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/drinkeg/drinkeg/dto/WineWishlistDTO/request/WineWishlistRequestDTO.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/dto/request/WineWishlistRequestDTO.java similarity index 80% rename from src/main/java/com/drinkeg/drinkeg/dto/WineWishlistDTO/request/WineWishlistRequestDTO.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/dto/request/WineWishlistRequestDTO.java index 242c50a..076f437 100644 --- a/src/main/java/com/drinkeg/drinkeg/dto/WineWishlistDTO/request/WineWishlistRequestDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/dto/request/WineWishlistRequestDTO.java @@ -1,4 +1,4 @@ -package com.drinkeg.drinkeg.dto.WineWishlistDTO.request; +package com.drinkeg.drinkeg.wineWishlist.dto.request; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/drinkeg/drinkeg/dto/WineWishlistDTO/response/WineWishlistResponseDTO.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/dto/response/WineWishlistResponseDTO.java similarity index 85% rename from src/main/java/com/drinkeg/drinkeg/dto/WineWishlistDTO/response/WineWishlistResponseDTO.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/dto/response/WineWishlistResponseDTO.java index 5b83f21..3944677 100644 --- a/src/main/java/com/drinkeg/drinkeg/dto/WineWishlistDTO/response/WineWishlistResponseDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/dto/response/WineWishlistResponseDTO.java @@ -1,4 +1,4 @@ -package com.drinkeg.drinkeg.dto.WineWishlistDTO.response; +package com.drinkeg.drinkeg.wineWishlist.dto.response; import com.drinkeg.drinkeg.wine.dto.response.SearchWineResponseDTO; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepository.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepository.java similarity index 78% rename from src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepository.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepository.java index 7448f25..240a8ce 100644 --- a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepository.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepository.java @@ -1,8 +1,8 @@ -package com.drinkeg.drinkeg.repository; +package com.drinkeg.drinkeg.wineWishlist.repository; import com.drinkeg.drinkeg.domain.Member; import com.drinkeg.drinkeg.wine.domain.Wine; -import com.drinkeg.drinkeg.domain.WineWishlist; +import com.drinkeg.drinkeg.wineWishlist.domain.WineWishlist; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryCustom.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepositoryCustom.java similarity index 69% rename from src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryCustom.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepositoryCustom.java index 8053ce2..92e35d7 100644 --- a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryCustom.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepositoryCustom.java @@ -1,4 +1,4 @@ -package com.drinkeg.drinkeg.repository; +package com.drinkeg.drinkeg.wineWishlist.repository; public interface WineWishlistRepositoryCustom { diff --git a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepositoryImpl.java similarity index 88% rename from src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryImpl.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepositoryImpl.java index 583a6aa..d00fdf1 100644 --- a/src/main/java/com/drinkeg/drinkeg/repository/WineWishlistRepositoryImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/repository/WineWishlistRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.drinkeg.drinkeg.repository; +package com.drinkeg.drinkeg.wineWishlist.repository; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -7,7 +7,8 @@ import java.util.Optional; -import static com.drinkeg.drinkeg.domain.QWineWishlist.wineWishlist; +import static com.drinkeg.drinkeg.wineWishlist.domain.QWineWishlist.wineWishlist; + @Repository @RequiredArgsConstructor diff --git a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistService.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/service/WineWishlistService.java similarity index 60% rename from src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistService.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/service/WineWishlistService.java index d05401b..6c9d667 100644 --- a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistService.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/service/WineWishlistService.java @@ -1,7 +1,7 @@ -package com.drinkeg.drinkeg.service.wineWishlistService; +package com.drinkeg.drinkeg.wineWishlist.service; -import com.drinkeg.drinkeg.dto.WineWishlistDTO.request.WineWishlistRequestDTO; -import com.drinkeg.drinkeg.dto.WineWishlistDTO.response.WineWishlistResponseDTO; +import com.drinkeg.drinkeg.wineWishlist.dto.request.WineWishlistRequestDTO; +import com.drinkeg.drinkeg.wineWishlist.dto.response.WineWishlistResponseDTO; import java.util.List; diff --git a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/wineWishlist/service/WineWishlistServiceImpl.java similarity index 88% rename from src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistServiceImpl.java rename to src/main/java/com/drinkeg/drinkeg/wineWishlist/service/WineWishlistServiceImpl.java index eff9716..526f84c 100644 --- a/src/main/java/com/drinkeg/drinkeg/service/wineWishlistService/WineWishlistServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wineWishlist/service/WineWishlistServiceImpl.java @@ -1,16 +1,16 @@ -package com.drinkeg.drinkeg.service.wineWishlistService; +package com.drinkeg.drinkeg.wineWishlist.service; import com.drinkeg.drinkeg.apipayLoad.code.status.ErrorStatus; import com.drinkeg.drinkeg.converter.WineWishlistConverter; import com.drinkeg.drinkeg.domain.Member; import com.drinkeg.drinkeg.wine.domain.Wine; -import com.drinkeg.drinkeg.domain.WineWishlist; -import com.drinkeg.drinkeg.dto.WineWishlistDTO.request.WineWishlistRequestDTO; -import com.drinkeg.drinkeg.dto.WineWishlistDTO.response.WineWishlistResponseDTO; +import com.drinkeg.drinkeg.wineWishlist.domain.WineWishlist; +import com.drinkeg.drinkeg.wineWishlist.dto.request.WineWishlistRequestDTO; +import com.drinkeg.drinkeg.wineWishlist.dto.response.WineWishlistResponseDTO; import com.drinkeg.drinkeg.exception.GeneralException; import com.drinkeg.drinkeg.repository.MemberRepository; import com.drinkeg.drinkeg.wine.repository.WineRepository; -import com.drinkeg.drinkeg.repository.WineWishlistRepository; +import com.drinkeg.drinkeg.wineWishlist.repository.WineWishlistRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service;