Skip to content

Commit

Permalink
Merge pull request #48 from imdangg/feat/fix
Browse files Browse the repository at this point in the history
인사이트 상세 교환 상태, 단지 목록 API 추가
  • Loading branch information
yeonkyungJoo authored Jan 19, 2025
2 parents 1c0b74e + ed401a1 commit d9189d7
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,11 +35,18 @@ public ResponseEntity<List<DistrictResponse>> listDistrict(@AuthenticationPrinci
return ResponseEntity.ok(districtResponses);
}

@GetMapping("/by-district")
public ResponseEntity<MyInsightResponse> 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<List<ApartmentComplexResponse>> listApartmentComplexByDistrict(@AuthenticationPrincipal UUID memberId,
@ModelAttribute District district) {
List<ApartmentComplexResponse> apartmentComplexResponses = insightApplicationService.listApartmentComplexByDistrict(memberId, district);
return ResponseEntity.ok(apartmentComplexResponses);
}

// 전체 (내 인사이트 + 교환한 인사이트)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "강남구")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -84,8 +84,8 @@ public List<DistrictResponse> listMyInsightDistrict(UUID memberId) {
}

@Override
public MyInsightResponse countMyInsightByDistrict(UUID memberId, District district) {
return countMyInsightByDistrictCommandHandler.countMyInsightByDistrict(memberId, district);
public List<ApartmentComplexResponse> listApartmentComplexByDistrict(UUID memberId, District district) {
return listApartmentComplexByDistrictCommandHandler.listApartmentComplexByDistrict(memberId, district);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class DetailInsightResponse {

private Integer score;
private ZonedDateTime createdAt;
private ExchangeRequestStatus exchangeRequestStatus;

public DetailInsightResponse toPreviewInsightResponse() {
return DetailInsightResponse.builder()
Expand All @@ -68,6 +70,8 @@ public DetailInsightResponse toPreviewInsightResponse() {
// .member(member)
.createdAt(createdAt)
.score(score)
// TODO - CHECK
.exchangeRequestStatus(exchangeRequestStatus)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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<ApartmentComplex> apartmentComplexes;
public class ApartmentComplexResponse {
private String apartmentComplexName;
private Long insightCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,35 @@ public DetailInsightResponse detailInsight(DetailInsightQuery detailInsightQuery

// 1. 본인의 인사이트
if (insight.getMemberId().equals(requestedBy)) {
// 교환 신청 여부 확인
Optional<ExchangeRequest> 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<ExchangeRequest> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ApartmentComplexResponse> listApartmentComplexByDistrict(UUID _memberId, District district) {
MemberId memberId = new MemberId(_memberId);
List<ApartmentComplex> 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<Object[]> results = memberSnapshotRepository.findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(memberId, district);
return results.stream()
.map(result -> ApartmentComplexResponse.builder()
.apartmentComplexName((String) result[0])
.insightCount((Long) result[1])
.build())
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -97,6 +98,8 @@ public DetailInsightResponse insightToDetailInsightResponse(Insight insight) {
.viewCount(insight.getViewCount())
.score(insight.getScore())
.createdAt(insight.getCreatedAt())
// TODO - CHECK
.exchangeRequestStatus(exchangeRequestStatus)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -36,6 +37,8 @@ public DetailInsightResponse snapshotToDetailInsightResponse(Snapshot snapshot)
.complexEnvironment(snapshot.getComplexEnvironment())
.complexFacility(snapshot.getComplexFacility())
.favorableNews(snapshot.getFavorableNews())
// TODO - CHECK
.exchangeRequestStatus(exchangeRequestStatus)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +31,7 @@ public interface InsightApplicationService {
List<ApartmentComplex> listMyVisitedApartmentComplex(UUID memberId);

List<DistrictResponse> listMyInsightDistrict(UUID memberId);
MyInsightResponse countMyInsightByDistrict(UUID memberId, District district);
List<ApartmentComplexResponse> listApartmentComplexByDistrict(UUID memberId, District district);
Page<InsightResponse> listMyInsight(ListMyInsightQuery listMyInsightQuery);

DetailInsightResponse detailInsight(DetailInsightQuery detailInsightQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public interface MemberSnapshotRepository {
Page<MemberSnapshot> findAllByMemberIdAndApartmentComplexAndSnapshotMemberId(MemberId memberId, ApartmentComplex apartmentComplex, MemberId createdBy, PageRequest pageRequest);

List<Object[]> findAllDistinctDistrictByMemberId(MemberId memberId);
List<ApartmentComplex> findAllDistinctApartmentComplexByMemberIdAndDistrict(MemberId memberId, District district);
// int countAllByMemberIdAndAddress(MemberId memberId, Address address);
List<Object[]> findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(MemberId memberId, District district);
Long[] countAllByMemberIdAndDistrict(MemberId memberId, District district);

MemberSnapshot save(MemberSnapshot memberSnapshot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Component
Expand Down Expand Up @@ -65,10 +64,8 @@ public List<Object[]> findAllDistinctDistrictByMemberId(MemberId memberId) {
}

@Override
public List<ApartmentComplex> 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<Object[]> findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(MemberId memberId, District district) {
return memberSnapshotJpaRepository.findAllDistinctApartmentComplexAndInsightCountByMemberIdAndDistrict(memberId.getValue().toString(), district.getSiDo(), district.getSiGunGu(), district.getEupMyeonDong());
}

@Override
Expand Down
Loading

0 comments on commit d9189d7

Please sign in to comment.