diff --git a/insight-service/insight-application/src/main/java/com/project/imdang/insight/service/application/rest/MyInsightController.java b/insight-service/insight-application/src/main/java/com/project/imdang/insight/service/application/rest/MyInsightController.java index 05b3c94..edb1104 100644 --- a/insight-service/insight-application/src/main/java/com/project/imdang/insight/service/application/rest/MyInsightController.java +++ b/insight-service/insight-application/src/main/java/com/project/imdang/insight/service/application/rest/MyInsightController.java @@ -1,9 +1,9 @@ package com.project.imdang.insight.service.application.rest; +import com.project.imdang.insight.service.domain.dto.insight.list.ApartmentComplexResponse; import com.project.imdang.insight.service.domain.dto.insight.list.DistrictResponse; import com.project.imdang.insight.service.domain.dto.insight.list.InsightResponse; import com.project.imdang.insight.service.domain.dto.insight.list.ListMyInsightQuery; -import com.project.imdang.insight.service.domain.dto.insight.list.MyInsightResponse; import com.project.imdang.insight.service.domain.ports.input.service.InsightApplicationService; import com.project.imdang.insight.service.domain.valueobject.District; import lombok.RequiredArgsConstructor; @@ -35,11 +35,18 @@ public ResponseEntity> listDistrict(@AuthenticationPrinci return ResponseEntity.ok(districtResponses); } - @GetMapping("/by-district") - public ResponseEntity countByDistrict(@AuthenticationPrincipal UUID memberId, - @ModelAttribute District district) { - MyInsightResponse myInsightResponse = insightApplicationService.countMyInsightByDistrict(memberId, district); - return ResponseEntity.ok(myInsightResponse); + // '단지별 보기' 클릭 시, 자치구별 단지-인사이트 개수 목록 API + /* + { + "apartmentComplexName": "신뇬현 더 센트럴 푸르지오", + "insightCount": 12 + } + */ + @GetMapping("/by-district/apartment-complexes") + public ResponseEntity> listApartmentComplexByDistrict(@AuthenticationPrincipal UUID memberId, + @ModelAttribute District district) { + List apartmentComplexResponses = insightApplicationService.listApartmentComplexByDistrict(memberId, district); + return ResponseEntity.ok(apartmentComplexResponses); } // 전체 (내 인사이트 + 교환한 인사이트) diff --git a/insight-service/insight-container/src/test/java/com/project/imdang/insight/service/application/rest/MyInsightControllerTest.java b/insight-service/insight-container/src/test/java/com/project/imdang/insight/service/application/rest/MyInsightControllerTest.java index c18e7ea..dc53f5f 100644 --- a/insight-service/insight-container/src/test/java/com/project/imdang/insight/service/application/rest/MyInsightControllerTest.java +++ b/insight-service/insight-container/src/test/java/com/project/imdang/insight/service/application/rest/MyInsightControllerTest.java @@ -59,8 +59,8 @@ void listDistrict() throws Exception { } @Test - void countByDistrict() throws Exception { - mockMvc.perform(get("/my-insights/by-district") + void listApartmentComplexByDistrict() throws Exception { + mockMvc.perform(get("/my-insights/by-district/apartment-complexes") .header("Authorization", "Bearer " + requestMemberToken) .param("siDo", "서울시") .param("siGunGu", "강남구") diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/InsightApplicationServiceImpl.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/InsightApplicationServiceImpl.java index 35e35b5..32cf55a 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/InsightApplicationServiceImpl.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/InsightApplicationServiceImpl.java @@ -8,25 +8,25 @@ import com.project.imdang.insight.service.domain.dto.insight.delete.DeleteInsightResponse; import com.project.imdang.insight.service.domain.dto.insight.detail.DetailInsightQuery; import com.project.imdang.insight.service.domain.dto.insight.detail.DetailInsightResponse; +import com.project.imdang.insight.service.domain.dto.insight.list.ApartmentComplexResponse; import com.project.imdang.insight.service.domain.dto.insight.list.DistrictResponse; import com.project.imdang.insight.service.domain.dto.insight.list.InsightResponse; import com.project.imdang.insight.service.domain.dto.insight.list.ListInsightByApartmentComplexQuery; import com.project.imdang.insight.service.domain.dto.insight.list.ListInsightQuery; import com.project.imdang.insight.service.domain.dto.insight.list.ListMyInsightQuery; -import com.project.imdang.insight.service.domain.dto.insight.list.MyInsightResponse; import com.project.imdang.insight.service.domain.dto.insight.recommend.RecommendInsightCommand; import com.project.imdang.insight.service.domain.dto.insight.recommend.RecommendInsightResponse; import com.project.imdang.insight.service.domain.dto.insight.update.UpdateInsightCommand; import com.project.imdang.insight.service.domain.dto.insight.update.UpdateInsightResponse; import com.project.imdang.insight.service.domain.handler.insight.AccuseInsightCommandHandler; -import com.project.imdang.insight.service.domain.handler.insight.CountMyInsightByDistrictCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.CreateInsightCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.DeleteInsightCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.DetailInsightCommandHandler; +import com.project.imdang.insight.service.domain.handler.insight.ListApartmentComplexByDistrictCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.ListInsightByApartmentComplexCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.ListInsightCommandHandler; -import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightDistrictCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightCommandHandler; +import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightDistrictCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.ListMyVisitedApartmentComplexCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.RecommendInsightCommandHandler; import com.project.imdang.insight.service.domain.handler.insight.UpdateInsightCommandHandler; @@ -52,7 +52,7 @@ public class InsightApplicationServiceImpl implements InsightApplicationService private final ListMyInsightDistrictCommandHandler listMyInsightDistrictCommandHandler; - private final CountMyInsightByDistrictCommandHandler countMyInsightByDistrictCommandHandler; + private final ListApartmentComplexByDistrictCommandHandler listApartmentComplexByDistrictCommandHandler; private final ListMyInsightCommandHandler listMyInsightCommandHandler; private final DetailInsightCommandHandler detailInsightCommandHandler; @@ -84,8 +84,8 @@ public List listMyInsightDistrict(UUID memberId) { } @Override - public MyInsightResponse countMyInsightByDistrict(UUID memberId, District district) { - return countMyInsightByDistrictCommandHandler.countMyInsightByDistrict(memberId, district); + public List listApartmentComplexByDistrict(UUID memberId, District district) { + return listApartmentComplexByDistrictCommandHandler.listApartmentComplexByDistrict(memberId, district); } @Override diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/detail/DetailInsightResponse.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/detail/DetailInsightResponse.java index c98f447..e9e5dcf 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/detail/DetailInsightResponse.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/detail/DetailInsightResponse.java @@ -5,6 +5,7 @@ import com.project.imdang.insight.service.domain.valueobject.ApartmentComplex; import com.project.imdang.insight.service.domain.valueobject.ComplexEnvironment; import com.project.imdang.insight.service.domain.valueobject.ComplexFacility; +import com.project.imdang.insight.service.domain.valueobject.ExchangeRequestStatus; import com.project.imdang.insight.service.domain.valueobject.FavorableNews; import com.project.imdang.insight.service.domain.valueobject.Infra; import com.project.imdang.insight.service.domain.valueobject.VisitMethod; @@ -54,6 +55,7 @@ public class DetailInsightResponse { private Integer score; private ZonedDateTime createdAt; + private ExchangeRequestStatus exchangeRequestStatus; public DetailInsightResponse toPreviewInsightResponse() { return DetailInsightResponse.builder() @@ -68,6 +70,8 @@ public DetailInsightResponse toPreviewInsightResponse() { // .member(member) .createdAt(createdAt) .score(score) + // TODO - CHECK + .exchangeRequestStatus(exchangeRequestStatus) .build(); } } diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/list/MyInsightResponse.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/list/ApartmentComplexResponse.java similarity index 58% rename from insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/list/MyInsightResponse.java rename to insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/list/ApartmentComplexResponse.java index 4b4a1cf..d9477d8 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/list/MyInsightResponse.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/dto/insight/list/ApartmentComplexResponse.java @@ -1,20 +1,16 @@ package com.project.imdang.insight.service.domain.dto.insight.list; -import com.project.imdang.insight.service.domain.valueobject.ApartmentComplex; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.List; - @Builder @AllArgsConstructor @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MyInsightResponse { -// private int apartmentComplexCount; - private List apartmentComplexes; +public class ApartmentComplexResponse { + private String apartmentComplexName; private Long insightCount; } diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/DetailInsightCommandHandler.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/DetailInsightCommandHandler.java index be55950..fa5ced0 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/DetailInsightCommandHandler.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/DetailInsightCommandHandler.java @@ -59,24 +59,35 @@ public DetailInsightResponse detailInsight(DetailInsightQuery detailInsightQuery // 1. 본인의 인사이트 if (insight.getMemberId().equals(requestedBy)) { + // 교환 신청 여부 확인 + Optional optional = + exchangeRequestRepository.findByRequestMemberIdAndRequestedInsightId(requestedBy, insightId); + ExchangeRequestStatus exchangeRequestStatus = optional.map(ExchangeRequest::getStatus).orElse(null); // TODO - CHECK : OR snapshotRepository - return insightDataMapper.insightToDetailInsightResponse(insight); + return insightDataMapper.insightToDetailInsightResponse(insight, exchangeRequestStatus); } else { - // 2. 교환 여부 확인 + // 2. 교환 신청 여부 확인 Optional optional = - exchangeRequestRepository.findByRequestMemberIdAndRequestedInsightIdAndExchangeRequestStatus(requestedBy, insightId, ExchangeRequestStatus.ACCEPTED); + exchangeRequestRepository.findByRequestMemberIdAndRequestedInsightId(requestedBy, insightId); if (optional.isPresent()) { - // 2-1. 교환 O + // 2-1. 교환 신청 O ExchangeRequest exchangeRequest = optional.get(); - SnapshotId snapshotId = exchangeRequest.getRequestedSnapshotId(); - Snapshot snapshot = snapshotRepository.findById(snapshotId) - .orElseThrow(() -> new SnapshotNotFoundException(snapshotId)); - return snapshotDataMapper.snapshotToDetailInsightResponse(snapshot); + + if (ExchangeRequestStatus.ACCEPTED.equals(exchangeRequest.getStatus())) { + SnapshotId snapshotId = exchangeRequest.getRequestedSnapshotId(); + Snapshot snapshot = snapshotRepository.findById(snapshotId) + .orElseThrow(() -> new SnapshotNotFoundException(snapshotId)); + return snapshotDataMapper.snapshotToDetailInsightResponse(snapshot, exchangeRequest.getStatus()); + } else { + // PENDING, REJECTED + return insightDataMapper.insightToDetailInsightResponse(insight, exchangeRequest.getStatus()) + .toPreviewInsightResponse(); + } } else { - // 2-2. 교환 X - return insightDataMapper.insightToDetailInsightResponse(insight) + // 2-2. 교환 신청 X + return insightDataMapper.insightToDetailInsightResponse(insight, null) .toPreviewInsightResponse(); } } diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/CountMyInsightByDistrictCommandHandler.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/ListApartmentComplexByDistrictCommandHandler.java similarity index 51% rename from insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/CountMyInsightByDistrictCommandHandler.java rename to insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/ListApartmentComplexByDistrictCommandHandler.java index 3e2cae6..8f5a61b 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/CountMyInsightByDistrictCommandHandler.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/handler/insight/ListApartmentComplexByDistrictCommandHandler.java @@ -1,9 +1,8 @@ package com.project.imdang.insight.service.domain.handler.insight; import com.project.imdang.domain.valueobject.MemberId; -import com.project.imdang.insight.service.domain.dto.insight.list.MyInsightResponse; +import com.project.imdang.insight.service.domain.dto.insight.list.ApartmentComplexResponse; import com.project.imdang.insight.service.domain.ports.output.repository.MemberSnapshotRepository; -import com.project.imdang.insight.service.domain.valueobject.ApartmentComplex; import com.project.imdang.insight.service.domain.valueobject.District; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -12,24 +11,24 @@ import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; @Slf4j @RequiredArgsConstructor @Component -public class CountMyInsightByDistrictCommandHandler { +public class ListApartmentComplexByDistrictCommandHandler { private final MemberSnapshotRepository memberSnapshotRepository; @Transactional(readOnly = true) - public MyInsightResponse countMyInsightByDistrict(UUID _memberId, District district) { + public List listApartmentComplexByDistrict(UUID _memberId, District district) { MemberId memberId = new MemberId(_memberId); - List apartmentComplexes = memberSnapshotRepository.findAllDistinctApartmentComplexByMemberIdAndDistrict(memberId, district); - Long[] counts = memberSnapshotRepository.countAllByMemberIdAndDistrict(memberId, district); -// Long apartmentComplexCount = counts[0]; - Long insightCount = counts[1]; - return MyInsightResponse.builder() - .apartmentComplexes(apartmentComplexes) - .insightCount(insightCount) - .build(); + List results = memberSnapshotRepository.findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(memberId, district); + return results.stream() + .map(result -> ApartmentComplexResponse.builder() + .apartmentComplexName((String) result[0]) + .insightCount((Long) result[1]) + .build()) + .collect(Collectors.toList()); } } diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/InsightDataMapper.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/InsightDataMapper.java index 17d9a2d..6f626fb 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/InsightDataMapper.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/InsightDataMapper.java @@ -10,6 +10,7 @@ import com.project.imdang.insight.service.domain.dto.insight.recommend.RecommendInsightResponse; import com.project.imdang.insight.service.domain.dto.insight.update.UpdateInsightResponse; import com.project.imdang.insight.service.domain.entity.Insight; +import com.project.imdang.insight.service.domain.valueobject.ExchangeRequestStatus; import org.springframework.stereotype.Component; @Component @@ -75,7 +76,7 @@ public RecommendInsightResponse insightToRecommendInsightResponse(Insight insigh .build(); } - public DetailInsightResponse insightToDetailInsightResponse(Insight insight) { + public DetailInsightResponse insightToDetailInsightResponse(Insight insight, ExchangeRequestStatus exchangeRequestStatus) { return DetailInsightResponse.builder() .memberId(insight.getMemberId().getValue()) .insightId(insight.getId().getValue()) @@ -97,6 +98,8 @@ public DetailInsightResponse insightToDetailInsightResponse(Insight insight) { .viewCount(insight.getViewCount()) .score(insight.getScore()) .createdAt(insight.getCreatedAt()) + // TODO - CHECK + .exchangeRequestStatus(exchangeRequestStatus) .build(); } } diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/SnapshotDataMapper.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/SnapshotDataMapper.java index 4aa41e1..41e46a3 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/SnapshotDataMapper.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/mapper/SnapshotDataMapper.java @@ -3,6 +3,7 @@ import com.project.imdang.insight.service.domain.dto.insight.detail.DetailInsightResponse; import com.project.imdang.insight.service.domain.dto.insight.list.InsightResponse; import com.project.imdang.insight.service.domain.entity.Snapshot; +import com.project.imdang.insight.service.domain.valueobject.ExchangeRequestStatus; import org.springframework.stereotype.Component; @Component @@ -18,7 +19,7 @@ public InsightResponse snapshotToInsightResponse(Snapshot snapshot) { .build(); } - public DetailInsightResponse snapshotToDetailInsightResponse(Snapshot snapshot) { + public DetailInsightResponse snapshotToDetailInsightResponse(Snapshot snapshot, ExchangeRequestStatus exchangeRequestStatus) { return DetailInsightResponse.builder() .snapshotId(snapshot.getId().getValue()) .memberId(snapshot.getMemberId().getValue()) @@ -36,6 +37,8 @@ public DetailInsightResponse snapshotToDetailInsightResponse(Snapshot snapshot) .complexEnvironment(snapshot.getComplexEnvironment()) .complexFacility(snapshot.getComplexFacility()) .favorableNews(snapshot.getFavorableNews()) + // TODO - CHECK + .exchangeRequestStatus(exchangeRequestStatus) .build(); } } diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/input/service/InsightApplicationService.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/input/service/InsightApplicationService.java index e05697f..19100ef 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/input/service/InsightApplicationService.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/input/service/InsightApplicationService.java @@ -13,7 +13,7 @@ import com.project.imdang.insight.service.domain.dto.insight.list.ListInsightByApartmentComplexQuery; import com.project.imdang.insight.service.domain.dto.insight.list.ListInsightQuery; import com.project.imdang.insight.service.domain.dto.insight.list.ListMyInsightQuery; -import com.project.imdang.insight.service.domain.dto.insight.list.MyInsightResponse; +import com.project.imdang.insight.service.domain.dto.insight.list.ApartmentComplexResponse; import com.project.imdang.insight.service.domain.dto.insight.recommend.RecommendInsightCommand; import com.project.imdang.insight.service.domain.dto.insight.recommend.RecommendInsightResponse; import com.project.imdang.insight.service.domain.dto.insight.update.UpdateInsightCommand; @@ -31,7 +31,7 @@ public interface InsightApplicationService { List listMyVisitedApartmentComplex(UUID memberId); List listMyInsightDistrict(UUID memberId); - MyInsightResponse countMyInsightByDistrict(UUID memberId, District district); + List listApartmentComplexByDistrict(UUID memberId, District district); Page listMyInsight(ListMyInsightQuery listMyInsightQuery); DetailInsightResponse detailInsight(DetailInsightQuery detailInsightQuery); diff --git a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/output/repository/MemberSnapshotRepository.java b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/output/repository/MemberSnapshotRepository.java index 3150962..c0b746b 100644 --- a/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/output/repository/MemberSnapshotRepository.java +++ b/insight-service/insight-domain/insight-application-service/src/main/java/com/project/imdang/insight/service/domain/ports/output/repository/MemberSnapshotRepository.java @@ -21,8 +21,7 @@ public interface MemberSnapshotRepository { Page findAllByMemberIdAndApartmentComplexAndSnapshotMemberId(MemberId memberId, ApartmentComplex apartmentComplex, MemberId createdBy, PageRequest pageRequest); List findAllDistinctDistrictByMemberId(MemberId memberId); - List findAllDistinctApartmentComplexByMemberIdAndDistrict(MemberId memberId, District district); -// int countAllByMemberIdAndAddress(MemberId memberId, Address address); + List findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(MemberId memberId, District district); Long[] countAllByMemberIdAndDistrict(MemberId memberId, District district); MemberSnapshot save(MemberSnapshot memberSnapshot); diff --git a/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/adapter/MemberSnapshotRepositoryImpl.java b/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/adapter/MemberSnapshotRepositoryImpl.java index 4c3d506..bce0731 100644 --- a/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/adapter/MemberSnapshotRepositoryImpl.java +++ b/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/adapter/MemberSnapshotRepositoryImpl.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; @RequiredArgsConstructor @Component @@ -65,10 +64,8 @@ public List findAllDistinctDistrictByMemberId(MemberId memberId) { } @Override - public List findAllDistinctApartmentComplexByMemberIdAndDistrict(MemberId memberId, District district) { - return memberSnapshotJpaRepository.findAllDistinctApartmentComplexByMemberIdAndDistrict(memberId.getValue().toString(), district.getSiDo(), district.getSiGunGu(), district.getEupMyeonDong()).stream() - .map(ApartmentComplex::new) - .collect(Collectors.toList()); + public List findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(MemberId memberId, District district) { + return memberSnapshotJpaRepository.findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(memberId.getValue().toString(), district.getSiDo(), district.getSiGunGu(), district.getEupMyeonDong()); } @Override diff --git a/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/repository/MemberSnapshotJpaRepository.java b/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/repository/MemberSnapshotJpaRepository.java index ff00800..74e9667 100644 --- a/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/repository/MemberSnapshotJpaRepository.java +++ b/insight-service/insight-persistence/src/main/java/com/project/imdang/insight/service/persistence/insight/repository/MemberSnapshotJpaRepository.java @@ -53,15 +53,12 @@ public interface MemberSnapshotJpaRepository extends JpaRepository findAllDistinctDistrictByMemberId(String memberId); - @Query(value = "select distinct s.complex_name from member_snapshot ms inner join snapshot s on ms.snapshot_id = s.id " + - "where ms.member_id = :memberId and s.address_si_do = :siDo and s.address_si_gun_gu = :siGunGu and s.address_eup_myeon_dong = :eupMyeonDong", + @Query(value = "select s.complex_name, count(*) from member_snapshot ms inner join snapshot s on ms.snapshot_id = s.id " + + "where ms.member_id = :memberId and s.address_si_do = :siDo and s.address_si_gun_gu = :siGunGu and s.address_eup_myeon_dong = :eupMyeonDong " + + "group by s.complex_name", nativeQuery = true) - List findAllDistinctApartmentComplexByMemberIdAndDistrict(String memberId, String siDo, String siGunGu, String eupMyeonDong); + List findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(String memberId, String siDo, String siGunGu, String eupMyeonDong); -// @Query(value = "select count(distinct s.complex_name) from member_snapshot ms inner join snapshot s on ms.snapshot_id = s.id " + -// "where ms.member_id = :memberId and s.address_si_do = :siDo and s.address_si_gun_gu = :siGunGu and s.address_eup_myeon_dong = :eupMyeonDong ", -// nativeQuery = true) -// int countAllDistinctApartmentComplexByMemberIdAndDistinct(String memberId, String siDo, String siGunGu, String eupMyeonDong); @Query(value = "select count(distinct s.complex_name) as apartment_complex_count, count(*) as insight_count from member_snapshot ms " + "inner join snapshot s on ms.snapshot_id = s.id " + "where ms.member_id = :memberId and s.address_si_do = :siDo and s.address_si_gun_gu = :siGunGu and s.address_eup_myeon_dong = :eupMyeonDong ",