From 94d483b04063eaebd9133eb9a5d170543a9c2035 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Sun, 13 Aug 2023 22:19:09 +0900 Subject: [PATCH 01/13] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5=EC=97=90=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=20profile=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/domain/MemberRepository.java | 3 +- .../MemberRepositoryCustom.java | 10 ++++ .../infrastructure/MemberRepositoryImpl.java | 41 ++++++++++++++ .../review/application/ReviewService.java | 53 ++++++++++++++++--- .../review/application/dto/ReviewDto.java | 9 +++- 5 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java create mode 100644 src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java diff --git a/src/main/java/org/prography/kagongsillok/member/domain/MemberRepository.java b/src/main/java/org/prography/kagongsillok/member/domain/MemberRepository.java index e175277..0aeac88 100644 --- a/src/main/java/org/prography/kagongsillok/member/domain/MemberRepository.java +++ b/src/main/java/org/prography/kagongsillok/member/domain/MemberRepository.java @@ -1,7 +1,8 @@ package org.prography.kagongsillok.member.domain; +import org.prography.kagongsillok.member.infrastructure.MemberRepositoryCustom; import org.springframework.data.jpa.repository.JpaRepository; -public interface MemberRepository extends JpaRepository { +public interface MemberRepository extends JpaRepository, MemberRepositoryCustom { } diff --git a/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java new file mode 100644 index 0000000..1703293 --- /dev/null +++ b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java @@ -0,0 +1,10 @@ +package org.prography.kagongsillok.member.infrastructure; + +import java.util.List; +import java.util.Map; +import org.prography.kagongsillok.member.domain.Member; + +public interface MemberRepositoryCustom { + + Map findByIdIn(List memberIds); +} diff --git a/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java new file mode 100644 index 0000000..b3ddc55 --- /dev/null +++ b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java @@ -0,0 +1,41 @@ +package org.prography.kagongsillok.member.infrastructure; + +import static org.prography.kagongsillok.member.domain.QMember.member; +import static org.prography.kagongsillok.review.domain.QReviewTag.reviewTag; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.prography.kagongsillok.member.domain.Member; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class MemberRepositoryImpl implements MemberRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Map findByIdIn(final List memberIds) { + return queryFactory + .selectFrom(member) + .where( + idIn(memberIds), + isNotDeleted() + ) + .stream() + .collect(Collectors.toMap(Member::getId, Function.identity())); + } + + private BooleanExpression idIn(final List ids) { + return member.id.in(ids); + } + + private BooleanExpression isNotDeleted() { + return member.isDeleted.eq(Boolean.FALSE); + } +} diff --git a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java index 4c0f0f1..517dfae 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java +++ b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java @@ -1,7 +1,9 @@ package org.prography.kagongsillok.review.application; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.common.utils.CustomListUtils; import org.prography.kagongsillok.member.application.exception.NotFoundMemberException; @@ -41,29 +43,44 @@ public ReviewDto createReview(final ReviewCreateCommand reviewCreateCommand) { final Review savedReview = reviewRepository.save(review); - return ReviewDto.from(savedReview); + return ReviewDto.of(savedReview, member); } public ReviewDto getReview(final Long id) { final Review review = reviewRepository.findById(id) .orElseThrow(() -> new NotFoundReviewException(id)); + final Long memberId = review.getMemberId(); + final Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new NotFoundMemberException(memberId)); if (review.getIsDeleted()) { throw new NotFoundReviewException(id); } + if (member.getIsDeleted()) { + throw new NotFoundReviewException(memberId); + } - return ReviewDto.from(review); + return ReviewDto.of(review, member); } public List getAllReviewsByMemberId(final Long memberId) { final List reviews = reviewRepository.findAllByMemberId(memberId); - return CustomListUtils.mapTo(reviews, ReviewDto::from); + List reviewDtos = new ArrayList<>(); + for (Review review : reviews) { + final Member member = memberRepository.findById(review.getMemberId()) + .orElseThrow(() -> new NotFoundMemberException(review.getMemberId())); + reviewDtos.add(ReviewDto.of(review, member)); + } + + return reviewDtos; } public List getAllReviewsByPlaceId(final Long placeId) { final List reviews = reviewRepository.findAllByPlaceId(placeId); + final List reviewedMemberIds = getReviewedMemberIds(reviews); + final Map reviewedMembers = memberRepository.findByIdIn(reviewedMemberIds); - return CustomListUtils.mapTo(reviews, ReviewDto::from); + return mappingMemberToReview(reviews, reviewedMembers); } @Transactional @@ -73,10 +90,12 @@ public ReviewDto updateReview(final Long id, final ReviewUpdateCommand reviewUpd final Map updateReviewTags = reviewTagRepository.findByPerId(reviewUpdateCommand.getReviewTagIds()); final Review target = reviewUpdateCommand.toEntity(updateReviewTags); - review.update(target); - return ReviewDto.from(review); + final Member member = memberRepository.findById(target.getMemberId()) + .orElseThrow(() -> new NotFoundMemberException(target.getMemberId())); + + return ReviewDto.of(review, member); } @Transactional @@ -86,4 +105,26 @@ public void deleteReview(final Long id) { review.delete(); } + + private List getReviewedMemberIds(final List reviews) { + return reviews.stream() + .map(review -> review.getMemberId()) + .collect(Collectors.toList()); + } + + private List mappingMemberToReview(final List reviews, final Map members) { + return reviews.stream() + .map(review -> { + Member member = members.get(review.getMemberId()); + if (member == null) { + member = Member.builder() + .nickname("알 수 없음") + .email("Unknown@unknown.com") + .build(); + } + + return ReviewDto.of(review, member); + }) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java index e3c7ecd..04dc1ed 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java +++ b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.prography.kagongsillok.member.domain.Member; import org.prography.kagongsillok.review.domain.Review; import org.prography.kagongsillok.review.domain.ReviewTagMapping; import org.prography.kagongsillok.review.domain.ReviewTagMappings; @@ -19,6 +20,7 @@ public class ReviewDto { private Long memberId; private Long placeId; private String memberNickName; + private String memberProfileUrl; private int rating; private String content; private List imageIds; @@ -31,6 +33,7 @@ public ReviewDto( final Long memberId, final Long placeId, final String memberNickName, + final String memberProfileUrl, final int rating, final String content, final List imageIds, @@ -41,6 +44,7 @@ public ReviewDto( this.memberId = memberId; this.placeId = placeId; this.memberNickName = memberNickName; + this.memberProfileUrl = memberProfileUrl; this.rating = rating; this.content = content; this.imageIds = imageIds; @@ -48,13 +52,14 @@ public ReviewDto( this.writtenAt = writtenAt; } - public static ReviewDto from(Review review) { + public static ReviewDto of(final Review review, final Member member) { return ReviewDto .builder() .id(review.getId()) .memberId(review.getMemberId()) .placeId(review.getPlaceId()) .memberNickName(review.getMemberNickName()) + .memberProfileUrl(member.getProfileImageUrl()) .rating(review.getRating()) .content(review.getContent()) .imageIds(review.getImageIds()) @@ -63,7 +68,7 @@ public static ReviewDto from(Review review) { .build(); } - private static List getTagIds(ReviewTagMappings reviewTags) { + private static List getTagIds(final ReviewTagMappings reviewTags) { List reviewTagMappings = reviewTags.getValues(); List tagIds = new ArrayList<>(); From 282878b39016a6b39035757670c3cd0f9528d6c3 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Mon, 14 Aug 2023 14:43:03 +0900 Subject: [PATCH 02/13] =?UTF-8?q?feat:=20=ED=83=9C=EA=B7=B8=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EA=B2=80=EC=83=89=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/application/PlaceService.java | 17 ++++++++++++ .../place/ui/PlaceV1Controller.java | 10 +++++++ .../ReviewRepositoryCustom.java | 2 ++ .../infrastructure/ReviewRepositoryImpl.java | 26 ++++++++++++++++++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java index 8be78a2..565d10e 100644 --- a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java +++ b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java @@ -1,6 +1,7 @@ package org.prography.kagongsillok.place.application; import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.common.utils.CustomListUtils; import org.prography.kagongsillok.place.application.dto.PlaceCreateCommand; @@ -11,6 +12,9 @@ import org.prography.kagongsillok.place.domain.Location; import org.prography.kagongsillok.place.domain.Place; import org.prography.kagongsillok.place.domain.PlaceRepository; +import org.prography.kagongsillok.review.domain.Review; +import org.prography.kagongsillok.review.domain.ReviewRepository; +import org.prography.kagongsillok.review.domain.ReviewTagRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,6 +24,7 @@ public class PlaceService { private final PlaceRepository placeRepository; + private final ReviewRepository reviewRepository; @Transactional public PlaceDto createPlace(final PlaceCreateCommand placeCreateCommand) { @@ -72,4 +77,16 @@ public void deletePlace(final Long id) { place.delete(); } + + public List searchPlacesByTags(final List reviewTagIds) { + final List reviews = reviewRepository.findByReviewTagIds(reviewTagIds); + final List placeIds = reviews.stream() + .map(review -> review.getPlaceId()) + .collect(Collectors.toList()); + + final List places = placeRepository.findByIdIn(placeIds); + + + return CustomListUtils.mapTo(places, PlaceDto::from); + } } diff --git a/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java b/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java index 0871c75..d7afa4f 100644 --- a/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java +++ b/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -44,4 +45,13 @@ public ResponseEntity> searchTitle(@RequestPar return CommonResponse.success(PlaceListResponse.of(placeDtos)); } + + @GetMapping("/tags") + public ResponseEntity> searchTaggedPlace( + @RequestBody final List tagIds + ) { + final List placeDtos = placeService.searchPlacesByTags(tagIds); + + return CommonResponse.success(PlaceListResponse.of(placeDtos)); + } } diff --git a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java index aa35137..189849c 100644 --- a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java +++ b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java @@ -8,4 +8,6 @@ public interface ReviewRepositoryCustom { List findAllByMemberId(final Long memberId); List findAllByPlaceId(final Long placeId); + + List findByReviewTagIds(final List reviewTagIds); } diff --git a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java index f5ccf77..5b678f8 100644 --- a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java +++ b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java @@ -1,11 +1,11 @@ package org.prography.kagongsillok.review.infrastructure; -import static org.prography.kagongsillok.record.domain.QStudyRecord.studyRecord; import static org.prography.kagongsillok.review.domain.QReview.review; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.review.domain.Review; import org.springframework.stereotype.Repository; @@ -42,7 +42,31 @@ public List findAllByPlaceId(final Long placeId) { .fetch(); } + @Override + public List findByReviewTagIds(final List reviewTagIds) { + List allReviews = queryFactory + .selectFrom(review) + .where( + isNotDeleted() + ) + .fetch(); + + return allReviews.stream() + .filter(rev -> rev.getTagMappings() + .getValues() + .stream() + .filter(reviewTagMapping -> reviewTagIds.contains( + reviewTagMapping + .getReviewTag() + .getId() + )) + .collect(Collectors.toList()) + .size() > 0) + .collect(Collectors.toList()); + } + private BooleanExpression isNotDeleted() { return review.isDeleted.eq(Boolean.FALSE); } + } From 057cdebc1aa49fdb7d0be91d2a2e9dbea5ee442a Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Mon, 14 Aug 2023 15:36:29 +0900 Subject: [PATCH 03/13] =?UTF-8?q?test:=20=ED=83=9C=EA=B7=B8=EB=93=A4?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=A5=EC=86=8C=20=EC=A1=B0=ED=9A=8C=20=EC=9D=B8?= =?UTF-8?q?=EC=88=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/ui/PlaceV1Controller.java | 2 +- .../acceptance/AcceptanceTestFixture.java | 17 ++++ .../acceptance/place/PlaceAcceptanceTest.java | 85 ++++++++++++++++++- 3 files changed, 101 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java b/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java index d7afa4f..4106d8f 100644 --- a/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java +++ b/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java @@ -48,7 +48,7 @@ public ResponseEntity> searchTitle(@RequestPar @GetMapping("/tags") public ResponseEntity> searchTaggedPlace( - @RequestBody final List tagIds + @RequestParam final List tagIds ) { final List placeDtos = placeService.searchPlacesByTags(tagIds); diff --git a/src/test/java/org/prography/kagongsillok/acceptance/AcceptanceTestFixture.java b/src/test/java/org/prography/kagongsillok/acceptance/AcceptanceTestFixture.java index f8170cb..c6ee8e9 100644 --- a/src/test/java/org/prography/kagongsillok/acceptance/AcceptanceTestFixture.java +++ b/src/test/java/org/prography/kagongsillok/acceptance/AcceptanceTestFixture.java @@ -157,6 +157,23 @@ public class AcceptanceTestFixture { .build(); } + public static ReviewCreateRequest 장소_ID로_리뷰_생성_요청_바디( + final Long placeId, + final Long memberId, + final String content, + final List tagIds + ) { + return ReviewCreateRequest + .builder() + .rating(5) + .memberId(memberId) + .placeId(placeId) + .content(content) + .imageIds(List.of(1L, 2L)) + .reviewTagIds(tagIds) + .build(); + } + public static ReviewCreateRequest 이미지_두개_태그_두개_장소_ID로_리뷰_생성_요청_바디( final Long memberId, final String content, diff --git a/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java b/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java index 141f613..78752ec 100644 --- a/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java +++ b/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java @@ -2,22 +2,34 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.prography.kagongsillok.acceptance.AcceptanceTestFixture.기본_닉네임_이메일_가입_요청_바디; import static org.prography.kagongsillok.acceptance.AcceptanceTestFixture.이미지_세개_링크_두개_장소_생성_요청_바디; +import static org.prography.kagongsillok.acceptance.AcceptanceTestFixture.장소_ID로_리뷰_생성_요청_바디; import static org.prography.kagongsillok.acceptance.AcceptanceTestFixture.장소_수정_요청_바디; +import static org.prography.kagongsillok.acceptance.AcceptanceTestFixture.태그_생성_요청_바디; import java.util.List; import org.junit.jupiter.api.Test; import org.prography.kagongsillok.acceptance.AcceptanceTest; +import org.prography.kagongsillok.auth.ui.dto.LocalJoinRequest; +import org.prography.kagongsillok.member.ui.dto.MemberResponse; import org.prography.kagongsillok.place.ui.dto.PlaceCreateRequest; import org.prography.kagongsillok.place.ui.dto.PlaceListResponse; import org.prography.kagongsillok.place.ui.dto.PlaceLocationAroundSearchRequest; import org.prography.kagongsillok.place.ui.dto.PlaceResponse; import org.prography.kagongsillok.place.ui.dto.PlaceUpdateRequest; +import org.prography.kagongsillok.review.ui.dto.ReviewCreateRequest; +import org.prography.kagongsillok.review.ui.dto.ReviewResponse; +import org.prography.kagongsillok.review.ui.dto.ReviewTagCreateRequest; +import org.prography.kagongsillok.review.ui.dto.ReviewTagResponse; public class PlaceAcceptanceTest extends AcceptanceTest { private static final String PLACE_ADMIN_BASE_URL_V1 = "/admin/v1/places"; private static final String PLACE_API_BASE_URL_V1 = "/api/v1/places"; + private static final String REVIEW_API_BASE_URL_V1 = "api/v1/reviews"; + private static final String TAG_ADMIN_BASE_URL_V1 = "admin/v1/tags"; + private static final String AUTH_API_BASE_URL_V1 = "/api/v1/auth"; @Test void 관리자가_장소를_등록한다() { @@ -156,6 +168,77 @@ public class PlaceAcceptanceTest extends AcceptanceTest { 없는_장소_이름으로_검색_검증(장소_이름으로_검색_응답1); } + @Test + void 태그로_관련된_장소들을_검색한다() { + final var 멤버_생성_요청_바디 = 기본_닉네임_이메일_가입_요청_바디("닉네임", "test@test.com"); + final var 생성된_멤버_id = 멤버_생성_요청(멤버_생성_요청_바디).getId(); + final var 장소_생성_요청_바디1 = 이미지_세개_링크_두개_장소_생성_요청_바디("testPlace1", 10.0, 10.0); + final var 장소_생성_요청_바디2 = 이미지_세개_링크_두개_장소_생성_요청_바디("testPlace2", -50.0, -50.0); + final var 장소_생성_요청_바디3 = 이미지_세개_링크_두개_장소_생성_요청_바디("testPlace3", -10.0, -20.0); + final var 생성_장소1_ID = 장소_생성_요청(장소_생성_요청_바디1).getId(); + final var 생성_장소2_ID = 장소_생성_요청(장소_생성_요청_바디2).getId(); + 장소_생성_요청(장소_생성_요청_바디2); + 장소_생성_요청(장소_생성_요청_바디3); + final var 태그_생성_요청_바디1 = 태그_생성_요청_바디("#tag1", "test tag1"); + final var 태그_생성_요청_바디2 = 태그_생성_요청_바디("#tag2", "test tag2"); + final var 태그_생성_요청_바디3 = 태그_생성_요청_바디("#tag3", "test tag3"); + final var 태그_생성_요청_바디4 = 태그_생성_요청_바디("#tag4", "test tag4"); + final var 생성된_태그1_ID = 태그_생성_요청(태그_생성_요청_바디1).getId(); + final var 생성된_태그2_ID = 태그_생성_요청(태그_생성_요청_바디2).getId(); + final var 생성된_태그3_ID = 태그_생성_요청(태그_생성_요청_바디3).getId(); + final var 생성된_태그4_ID = 태그_생성_요청(태그_생성_요청_바디4).getId(); + final var 입력_태그1 = 입력_태그_두개_생성(생성된_태그1_ID, 생성된_태그2_ID); + final var 입력_태그2 = 입력_태그_두개_생성(생성된_태그3_ID, 생성된_태그4_ID); + final var 리뷰_생성_요청_바디1 = 장소_ID로_리뷰_생성_요청_바디(생성_장소1_ID, 생성된_멤버_id, "test review", 입력_태그1); + final var 리뷰_생성_요청_바디2 = 장소_ID로_리뷰_생성_요청_바디(생성_장소2_ID, 생성된_멤버_id, "test review", 입력_태그2); + 리뷰_생성_요청(리뷰_생성_요청_바디1); + 리뷰_생성_요청(리뷰_생성_요청_바디2); + final var 조회할_태그_ID들 = 조회할_태그_생성(생성된_태그1_ID, 생성된_태그3_ID); + + final var 태그_ID로_장소_조회_응답 = 태그_ID로_장소_조회_요청(조회할_태그_ID들); + + 태그_ID로_장소_조회_검증(태그_ID로_장소_조회_응답); + } + + private MemberResponse 멤버_생성_요청(final LocalJoinRequest 멤버_생성_요청_바디) { + return 응답_바디_추출(post(AUTH_API_BASE_URL_V1 + "/local/join", 멤버_생성_요청_바디), MemberResponse.class); + } + + private static void 태그_ID로_장소_조회_검증(final PlaceListResponse 태그_ID로_장소_조회_응답) { + assertAll( + () -> assertThat(태그_ID로_장소_조회_응답.getPlaces().size()).isEqualTo(2), + () -> assertThat(태그_ID로_장소_조회_응답.getPlaces()).extracting("name") + .containsAll(List.of("testPlace1", "testPlace2")), + () -> assertThat(태그_ID로_장소_조회_응답.getPlaces()).extracting("latitude") + .containsAll(List.of(10.0, -50.0)), + () -> assertThat(태그_ID로_장소_조회_응답.getPlaces()).extracting("longitude") + .containsAll(List.of(10.0, -50.0)) + ); + } + + private PlaceListResponse 태그_ID로_장소_조회_요청(final List 조회할_태그_ID들) { + return 응답_바디_추출(get(PLACE_API_BASE_URL_V1 + "/tags" + + "?tagIds=" + 조회할_태그_ID들.get(0) + + "&tagIds=" + 조회할_태그_ID들.get(1) + ), PlaceListResponse.class); + } + + private List 조회할_태그_생성(final Long 생성된_태그1_ID, final Long 생성된_태그2_ID) { + return List.of(생성된_태그1_ID, 생성된_태그2_ID); + } + + private ReviewResponse 리뷰_생성_요청(final ReviewCreateRequest 리뷰_생성_요청_바디) { + return 응답_바디_추출(post(REVIEW_API_BASE_URL_V1, 리뷰_생성_요청_바디), ReviewResponse.class); + } + + private static List 입력_태그_두개_생성(final Long 태그1, final Long 태그2) { + return List.of(태그1, 태그2); + } + + private ReviewTagResponse 태그_생성_요청(final ReviewTagCreateRequest 태그_생성_요청_바디) { + return 응답_바디_추출(post(TAG_ADMIN_BASE_URL_V1, 태그_생성_요청_바디), ReviewTagResponse.class); + } + private static void 없는_장소_이름으로_검색_검증(final PlaceListResponse 장소_이름으로_검색_응답1) { assertAll( () -> assertThat(장소_이름으로_검색_응답1.getPlaces().size()).isEqualTo(0) @@ -296,6 +379,4 @@ public class PlaceAcceptanceTest extends AcceptanceTest { private PlaceResponse 장소_생성_요청(final PlaceCreateRequest 장소_생성_요청_바디) { return 응답_바디_추출(post(PLACE_ADMIN_BASE_URL_V1, 장소_생성_요청_바디), PlaceResponse.class); } - - } From 27f4876656dd7f122d98e9ad19b21f58396bdfa2 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Mon, 14 Aug 2023 21:10:08 +0900 Subject: [PATCH 04/13] =?UTF-8?q?refactor:=20=EC=9E=A5=EC=86=8C=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=EC=97=90=20=ED=83=9C=EA=B7=B8=20=EB=B3=B4?= =?UTF-8?q?=EB=82=B4=EB=8F=84=EB=A1=9D=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/application/PlaceService.java | 20 +++++++++++++++++- .../place/application/dto/PlaceDto.java | 21 ++++++++++++++++++- .../place/ui/PlaceV1Controller.java | 6 ++++++ .../place/ui/dto/PlaceResponse.java | 7 ++++++- 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java index 565d10e..e1afbe4 100644 --- a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java +++ b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java @@ -14,6 +14,7 @@ import org.prography.kagongsillok.place.domain.PlaceRepository; import org.prography.kagongsillok.review.domain.Review; import org.prography.kagongsillok.review.domain.ReviewRepository; +import org.prography.kagongsillok.review.domain.ReviewTag; import org.prography.kagongsillok.review.domain.ReviewTagRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -43,6 +44,24 @@ public PlaceDto getPlace(final Long id) { return PlaceDto.from(place); } + public PlaceDto getPlaceWithTags(final Long placeId) { + final Place place = placeRepository.findById(placeId) + .orElseThrow(() -> new NotFoundPlaceException(placeId)); + if (place.getIsDeleted()) { + throw new NotFoundPlaceException(placeId); + } + final List reviews = reviewRepository.findAllByPlaceId(placeId); + final List reviewTags = reviews.stream() + .flatMap(review -> review.getTagMappings() + .getValues() + .stream() + .map(reviewTagMapping -> reviewTagMapping.getReviewTag()) + ) + .collect(Collectors.toList()); + + return PlaceDto.of(place, reviewTags); + } + public List searchPlacesLocationAround(final PlaceLocationAroundSearchCondition searchCondition) { final List places = placeRepository.findByLocationAround( Location.of(searchCondition.getLatitude(), searchCondition.getLongitude()), @@ -86,7 +105,6 @@ public List searchPlacesByTags(final List reviewTagIds) { final List places = placeRepository.findByIdIn(placeIds); - return CustomListUtils.mapTo(places, PlaceDto::from); } } diff --git a/src/main/java/org/prography/kagongsillok/place/application/dto/PlaceDto.java b/src/main/java/org/prography/kagongsillok/place/application/dto/PlaceDto.java index 8eb0581..c1105d5 100644 --- a/src/main/java/org/prography/kagongsillok/place/application/dto/PlaceDto.java +++ b/src/main/java/org/prography/kagongsillok/place/application/dto/PlaceDto.java @@ -10,6 +10,7 @@ import org.prography.kagongsillok.place.domain.BusinessHour; import org.prography.kagongsillok.place.domain.Link; import org.prography.kagongsillok.place.domain.Place; +import org.prography.kagongsillok.review.domain.ReviewTag; @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -24,6 +25,7 @@ public class PlaceDto { private String phone; private List links; private List businessHours; + private List reviewTags; @Builder public PlaceDto( @@ -35,7 +37,8 @@ public PlaceDto( final List imageIds, final String phone, final List links, - final List businessHours + final List businessHours, + final List reviewTags ) { this.id = id; this.name = name; @@ -46,6 +49,7 @@ public PlaceDto( this.phone = phone; this.links = links; this.businessHours = businessHours; + this.reviewTags = reviewTags; } public static PlaceDto from(final Place place) { @@ -62,6 +66,21 @@ public static PlaceDto from(final Place place) { .build(); } + public static PlaceDto of(final Place place, final List reviewTags) { + return PlaceDto.builder() + .id(place.getId()) + .name(place.getName()) + .address(place.getAddress()) + .latitude(place.getLatitude()) + .longitude(place.getLongitude()) + .imageIds(place.getImageIds()) + .phone(place.getPhone()) + .links(CustomListUtils.mapTo(place.getLinks().getValues(), LinkDto::from)) + .businessHours(CustomListUtils.mapTo(place.getBusinessHours().getValues(), BusinessHourDto::from)) + .reviewTags(reviewTags) + .build(); + } + @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class LinkDto { diff --git a/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java b/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java index 4106d8f..b2fcc19 100644 --- a/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java +++ b/src/main/java/org/prography/kagongsillok/place/ui/PlaceV1Controller.java @@ -30,6 +30,12 @@ public ResponseEntity> getPlace(@PathVariable("id" return CommonResponse.success(PlaceResponse.from(placeDto)); } + @GetMapping("/with-tags/{placeId}") + public ResponseEntity> getPlaceWithTags(@PathVariable("placeId") final Long placeId) { + final PlaceDto placeDto = placeService.getPlaceWithTags(placeId); + return CommonResponse.success(PlaceResponse.from(placeDto)); + } + @GetMapping("/around") public ResponseEntity> searchAroundPlace( @ModelAttribute final PlaceLocationAroundSearchRequest request diff --git a/src/main/java/org/prography/kagongsillok/place/ui/dto/PlaceResponse.java b/src/main/java/org/prography/kagongsillok/place/ui/dto/PlaceResponse.java index 11434f6..746dbff 100644 --- a/src/main/java/org/prography/kagongsillok/place/ui/dto/PlaceResponse.java +++ b/src/main/java/org/prography/kagongsillok/place/ui/dto/PlaceResponse.java @@ -11,6 +11,7 @@ import org.prography.kagongsillok.place.application.dto.PlaceDto; import org.prography.kagongsillok.place.application.dto.PlaceDto.BusinessHourDto; import org.prography.kagongsillok.place.application.dto.PlaceDto.LinkDto; +import org.prography.kagongsillok.review.domain.ReviewTag; @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -25,6 +26,7 @@ public class PlaceResponse { private String phone; private List links; private List businessHours; + private List reviewTags; @Builder public PlaceResponse( @@ -36,7 +38,8 @@ public PlaceResponse( final List imageIds, final String phone, final List links, - final List businessHours + final List businessHours, + final List reviewTags ) { this.id = id; this.name = name; @@ -47,6 +50,7 @@ public PlaceResponse( this.phone = phone; this.links = links; this.businessHours = businessHours; + this.reviewTags = reviewTags; } public static PlaceResponse from(final PlaceDto placeDto) { @@ -60,6 +64,7 @@ public static PlaceResponse from(final PlaceDto placeDto) { .phone(placeDto.getPhone()) .links(CustomListUtils.mapTo(placeDto.getLinks(), LinkResponse::from)) .businessHours(CustomListUtils.mapTo(placeDto.getBusinessHours(), BusinessHourResponse::from)) + .reviewTags(placeDto.getReviewTags()) .build(); } From f4fd40ff41b760f3bec16457bd6eacd19e6f6e87 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Mon, 14 Aug 2023 22:43:16 +0900 Subject: [PATCH 05/13] =?UTF-8?q?refactor:=20=EC=9E=A5=EC=86=8C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5=EC=97=90=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=EB=90=9C=20=ED=83=9C=EA=B7=B8=20=EA=B0=99=EC=9D=B4=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EB=8F=84=EB=A1=9D=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/application/PlaceService.java | 52 ++++++++++++++----- .../ReviewRepositoryCustom.java | 3 ++ .../infrastructure/ReviewRepositoryImpl.java | 15 ++++++ 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java index e1afbe4..d1fd549 100644 --- a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java +++ b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java @@ -1,6 +1,10 @@ package org.prography.kagongsillok.place.application; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.common.utils.CustomListUtils; @@ -9,13 +13,13 @@ import org.prography.kagongsillok.place.application.dto.PlaceLocationAroundSearchCondition; import org.prography.kagongsillok.place.application.dto.PlaceUpdateCommand; import org.prography.kagongsillok.place.application.exception.NotFoundPlaceException; +import org.prography.kagongsillok.place.domain.Link; import org.prography.kagongsillok.place.domain.Location; import org.prography.kagongsillok.place.domain.Place; import org.prography.kagongsillok.place.domain.PlaceRepository; import org.prography.kagongsillok.review.domain.Review; import org.prography.kagongsillok.review.domain.ReviewRepository; import org.prography.kagongsillok.review.domain.ReviewTag; -import org.prography.kagongsillok.review.domain.ReviewTagRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -51,15 +55,8 @@ public PlaceDto getPlaceWithTags(final Long placeId) { throw new NotFoundPlaceException(placeId); } final List reviews = reviewRepository.findAllByPlaceId(placeId); - final List reviewTags = reviews.stream() - .flatMap(review -> review.getTagMappings() - .getValues() - .stream() - .map(reviewTagMapping -> reviewTagMapping.getReviewTag()) - ) - .collect(Collectors.toList()); - return PlaceDto.of(place, reviewTags); + return PlaceDto.of(place, getReviewTagsRelatedToPlace(reviews)); } public List searchPlacesLocationAround(final PlaceLocationAroundSearchCondition searchCondition) { @@ -69,13 +66,13 @@ public List searchPlacesLocationAround(final PlaceLocationAroundSearch searchCondition.getLongitudeBound() ); - return CustomListUtils.mapTo(places, PlaceDto::from); + return getPlaceDtos(places); } public List searchPlacesByName(final String name) { final List places = placeRepository.findByNameContains(name); - return CustomListUtils.mapTo(places, PlaceDto::from); + return getPlaceDtos(places); } @Transactional @@ -102,9 +99,38 @@ public List searchPlacesByTags(final List reviewTagIds) { final List placeIds = reviews.stream() .map(review -> review.getPlaceId()) .collect(Collectors.toList()); - final List places = placeRepository.findByIdIn(placeIds); - return CustomListUtils.mapTo(places, PlaceDto::from); + return createPlaceDtos(places, reviews); + } + + private List getPlaceDtos(final List places) { + final List placeIds = places.stream() + .map(place -> place.getId()) + .collect(Collectors.toList()); + final List reviews = reviewRepository.findByPlaceIds(placeIds); + + return createPlaceDtos(places, reviews); + } + + private List createPlaceDtos(final List places, final List reviews) { + return places.stream() + .map(place -> { + List relatedReviews = reviews.stream() + .filter(review -> review.getPlaceId().equals(place.getId())) + .collect(Collectors.toList()); + return PlaceDto.of(place, getReviewTagsRelatedToPlace(relatedReviews)); + }) + .collect(Collectors.toList()); + } + + private List getReviewTagsRelatedToPlace(final List reviews) { + return reviews.stream() + .flatMap(review -> review.getTagMappings() + .getValues() + .stream() + .map(reviewTagMapping -> reviewTagMapping.getReviewTag()) + ) + .collect(Collectors.toList()); } } diff --git a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java index 189849c..e12ceed 100644 --- a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java +++ b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryCustom.java @@ -1,6 +1,7 @@ package org.prography.kagongsillok.review.infrastructure; import java.util.List; +import java.util.Map; import org.prography.kagongsillok.review.domain.Review; public interface ReviewRepositoryCustom { @@ -10,4 +11,6 @@ public interface ReviewRepositoryCustom { List findAllByPlaceId(final Long placeId); List findByReviewTagIds(final List reviewTagIds); + + List findByPlaceIds(final List placeIds); } diff --git a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java index 5b678f8..710c978 100644 --- a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java +++ b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java @@ -1,13 +1,17 @@ package org.prography.kagongsillok.review.infrastructure; import static org.prography.kagongsillok.review.domain.QReview.review; +import static org.prography.kagongsillok.review.domain.QReviewTag.reviewTag; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; +import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.review.domain.Review; +import org.prography.kagongsillok.review.domain.ReviewTag; import org.springframework.stereotype.Repository; @Repository @@ -65,6 +69,17 @@ public List findByReviewTagIds(final List reviewTagIds) { .collect(Collectors.toList()); } + @Override + public List findByPlaceIds(final List placeIds) { + return queryFactory.selectFrom(review) + .where( + review.placeId.in(placeIds), + isNotDeleted() + ) + .stream() + .collect(Collectors.toList()); + } + private BooleanExpression isNotDeleted() { return review.isDeleted.eq(Boolean.FALSE); } From 948938cc1b4964bb5db7efd80438e1d2354a3057 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Mon, 14 Aug 2023 23:50:47 +0900 Subject: [PATCH 06/13] =?UTF-8?q?refactor:=20place=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?review=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20reviewTag=20join=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/application/PlaceService.java | 10 +++------- .../kagongsillok/review/domain/ReviewTag.java | 6 ------ .../infrastructure/ReviewRepositoryImpl.java | 16 +++++++++++++--- .../acceptance/place/PlaceAcceptanceTest.java | 3 +-- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java index d1fd549..27beec3 100644 --- a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java +++ b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java @@ -1,19 +1,13 @@ package org.prography.kagongsillok.place.application; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.prography.kagongsillok.common.utils.CustomListUtils; import org.prography.kagongsillok.place.application.dto.PlaceCreateCommand; import org.prography.kagongsillok.place.application.dto.PlaceDto; import org.prography.kagongsillok.place.application.dto.PlaceLocationAroundSearchCondition; import org.prography.kagongsillok.place.application.dto.PlaceUpdateCommand; import org.prography.kagongsillok.place.application.exception.NotFoundPlaceException; -import org.prography.kagongsillok.place.domain.Link; import org.prography.kagongsillok.place.domain.Location; import org.prography.kagongsillok.place.domain.Place; import org.prography.kagongsillok.place.domain.PlaceRepository; @@ -98,7 +92,9 @@ public List searchPlacesByTags(final List reviewTagIds) { final List reviews = reviewRepository.findByReviewTagIds(reviewTagIds); final List placeIds = reviews.stream() .map(review -> review.getPlaceId()) - .collect(Collectors.toList()); + .collect(Collectors.toSet()) + .stream() + .toList(); final List places = placeRepository.findByIdIn(placeIds); return createPlaceDtos(places, reviews); diff --git a/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java b/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java index fd5ba77..f62f76d 100644 --- a/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java +++ b/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java @@ -24,14 +24,8 @@ public class ReviewTag extends AbstractRootEntity { private String tagContent; - private boolean isDeleted = Boolean.FALSE; - public ReviewTag(final String tagName, final String tagContent) { this.tagName = tagName; this.tagContent = tagContent; } - - public void delete() { - this.isDeleted = Boolean.TRUE; - } } diff --git a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java index 710c978..f3a04a5 100644 --- a/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java +++ b/src/main/java/org/prography/kagongsillok/review/infrastructure/ReviewRepositoryImpl.java @@ -2,16 +2,14 @@ import static org.prography.kagongsillok.review.domain.QReview.review; import static org.prography.kagongsillok.review.domain.QReviewTag.reviewTag; +import static org.prography.kagongsillok.review.domain.QReviewTagMapping.reviewTagMapping; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; -import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.review.domain.Review; -import org.prography.kagongsillok.review.domain.ReviewTag; import org.springframework.stereotype.Repository; @Repository @@ -38,6 +36,10 @@ public List findAllByMemberId(final Long memberId) { public List findAllByPlaceId(final Long placeId) { return queryFactory .selectFrom(review) + .leftJoin(review.tagMappings.values, reviewTagMapping) + .fetchJoin() + .leftJoin(reviewTagMapping.reviewTag, reviewTag) + .fetchJoin() .where( review.placeId.eq(placeId), isNotDeleted() @@ -50,6 +52,10 @@ public List findAllByPlaceId(final Long placeId) { public List findByReviewTagIds(final List reviewTagIds) { List allReviews = queryFactory .selectFrom(review) + .leftJoin(review.tagMappings.values, reviewTagMapping) + .fetchJoin() + .leftJoin(reviewTagMapping.reviewTag, reviewTag) + .fetchJoin() .where( isNotDeleted() ) @@ -72,6 +78,10 @@ public List findByReviewTagIds(final List reviewTagIds) { @Override public List findByPlaceIds(final List placeIds) { return queryFactory.selectFrom(review) + .leftJoin(review.tagMappings.values, reviewTagMapping) + .fetchJoin() + .leftJoin(reviewTagMapping.reviewTag, reviewTag) + .fetchJoin() .where( review.placeId.in(placeIds), isNotDeleted() diff --git a/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java b/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java index 78752ec..b04fffa 100644 --- a/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java +++ b/src/test/java/org/prography/kagongsillok/acceptance/place/PlaceAcceptanceTest.java @@ -177,8 +177,7 @@ public class PlaceAcceptanceTest extends AcceptanceTest { final var 장소_생성_요청_바디3 = 이미지_세개_링크_두개_장소_생성_요청_바디("testPlace3", -10.0, -20.0); final var 생성_장소1_ID = 장소_생성_요청(장소_생성_요청_바디1).getId(); final var 생성_장소2_ID = 장소_생성_요청(장소_생성_요청_바디2).getId(); - 장소_생성_요청(장소_생성_요청_바디2); - 장소_생성_요청(장소_생성_요청_바디3); + final var 생성_장소3_ID = 장소_생성_요청(장소_생성_요청_바디3).getId(); final var 태그_생성_요청_바디1 = 태그_생성_요청_바디("#tag1", "test tag1"); final var 태그_생성_요청_바디2 = 태그_생성_요청_바디("#tag2", "test tag2"); final var 태그_생성_요청_바디3 = 태그_생성_요청_바디("#tag3", "test tag3"); From 39ca58169d952d8412030942ca674b78ff6b5c7a Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Tue, 15 Aug 2023 15:23:21 +0900 Subject: [PATCH 07/13] =?UTF-8?q?refactor:=20review=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/CustomListUtils.java | 3 +++ .../review/application/ReviewService.java | 18 +++++++++++++----- .../review/application/dto/ReviewDto.java | 11 ++++++----- .../kagongsillok/review/domain/Review.java | 3 +++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/prography/kagongsillok/common/utils/CustomListUtils.java b/src/main/java/org/prography/kagongsillok/common/utils/CustomListUtils.java index 765f44e..d1fd410 100644 --- a/src/main/java/org/prography/kagongsillok/common/utils/CustomListUtils.java +++ b/src/main/java/org/prography/kagongsillok/common/utils/CustomListUtils.java @@ -35,6 +35,9 @@ public static boolean isEmpty(final List list) { } public static String joiningToString(final List list, final String delimiter) { + if (list.size() < 1) { + return null; + } return list.stream() .map(Object::toString) .collect(Collectors.joining(delimiter)); diff --git a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java index 517dfae..116495c 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java +++ b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java @@ -6,6 +6,8 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.common.utils.CustomListUtils; +import org.prography.kagongsillok.image.domain.Image; +import org.prography.kagongsillok.image.domain.ImageRepository; import org.prography.kagongsillok.member.application.exception.NotFoundMemberException; import org.prography.kagongsillok.member.domain.Member; import org.prography.kagongsillok.member.domain.MemberRepository; @@ -29,6 +31,7 @@ public class ReviewService { private final ReviewRepository reviewRepository; private final ReviewTagRepository reviewTagRepository; private final MemberRepository memberRepository; + private final ImageRepository imageRepository; @Transactional public ReviewDto createReview(final ReviewCreateCommand reviewCreateCommand) { @@ -43,7 +46,7 @@ public ReviewDto createReview(final ReviewCreateCommand reviewCreateCommand) { final Review savedReview = reviewRepository.save(review); - return ReviewDto.of(savedReview, member); + return ReviewDto.of(savedReview, member, getImages(review)); } public ReviewDto getReview(final Long id) { @@ -59,7 +62,7 @@ public ReviewDto getReview(final Long id) { throw new NotFoundReviewException(memberId); } - return ReviewDto.of(review, member); + return ReviewDto.of(review, member, getImages(review)); } public List getAllReviewsByMemberId(final Long memberId) { @@ -69,7 +72,8 @@ public List getAllReviewsByMemberId(final Long memberId) { for (Review review : reviews) { final Member member = memberRepository.findById(review.getMemberId()) .orElseThrow(() -> new NotFoundMemberException(review.getMemberId())); - reviewDtos.add(ReviewDto.of(review, member)); + + reviewDtos.add(ReviewDto.of(review, member, getImages(review))); } return reviewDtos; @@ -95,7 +99,7 @@ public ReviewDto updateReview(final Long id, final ReviewUpdateCommand reviewUpd final Member member = memberRepository.findById(target.getMemberId()) .orElseThrow(() -> new NotFoundMemberException(target.getMemberId())); - return ReviewDto.of(review, member); + return ReviewDto.of(review, member, getImages(review)); } @Transactional @@ -123,8 +127,12 @@ private List mappingMemberToReview(final List reviews, final .build(); } - return ReviewDto.of(review, member); + return ReviewDto.of(review, member, getImages(review)); }) .collect(Collectors.toList()); } + + private List getImages(final Review review) { + return imageRepository.findByIdIn(review.getImageIds()); + } } diff --git a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java index 04dc1ed..3f52182 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java +++ b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.prography.kagongsillok.image.domain.Image; import org.prography.kagongsillok.member.domain.Member; import org.prography.kagongsillok.review.domain.Review; import org.prography.kagongsillok.review.domain.ReviewTagMapping; @@ -23,7 +24,7 @@ public class ReviewDto { private String memberProfileUrl; private int rating; private String content; - private List imageIds; + private List images; private List tagIds; private ZonedDateTime writtenAt; @@ -36,7 +37,7 @@ public ReviewDto( final String memberProfileUrl, final int rating, final String content, - final List imageIds, + final List images, final List tagIds, final ZonedDateTime writtenAt ) { @@ -47,12 +48,12 @@ public ReviewDto( this.memberProfileUrl = memberProfileUrl; this.rating = rating; this.content = content; - this.imageIds = imageIds; + this.images = images; this.tagIds = tagIds; this.writtenAt = writtenAt; } - public static ReviewDto of(final Review review, final Member member) { + public static ReviewDto of(final Review review, final Member member, final List images) { return ReviewDto .builder() .id(review.getId()) @@ -62,7 +63,7 @@ public static ReviewDto of(final Review review, final Member member) { .memberProfileUrl(member.getProfileImageUrl()) .rating(review.getRating()) .content(review.getContent()) - .imageIds(review.getImageIds()) + .images(images) .tagIds(getTagIds(review.getTagMappings())) .writtenAt(review.getWrittenAt()) .build(); diff --git a/src/main/java/org/prography/kagongsillok/review/domain/Review.java b/src/main/java/org/prography/kagongsillok/review/domain/Review.java index 1dde26f..04c756c 100644 --- a/src/main/java/org/prography/kagongsillok/review/domain/Review.java +++ b/src/main/java/org/prography/kagongsillok/review/domain/Review.java @@ -75,6 +75,9 @@ public void update(final Review target) { } public List getImageIds() { + if (imageIds.equals(null)) { + return List.of(); + } return CustomStringUtils.splitToList(imageIds, ",", Long::valueOf); } From 4b639182a27084368647b4b70a2bee2acd61bc20 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Tue, 15 Aug 2023 15:55:06 +0900 Subject: [PATCH 08/13] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=ED=95=84=EC=88=98=20=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 리뷰 작성 시 이미지 필수였던 조건을 필수 아닌 조건으로 수정 - 리뷰 작성 시 이미지가 존재하는지 확인하는 로직 추가 --- .../exception/NotFoundImageException.java | 14 ++++++ .../image/domain/ImageRepository.java | 3 +- .../infrastructure/ImageRepositoryCustom.java | 9 ++++ .../infrastructure/ImageRepositoryImpl.java | 45 +++++++++++++++++++ .../review/application/ReviewService.java | 13 +++++- 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/prography/kagongsillok/image/application/exception/NotFoundImageException.java create mode 100644 src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryCustom.java create mode 100644 src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java diff --git a/src/main/java/org/prography/kagongsillok/image/application/exception/NotFoundImageException.java b/src/main/java/org/prography/kagongsillok/image/application/exception/NotFoundImageException.java new file mode 100644 index 0000000..2afe7a7 --- /dev/null +++ b/src/main/java/org/prography/kagongsillok/image/application/exception/NotFoundImageException.java @@ -0,0 +1,14 @@ +package org.prography.kagongsillok.image.application.exception; + +import java.util.List; +import org.prography.kagongsillok.common.exception.NotFoundException; +import org.prography.kagongsillok.common.utils.CustomListUtils; +import org.prography.kagongsillok.common.utils.CustomStringUtils; + +public final class NotFoundImageException extends NotFoundException { + + public NotFoundImageException(final List imageIds) { + super(String.format("존재하지 않는 이미지 id가 포함되어 있습니다. imageIds = %s", + CustomListUtils.joiningToString(imageIds, ","))); + } +} diff --git a/src/main/java/org/prography/kagongsillok/image/domain/ImageRepository.java b/src/main/java/org/prography/kagongsillok/image/domain/ImageRepository.java index c5e2a26..5a7a868 100644 --- a/src/main/java/org/prography/kagongsillok/image/domain/ImageRepository.java +++ b/src/main/java/org/prography/kagongsillok/image/domain/ImageRepository.java @@ -1,9 +1,10 @@ package org.prography.kagongsillok.image.domain; import java.util.List; +import org.prography.kagongsillok.image.infrastructure.ImageRepositoryCustom; import org.springframework.data.jpa.repository.JpaRepository; -public interface ImageRepository extends JpaRepository { +public interface ImageRepository extends JpaRepository, ImageRepositoryCustom { List findByIdIn(List imageIds); } diff --git a/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryCustom.java b/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryCustom.java new file mode 100644 index 0000000..2aacb9f --- /dev/null +++ b/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryCustom.java @@ -0,0 +1,9 @@ +package org.prography.kagongsillok.image.infrastructure; + +import java.util.List; + +public interface ImageRepositoryCustom { + + boolean isExistIdIn(final List imageIds); + +} diff --git a/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java b/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java new file mode 100644 index 0000000..f21a661 --- /dev/null +++ b/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java @@ -0,0 +1,45 @@ +package org.prography.kagongsillok.image.infrastructure; + +import static org.prography.kagongsillok.image.domain.QImage.image; +import static org.prography.kagongsillok.member.domain.QMember.member; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.prography.kagongsillok.image.domain.Image; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class ImageRepositoryImpl implements ImageRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public boolean isExistIdIn(final List imageIds) { + List existImageIds = queryFactory + .selectFrom(image) + .where( + isNotDeleted() + ) + .fetch() + .stream() + .map(i -> i.getId()) + .collect(Collectors.toList()); + + return imageIds.stream() + .map(imageId -> existImageIds.contains(imageId)) + .collect(Collectors.toList()) + .contains(Boolean.FALSE); + } + + private BooleanExpression idIn(final List ids) { + return image.id.in(ids); + } + + private BooleanExpression isNotDeleted() { + return image.isDeleted.eq(Boolean.FALSE); + } +} diff --git a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java index 116495c..5953251 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java +++ b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.prography.kagongsillok.common.utils.CustomListUtils; +import org.prography.kagongsillok.image.application.exception.NotFoundImageException; import org.prography.kagongsillok.image.domain.Image; import org.prography.kagongsillok.image.domain.ImageRepository; import org.prography.kagongsillok.member.application.exception.NotFoundMemberException; @@ -42,11 +43,14 @@ public ReviewDto createReview(final ReviewCreateCommand reviewCreateCommand) { final Member member = memberRepository.findById(memberId) .orElseThrow(() -> new NotFoundMemberException(memberId)); + + checkExistImage(reviewCreateCommand.getImageIds()); + final Review review = reviewCreateCommand.toEntity(member.getNickname(), reviewTagIds); final Review savedReview = reviewRepository.save(review); - return ReviewDto.of(savedReview, member, getImages(review)); + return ReviewDto.of(savedReview, member, getImages(savedReview)); } public ReviewDto getReview(final Long id) { @@ -93,6 +97,7 @@ public ReviewDto updateReview(final Long id, final ReviewUpdateCommand reviewUpd .orElseThrow(() -> new NotFoundReviewException(id)); final Map updateReviewTags = reviewTagRepository.findByPerId(reviewUpdateCommand.getReviewTagIds()); + checkExistImage(reviewUpdateCommand.getImageIds()); final Review target = reviewUpdateCommand.toEntity(updateReviewTags); review.update(target); @@ -135,4 +140,10 @@ private List mappingMemberToReview(final List reviews, final private List getImages(final Review review) { return imageRepository.findByIdIn(review.getImageIds()); } + + private void checkExistImage(final List imageIds) { + if (imageRepository.isExistIdIn(imageIds)) { + throw new NotFoundImageException(imageIds); + } + } } From 941e44cd8442bdd82aeb0bd3acbb9125b5addae3 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Tue, 15 Aug 2023 15:59:52 +0900 Subject: [PATCH 09/13] =?UTF-8?q?feat:=20=EC=9E=A5=EC=86=8C=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=EC=97=AC=EB=B6=80=20=ED=8C=90=EB=8B=A8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kagongsillok/place/application/PlaceService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java index 27beec3..0018ef2 100644 --- a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java +++ b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java @@ -3,6 +3,8 @@ import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.prography.kagongsillok.image.application.exception.NotFoundImageException; +import org.prography.kagongsillok.image.domain.ImageRepository; import org.prography.kagongsillok.place.application.dto.PlaceCreateCommand; import org.prography.kagongsillok.place.application.dto.PlaceDto; import org.prography.kagongsillok.place.application.dto.PlaceLocationAroundSearchCondition; @@ -24,9 +26,11 @@ public class PlaceService { private final PlaceRepository placeRepository; private final ReviewRepository reviewRepository; + private final ImageRepository imageRepository; @Transactional public PlaceDto createPlace(final PlaceCreateCommand placeCreateCommand) { + checkExistImage(placeCreateCommand.getImageIds()); final Place savedPlace = placeRepository.save(placeCreateCommand.toEntity()); return PlaceDto.from(savedPlace); @@ -73,6 +77,7 @@ public List searchPlacesByName(final String name) { public PlaceDto updatePlace(final Long id, final PlaceUpdateCommand updateCommand) { final Place place = placeRepository.findById(id) .orElseThrow(() -> new NotFoundPlaceException(id)); + checkExistImage(updateCommand.getImageIds()); final Place target = updateCommand.toEntity(); place.update(target); @@ -129,4 +134,10 @@ private List getReviewTagsRelatedToPlace(final List reviews) ) .collect(Collectors.toList()); } + + private void checkExistImage(final List imageIds) { + if (imageRepository.isExistIdIn(imageIds)) { + throw new NotFoundImageException(imageIds); + } + } } From e7c5d0fe28bf8cd81b8d6899375c7aba612760bc Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Tue, 15 Aug 2023 16:18:47 +0900 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=EC=97=90=20=EC=9E=A5=EC=86=8C=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/application/ReviewService.java | 9 ++++++-- .../review/application/dto/ReviewDto.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java index 5953251..2d2f663 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java +++ b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java @@ -12,6 +12,9 @@ import org.prography.kagongsillok.member.application.exception.NotFoundMemberException; import org.prography.kagongsillok.member.domain.Member; import org.prography.kagongsillok.member.domain.MemberRepository; +import org.prography.kagongsillok.place.application.exception.NotFoundPlaceException; +import org.prography.kagongsillok.place.domain.Place; +import org.prography.kagongsillok.place.domain.PlaceRepository; import org.prography.kagongsillok.review.application.dto.ReviewCreateCommand; import org.prography.kagongsillok.review.application.dto.ReviewDto; import org.prography.kagongsillok.review.application.dto.ReviewUpdateCommand; @@ -33,6 +36,7 @@ public class ReviewService { private final ReviewTagRepository reviewTagRepository; private final MemberRepository memberRepository; private final ImageRepository imageRepository; + private final PlaceRepository placeRepository; @Transactional public ReviewDto createReview(final ReviewCreateCommand reviewCreateCommand) { @@ -76,8 +80,9 @@ public List getAllReviewsByMemberId(final Long memberId) { for (Review review : reviews) { final Member member = memberRepository.findById(review.getMemberId()) .orElseThrow(() -> new NotFoundMemberException(review.getMemberId())); - - reviewDtos.add(ReviewDto.of(review, member, getImages(review))); + final Place place = placeRepository.findById(review.getPlaceId()) + .orElseThrow(() -> new NotFoundPlaceException(review.getPlaceId())); + reviewDtos.add(ReviewDto.of(review, member, getImages(review), place)); } return reviewDtos; diff --git a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java index 3f52182..30eb2a6 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java +++ b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java @@ -9,6 +9,7 @@ import lombok.NoArgsConstructor; import org.prography.kagongsillok.image.domain.Image; import org.prography.kagongsillok.member.domain.Member; +import org.prography.kagongsillok.place.domain.Place; import org.prography.kagongsillok.review.domain.Review; import org.prography.kagongsillok.review.domain.ReviewTagMapping; import org.prography.kagongsillok.review.domain.ReviewTagMappings; @@ -20,6 +21,7 @@ public class ReviewDto { private Long id; private Long memberId; private Long placeId; + private String placeName; private String memberNickName; private String memberProfileUrl; private int rating; @@ -33,6 +35,7 @@ public ReviewDto( final Long id, final Long memberId, final Long placeId, + final String placeName, final String memberNickName, final String memberProfileUrl, final int rating, @@ -44,6 +47,7 @@ public ReviewDto( this.id = id; this.memberId = memberId; this.placeId = placeId; + this.placeName = placeName; this.memberNickName = memberNickName; this.memberProfileUrl = memberProfileUrl; this.rating = rating; @@ -69,6 +73,23 @@ public static ReviewDto of(final Review review, final Member member, final List< .build(); } + public static ReviewDto of(final Review review, final Member member, final List images, final Place place) { + return ReviewDto + .builder() + .id(review.getId()) + .memberId(review.getMemberId()) + .placeId(review.getPlaceId()) + .placeName(place.getName()) + .memberNickName(review.getMemberNickName()) + .memberProfileUrl(member.getProfileImageUrl()) + .rating(review.getRating()) + .content(review.getContent()) + .images(images) + .tagIds(getTagIds(review.getTagMappings())) + .writtenAt(review.getWrittenAt()) + .build(); + } + private static List getTagIds(final ReviewTagMappings reviewTags) { List reviewTagMappings = reviewTags.getValues(); List tagIds = new ArrayList<>(); From e98267846329f01ece71a6b9706765e609098996 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Wed, 16 Aug 2023 14:30:41 +0900 Subject: [PATCH 11/13] Revert "Merge branch 'develop' into feat/search-place-by-tag" This reverts commit fff8d2db4f614c4d80c742eb8803b7ea59214fd4, reversing changes made to e7c5d0fe28bf8cd81b8d6899375c7aba612760bc. --- .../resolver/AccessTokenArgumentResolver.java | 5 -- .../AccessTokenAuthenticationException.java | 10 --- .../infrastructure/ImageRepositoryImpl.java | 1 + .../MemberRepositoryCustom.java | 2 +- .../infrastructure/MemberRepositoryImpl.java | 1 + .../review/application/ReviewService.java | 1 + .../application/dto/ReviewImageDto.java | 27 -------- .../application/dto/ReviewImageListDto.java | 23 ------- .../review/ui/ReviewV1Controller.java | 10 --- .../review/ui/dto/ReviewImageResponse.java | 25 -------- .../ui/dto/ReviewImagesInfoResponse.java | 28 --------- .../review/application/ReviewServiceTest.java | 62 ------------------- 12 files changed, 4 insertions(+), 191 deletions(-) delete mode 100644 src/main/java/org/prography/kagongsillok/common/resolver/exception/AccessTokenAuthenticationException.java delete mode 100644 src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageDto.java delete mode 100644 src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageListDto.java delete mode 100644 src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImageResponse.java delete mode 100644 src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImagesInfoResponse.java diff --git a/src/main/java/org/prography/kagongsillok/common/resolver/AccessTokenArgumentResolver.java b/src/main/java/org/prography/kagongsillok/common/resolver/AccessTokenArgumentResolver.java index 6b70744..b66773a 100644 --- a/src/main/java/org/prography/kagongsillok/common/resolver/AccessTokenArgumentResolver.java +++ b/src/main/java/org/prography/kagongsillok/common/resolver/AccessTokenArgumentResolver.java @@ -5,7 +5,6 @@ import org.prography.kagongsillok.auth.domain.dto.LoginMemberInfo; import org.prography.kagongsillok.auth.infrastructure.JwtAuthTokenProvider; import org.prography.kagongsillok.common.resolver.dto.LoginMemberDto; -import org.prography.kagongsillok.common.resolver.exception.AccessTokenAuthenticationException; import org.prography.kagongsillok.member.domain.Role; import org.springframework.core.MethodParameter; import org.springframework.stereotype.Component; @@ -32,7 +31,6 @@ public Object resolveArgument(final MethodParameter parameter, final ModelAndVie HttpServletRequest httpServletRequest = (HttpServletRequest) webRequest.getNativeRequest(); String accessToken = getAccessToken(httpServletRequest.getHeader("authorization")); - final LoginMemberInfo loginMemberInfo = jwtAuthTokenProvider.getLoginMemberByAccessToken(accessToken); final Long memberId = loginMemberInfo.getMemberId(); final Role role = loginMemberInfo.getRole(); @@ -41,9 +39,6 @@ public Object resolveArgument(final MethodParameter parameter, final ModelAndVie } private String getAccessToken(String accessTokenHeader) { - if (accessTokenHeader == null) { - throw new AccessTokenAuthenticationException(); - } return accessTokenHeader.split(" ")[1]; } } diff --git a/src/main/java/org/prography/kagongsillok/common/resolver/exception/AccessTokenAuthenticationException.java b/src/main/java/org/prography/kagongsillok/common/resolver/exception/AccessTokenAuthenticationException.java deleted file mode 100644 index b1094cc..0000000 --- a/src/main/java/org/prography/kagongsillok/common/resolver/exception/AccessTokenAuthenticationException.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prography.kagongsillok.common.resolver.exception; - -import org.prography.kagongsillok.auth.application.exception.AuthenticationException; - -public class AccessTokenAuthenticationException extends AuthenticationException { - - public AccessTokenAuthenticationException() { - super(String.format("Header에 AccessToken이 존재하지 않습니다.")); - } -} diff --git a/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java b/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java index 46d8267..f21a661 100644 --- a/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java +++ b/src/main/java/org/prography/kagongsillok/image/infrastructure/ImageRepositoryImpl.java @@ -1,6 +1,7 @@ package org.prography.kagongsillok.image.infrastructure; import static org.prography.kagongsillok.image.domain.QImage.image; +import static org.prography.kagongsillok.member.domain.QMember.member; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; diff --git a/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java index 8029304..1703293 100644 --- a/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java +++ b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryCustom.java @@ -6,5 +6,5 @@ public interface MemberRepositoryCustom { - Map findByIdIn(final List memberIds); + Map findByIdIn(List memberIds); } diff --git a/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java index df80bc0..b3ddc55 100644 --- a/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java +++ b/src/main/java/org/prography/kagongsillok/member/infrastructure/MemberRepositoryImpl.java @@ -1,6 +1,7 @@ package org.prography.kagongsillok.member.infrastructure; import static org.prography.kagongsillok.member.domain.QMember.member; +import static org.prography.kagongsillok.review.domain.QReviewTag.reviewTag; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; diff --git a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java index c2dc55f..2d2f663 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java +++ b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.prography.kagongsillok.common.utils.CustomListUtils; import org.prography.kagongsillok.image.application.exception.NotFoundImageException; import org.prography.kagongsillok.image.domain.Image; import org.prography.kagongsillok.image.domain.ImageRepository; diff --git a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageDto.java b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageDto.java deleted file mode 100644 index f8596cd..0000000 --- a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageDto.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.prography.kagongsillok.review.application.dto; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.prography.kagongsillok.image.domain.Image; -import org.prography.kagongsillok.member.domain.Member; -import org.prography.kagongsillok.review.domain.Review; - -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ReviewImageDto { - - private String imageUrl; - private String memberName; - private String memberProfileUrl; - - private ReviewImageDto(final Member member, final Image image) { - this.imageUrl = image.getUrl(); - this.memberName = member.getNickname(); - this.memberProfileUrl = member.getProfileImageUrl(); - } - - public static ReviewImageDto of(Member member, Image image) { - return new ReviewImageDto(member, image); - } -} diff --git a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageListDto.java b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageListDto.java deleted file mode 100644 index 1e2d8d6..0000000 --- a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewImageListDto.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.prography.kagongsillok.review.application.dto; - -import java.util.List; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ReviewImageListDto { - - private int totalImageCount; - private List reviewImageDtos; - - private ReviewImageListDto(final int totalImageCount, final List reviewImageDtos) { - this.totalImageCount = totalImageCount; - this.reviewImageDtos = reviewImageDtos; - } - - public static ReviewImageListDto of(final int totalImageCount, final List reviewImageDtos) { - return new ReviewImageListDto(totalImageCount, reviewImageDtos); - } -} diff --git a/src/main/java/org/prography/kagongsillok/review/ui/ReviewV1Controller.java b/src/main/java/org/prography/kagongsillok/review/ui/ReviewV1Controller.java index 4ecd4e4..a571774 100644 --- a/src/main/java/org/prography/kagongsillok/review/ui/ReviewV1Controller.java +++ b/src/main/java/org/prography/kagongsillok/review/ui/ReviewV1Controller.java @@ -5,9 +5,7 @@ import org.prography.kagongsillok.common.web.dto.CommonResponse; import org.prography.kagongsillok.review.application.ReviewService; import org.prography.kagongsillok.review.application.dto.ReviewDto; -import org.prography.kagongsillok.review.application.dto.ReviewImageListDto; import org.prography.kagongsillok.review.ui.dto.ReviewCreateRequest; -import org.prography.kagongsillok.review.ui.dto.ReviewImagesInfoResponse; import org.prography.kagongsillok.review.ui.dto.ReviewListResponse; import org.prography.kagongsillok.review.ui.dto.ReviewResponse; import org.prography.kagongsillok.review.ui.dto.ReviewUpdateRequest; @@ -76,12 +74,4 @@ public ResponseEntity deleteReview(@PathVariable("reviewId") final Long id reviewService.deleteReview(id); return ResponseEntity.ok().build(); } - - @GetMapping("/images/{placeId}") - public ResponseEntity> getPlaceReviewImages( - @PathVariable("placeId") Long placeId - ) { - final ReviewImageListDto reviewImageListDto = reviewService.getPlaceReviewImages(placeId); - return CommonResponse.success(ReviewImagesInfoResponse.from(reviewImageListDto)); - } } diff --git a/src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImageResponse.java b/src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImageResponse.java deleted file mode 100644 index e5685bc..0000000 --- a/src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImageResponse.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.prography.kagongsillok.review.ui.dto; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.prography.kagongsillok.review.application.dto.ReviewImageDto; - -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ReviewImageResponse { - - private String imageUrl; - private String memberName; - private String memberProfileUrl; - - private ReviewImageResponse(final ReviewImageDto reviewImageDto) { - this.imageUrl = reviewImageDto.getImageUrl(); - this.memberName = reviewImageDto.getMemberName(); - this.memberProfileUrl = reviewImageDto.getMemberProfileUrl(); - } - - public static ReviewImageResponse from(final ReviewImageDto reviewImageDto) { - return new ReviewImageResponse(reviewImageDto); - } -} diff --git a/src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImagesInfoResponse.java b/src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImagesInfoResponse.java deleted file mode 100644 index b5107c4..0000000 --- a/src/main/java/org/prography/kagongsillok/review/ui/dto/ReviewImagesInfoResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.prography.kagongsillok.review.ui.dto; - -import java.util.List; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.prography.kagongsillok.common.utils.CustomListUtils; -import org.prography.kagongsillok.review.application.dto.ReviewImageListDto; - -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ReviewImagesInfoResponse { - - private int totalImageCount; - private List reviewImages; - - private ReviewImagesInfoResponse(final ReviewImageListDto reviewImageListDto) { - this.totalImageCount = reviewImageListDto.getTotalImageCount(); - this.reviewImages = CustomListUtils.mapTo( - reviewImageListDto.getReviewImageDtos(), - ReviewImageResponse::from - ); - } - - public static ReviewImagesInfoResponse from(final ReviewImageListDto reviewImageListDto) { - return new ReviewImagesInfoResponse(reviewImageListDto); - } -} diff --git a/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java b/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java index 4f82a59..db7b6e4 100644 --- a/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java +++ b/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java @@ -6,14 +6,11 @@ import java.util.List; import org.junit.jupiter.api.Test; -import org.prography.kagongsillok.image.domain.Image; -import org.prography.kagongsillok.image.domain.ImageRepository; import org.prography.kagongsillok.member.domain.Member; import org.prography.kagongsillok.member.domain.MemberRepository; import org.prography.kagongsillok.member.domain.Role; import org.prography.kagongsillok.review.application.dto.ReviewCreateCommand; import org.prography.kagongsillok.review.application.dto.ReviewDto; -import org.prography.kagongsillok.review.application.dto.ReviewImageListDto; import org.prography.kagongsillok.review.application.dto.ReviewUpdateCommand; import org.prography.kagongsillok.review.application.exception.NotFoundReviewException; import org.prography.kagongsillok.review.domain.ReviewTag; @@ -35,9 +32,6 @@ public class ReviewServiceTest { @Autowired private MemberRepository memberRepository; - @Autowired - private ImageRepository imageRepository; - @Test void 리뷰를_생성한다() { final Long memberId = saveMemberAndGetMemberId(); @@ -256,52 +250,6 @@ public class ReviewServiceTest { ); } - @Test - void 장소_ID로_해당_장소_리뷰_이미지들을_조회한다() { - final Long memberId = saveMemberAndGetMemberId(); - final Long placeId = 1L; - final Long tagId1 = saveTagAndGetTagId("#tag1"); - final Long tagId2 = saveTagAndGetTagId("#tag2"); - final Long imageId1 = saveImageAndGetImageId("imageUrl1"); - final Long imageId2 = saveImageAndGetImageId("imageUrl2"); - final Long imageId3 = saveImageAndGetImageId("imageUrl3"); - final Long imageId4 = saveImageAndGetImageId("imageUrl4"); - final ReviewCreateCommand reviewCreateCommand1 = ReviewCreateCommand - .builder() - .memberId(memberId) - .placeId(placeId) - .rating(5) - .content("test review1") - .imageIds(List.of(imageId1, imageId2)) - .reviewTagIds(List.of(tagId1)) - .build(); - final ReviewCreateCommand reviewCreateCommand2 = ReviewCreateCommand - .builder() - .memberId(memberId) - .placeId(placeId) - .rating(1) - .content("test review2") - .imageIds(List.of(imageId3, imageId4)) - .reviewTagIds(List.of(tagId2)) - .build(); - reviewService.createReview(reviewCreateCommand1); - reviewService.createReview(reviewCreateCommand2); - - final ReviewImageListDto reviewImageListDto = reviewService.getPlaceReviewImages(placeId); - System.out.println(reviewImageListDto); - - assertAll( - () -> assertThat(reviewImageListDto.getReviewImageDtos().size()).isEqualTo(4), - () -> assertThat(reviewImageListDto.getReviewImageDtos()) - .extracting("imageUrl") - .containsAll(List.of("imageUrl1", "imageUrl2", "imageUrl3", "imageUrl4")), - () -> assertThat(reviewImageListDto.getReviewImageDtos()) - .extracting("memberName") - .containsAll(List.of("닉네임", "닉네임", "닉네임", "닉네임")), - () -> assertThat(reviewImageListDto.getTotalImageCount()).isEqualTo(4) - ); - } - private Long saveTagAndGetTagId(final String tagName) { final ReviewTag reviewTag1 = new ReviewTag(tagName, "test tag"); return reviewTagRepository.save(reviewTag1).getId(); @@ -315,14 +263,4 @@ private Long saveMemberAndGetMemberId() { .build(); return memberRepository.save(member).getId(); } - - private Long saveImageAndGetImageId(final String imageUrl) { - final Image image = Image.builder() - .url(imageUrl) - .width(100) - .height(100) - .extension("extension") - .build(); - return imageRepository.save(image).getId(); - } } From f3311d8baee2bb64303c799976b631496492d2f7 Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Wed, 16 Aug 2023 14:51:14 +0900 Subject: [PATCH 12/13] =?UTF-8?q?Revert=20"refactor:=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=EC=97=90=20=EC=9E=A5=EC=86=8C=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=B6=94=EA=B0=80"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e7c5d0fe28bf8cd81b8d6899375c7aba612760bc. --- .../review/application/ReviewService.java | 9 ++------ .../review/application/dto/ReviewDto.java | 21 ------------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java index 2d2f663..5953251 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java +++ b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java @@ -12,9 +12,6 @@ import org.prography.kagongsillok.member.application.exception.NotFoundMemberException; import org.prography.kagongsillok.member.domain.Member; import org.prography.kagongsillok.member.domain.MemberRepository; -import org.prography.kagongsillok.place.application.exception.NotFoundPlaceException; -import org.prography.kagongsillok.place.domain.Place; -import org.prography.kagongsillok.place.domain.PlaceRepository; import org.prography.kagongsillok.review.application.dto.ReviewCreateCommand; import org.prography.kagongsillok.review.application.dto.ReviewDto; import org.prography.kagongsillok.review.application.dto.ReviewUpdateCommand; @@ -36,7 +33,6 @@ public class ReviewService { private final ReviewTagRepository reviewTagRepository; private final MemberRepository memberRepository; private final ImageRepository imageRepository; - private final PlaceRepository placeRepository; @Transactional public ReviewDto createReview(final ReviewCreateCommand reviewCreateCommand) { @@ -80,9 +76,8 @@ public List getAllReviewsByMemberId(final Long memberId) { for (Review review : reviews) { final Member member = memberRepository.findById(review.getMemberId()) .orElseThrow(() -> new NotFoundMemberException(review.getMemberId())); - final Place place = placeRepository.findById(review.getPlaceId()) - .orElseThrow(() -> new NotFoundPlaceException(review.getPlaceId())); - reviewDtos.add(ReviewDto.of(review, member, getImages(review), place)); + + reviewDtos.add(ReviewDto.of(review, member, getImages(review))); } return reviewDtos; diff --git a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java index 30eb2a6..3f52182 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java +++ b/src/main/java/org/prography/kagongsillok/review/application/dto/ReviewDto.java @@ -9,7 +9,6 @@ import lombok.NoArgsConstructor; import org.prography.kagongsillok.image.domain.Image; import org.prography.kagongsillok.member.domain.Member; -import org.prography.kagongsillok.place.domain.Place; import org.prography.kagongsillok.review.domain.Review; import org.prography.kagongsillok.review.domain.ReviewTagMapping; import org.prography.kagongsillok.review.domain.ReviewTagMappings; @@ -21,7 +20,6 @@ public class ReviewDto { private Long id; private Long memberId; private Long placeId; - private String placeName; private String memberNickName; private String memberProfileUrl; private int rating; @@ -35,7 +33,6 @@ public ReviewDto( final Long id, final Long memberId, final Long placeId, - final String placeName, final String memberNickName, final String memberProfileUrl, final int rating, @@ -47,7 +44,6 @@ public ReviewDto( this.id = id; this.memberId = memberId; this.placeId = placeId; - this.placeName = placeName; this.memberNickName = memberNickName; this.memberProfileUrl = memberProfileUrl; this.rating = rating; @@ -73,23 +69,6 @@ public static ReviewDto of(final Review review, final Member member, final List< .build(); } - public static ReviewDto of(final Review review, final Member member, final List images, final Place place) { - return ReviewDto - .builder() - .id(review.getId()) - .memberId(review.getMemberId()) - .placeId(review.getPlaceId()) - .placeName(place.getName()) - .memberNickName(review.getMemberNickName()) - .memberProfileUrl(member.getProfileImageUrl()) - .rating(review.getRating()) - .content(review.getContent()) - .images(images) - .tagIds(getTagIds(review.getTagMappings())) - .writtenAt(review.getWrittenAt()) - .build(); - } - private static List getTagIds(final ReviewTagMappings reviewTags) { List reviewTagMappings = reviewTags.getValues(); List tagIds = new ArrayList<>(); From bf81588828229ee0716b60554f505f65a9878b9e Mon Sep 17 00:00:00 2001 From: SonMinGyu Date: Wed, 16 Aug 2023 14:58:06 +0900 Subject: [PATCH 13/13] Revert "Merge branch 'refactor/connect-rds' into feat/search-place-by-tag" This reverts commit ca8b6ebf7ea27a73fb7e1617a84e2eb65722f746, reversing changes made to f3311d8baee2bb64303c799976b631496492d2f7. --- src/main/resources/application-prod.yml | 48 ------------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/main/resources/application-prod.yml diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml deleted file mode 100644 index 0a8694e..0000000 --- a/src/main/resources/application-prod.yml +++ /dev/null @@ -1,48 +0,0 @@ -spring: - datasource: - url: jdbc:mysql://db-8th-team3.cjh70mrazv3k.ap-northeast-2.rds.amazonaws.com:3306/kagongsillok?createDatabaseIfNotExist=true - username: ${DATASOURCE_USERNAME} - password: ${DATASOURCE_PASSWORD} - driver-class-name: com.mysql.cj.jdbc.Driver - - h2: - console: - enabled: true - jpa: - properties: - hibernate: - format_sql: true - dialect: org.hibernate.dialect.MySQL8Dialect - default_batch_fetch_size: 100 - open-in-view: false - show-sql: true - hibernate: - ddl-auto: create - - redis: - host: localhost - port: 6397 - -security: - jwt: - token: - secret-key: ${JWT_SECRET_KEY} - access-token-expire-length: 3600000 # 1시간 - refresh-token-expire-length: 5184000000 # 60일 - -logging: - level: - org: - hibernate: - type: - descriptor: - sql: - BasicBinder: TRACE - config: classpath:log4j2/log4j2-develop.xml - -oauth: - kakao: - clientId: ${OAUTH_KAKAO_CLIENT_ID} - clientSecret: ${OAUTH_KAKAO_CLENT_SECRET} - authorizationServerHost: https://kauth.kakao.com - resourceServerHost: https://kapi.kakao.com