Skip to content

Commit

Permalink
Merge pull request #47 from imdangg/feat/fix
Browse files Browse the repository at this point in the history
위/경도 추가, District로 변환
  • Loading branch information
yeonkyungJoo authored Jan 19, 2025
2 parents 6d04611 + 2d0f2db commit 1c0b74e
Show file tree
Hide file tree
Showing 22 changed files with 225 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.project.imdang.insight.service.application.rest;

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.Address;
import com.project.imdang.insight.service.domain.valueobject.District;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand All @@ -27,16 +28,17 @@ public class MyInsightController {
// 보관함
private final InsightApplicationService insightApplicationService;

@GetMapping("/addresses")
public ResponseEntity<List<Address>> listAddress(@AuthenticationPrincipal UUID memberId) {
List<Address> addresses = insightApplicationService.listMyInsightAddress(memberId);
return ResponseEntity.ok(addresses);
// 보관중인 인사이트 자치구 목록 API
@GetMapping("/districts")
public ResponseEntity<List<DistrictResponse>> listDistrict(@AuthenticationPrincipal UUID memberId) {
List<DistrictResponse> districtResponses = insightApplicationService.listMyInsightDistrict(memberId);
return ResponseEntity.ok(districtResponses);
}

@GetMapping("/by-address")
public ResponseEntity<MyInsightResponse> countByAddress(@AuthenticationPrincipal UUID memberId,
@ModelAttribute Address address) {
MyInsightResponse myInsightResponse = insightApplicationService.countMyInsightByAddress(memberId, address);
@GetMapping("/by-district")
public ResponseEntity<MyInsightResponse> countByDistrict(@AuthenticationPrincipal UUID memberId,
@ModelAttribute District district) {
MyInsightResponse myInsightResponse = insightApplicationService.countMyInsightByDistrict(memberId, district);
return ResponseEntity.ok(myInsightResponse);
}

Expand All @@ -45,18 +47,18 @@ public ResponseEntity<MyInsightResponse> countByAddress(@AuthenticationPrincipal
// + 단지별 보기
@GetMapping
public ResponseEntity<Page<InsightResponse>> list(@AuthenticationPrincipal UUID memberId,
@RequestParam(name = "address") Address address,
@ModelAttribute District district,
@RequestParam(name = "apartmentComplexName", required = false) String apartmentComplexName,
@RequestParam(name = "onlyMine", defaultValue = "FALSE") Boolean onlyMine,
// TODO - PagingQuery
@RequestParam(name = "pageNumber", defaultValue = "0") Integer pageNumber,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "direction", defaultValue = "DESC") String direction,
@RequestParam(name = "properties", defaultValue = "createdAt") String[] properties) {
@RequestParam(name = "properties", defaultValue = "created_at") String[] properties) {

ListMyInsightQuery listMyInsightQuery = ListMyInsightQuery.builder()
.memberId(memberId)
.address(address)
.district(district)
.apartmentComplexName(apartmentComplexName)
.onlyMine(onlyMine)
.pageNumber(pageNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.project.imdang.insight.service.domain.dto.exchange.reject.RejectExchangeRequestCommand;
import com.project.imdang.insight.service.domain.dto.exchange.request.RequestExchangeInsightCommand;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand Down Expand Up @@ -68,9 +69,9 @@ public void request() throws Exception {
.andExpect(jsonPath("$.exchangeRequestId", notNullValue()));
}

// @Test
@Test
public void request_with_coupon() throws Exception {
UUID insightId = UUID.fromString("111512ab-a7b6-43f9-bd61-16ee2cded7d9");
UUID insightId = UUID.fromString("f509ce55-a67a-4c97-8846-0dee0c754c38");
RequestExchangeInsightCommand requestExchangeInsightCommand
= new TestData(insightId).requestExchangeInsightCommand(null, 1L) ;

Expand All @@ -82,10 +83,10 @@ public void request_with_coupon() throws Exception {
.andExpect(jsonPath("$.exchangeRequestId", notNullValue()));
}

// @Test
@Test
public void accept() throws Exception {
AcceptExchangeRequestCommand acceptExchangeRequestCommand = AcceptExchangeRequestCommand.builder()
.exchangeRequestId(UUID.fromString("a4c9a9e8-2577-4a4d-9bf1-3f76687336dd"))
.exchangeRequestId(UUID.fromString("61ec70ab-2baf-47b1-80a6-c5d551bfccc9"))
.requestedMemberId(requestedMemberId)
.build();
mockMvc.perform(post("/exchanges/accept")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void updateInsight() throws Exception {

@Test
void recommendInsight() throws Exception {
UUID insightId = UUID.fromString("b434b945-5e39-4439-b0eb-ff953b777118");
UUID insightId = UUID.fromString("f509ce55-a67a-4c97-8846-0dee0c754c38");
RecommendInsightCommand recommendInsightCommand = new TestData(insightId).recommendInsightCommand();
mockMvc.perform(post("/insights/recommend")
.header("Authorization", "Bearer " + requestMemberToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void init() {
}

@Test
void listAddress() throws Exception {
mockMvc.perform(get("/my-insights/addresses")
void listDistrict() throws Exception {
mockMvc.perform(get("/my-insights/districts")
.header("Authorization", "Bearer " + requestMemberToken)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
Expand All @@ -59,8 +59,8 @@ void listAddress() throws Exception {
}

@Test
void countByAddress() throws Exception {
mockMvc.perform(get("/my-insights/by-address")
void countByDistrict() throws Exception {
mockMvc.perform(get("/my-insights/by-district")
.header("Authorization", "Bearer " + requestMemberToken)
.param("siDo", "서울시")
.param("siGunGu", "강남구")
Expand All @@ -75,7 +75,10 @@ void countByAddress() throws Exception {
void list() throws Exception {
mockMvc.perform(get("/my-insights")
.header("Authorization", "Bearer " + requestMemberToken)
.param("onlyMine", "TRUE")
// .param("onlyMine", "TRUE")
.param("siDo", "서울시")
.param("siGunGu", "강남구")
.param("eupMyeonDong", "신논현동")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
// .andExpect(jsonPath("$.content.length()").value(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.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;
Expand All @@ -18,20 +19,20 @@
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.CountMyInsightByAddressCommandHandler;
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.ListInsightByApartmentComplexCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListInsightCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightAddressCommandHandler;
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.ListMyVisitedApartmentComplexCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.RecommendInsightCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.UpdateInsightCommandHandler;
import com.project.imdang.insight.service.domain.ports.input.service.InsightApplicationService;
import com.project.imdang.insight.service.domain.valueobject.Address;
import com.project.imdang.insight.service.domain.valueobject.ApartmentComplex;
import com.project.imdang.insight.service.domain.valueobject.District;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
Expand All @@ -50,8 +51,8 @@ public class InsightApplicationServiceImpl implements InsightApplicationService
private final ListMyVisitedApartmentComplexCommandHandler listMyVisitedApartmentComplexCommandHandler;


private final ListMyInsightAddressCommandHandler listMyInsightAddressCommandHandler;
private final CountMyInsightByAddressCommandHandler countMyInsightByAddressCommandHandler;
private final ListMyInsightDistrictCommandHandler listMyInsightDistrictCommandHandler;
private final CountMyInsightByDistrictCommandHandler countMyInsightByDistrictCommandHandler;
private final ListMyInsightCommandHandler listMyInsightCommandHandler;

private final DetailInsightCommandHandler detailInsightCommandHandler;
Expand All @@ -78,13 +79,13 @@ public List<ApartmentComplex> listMyVisitedApartmentComplex(UUID memberId) {
}

@Override
public List<Address> listMyInsightAddress(UUID memberId) {
return listMyInsightAddressCommandHandler.listMyInsightAddress(memberId);
public List<DistrictResponse> listMyInsightDistrict(UUID memberId) {
return listMyInsightDistrictCommandHandler.listMyInsightDistrict(memberId);
}

@Override
public MyInsightResponse countMyInsightByAddress(UUID memberId, Address address) {
return countMyInsightByAddressCommandHandler.countMyInsightByAddress(memberId, address);
public MyInsightResponse countMyInsightByDistrict(UUID memberId, District district) {
return countMyInsightByDistrictCommandHandler.countMyInsightByDistrict(memberId, district);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.project.imdang.insight.service.domain.dto.insight.list;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@AllArgsConstructor
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DistrictResponse {
private String siDo; // 시/도 (예: 서울특별시)
private String siGunGu; // 시/군/구 (예: 종로구)
private String eupMyeonDong; // 읍/면/동 (예: 효제동)

private Long apartmentComplexCount;
private Long insightCount;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.project.imdang.insight.service.domain.dto.insight.list;

import com.project.imdang.insight.service.domain.valueobject.Address;
import com.project.imdang.insight.service.domain.valueobject.District;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -17,7 +17,7 @@ public class ListMyInsightQuery {
// extends PagingQuery {
// @Setter
private UUID memberId;
private Address address;
private District district;
private String apartmentComplexName;

private Boolean onlyMine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
public class MyInsightResponse {
// private int apartmentComplexCount;
private List<ApartmentComplex> apartmentComplexes;
private int insightCount;
private Long insightCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
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.ports.output.repository.MemberSnapshotRepository;
import com.project.imdang.insight.service.domain.valueobject.Address;
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;
import org.springframework.stereotype.Component;
Expand All @@ -16,15 +16,17 @@
@Slf4j
@RequiredArgsConstructor
@Component
public class CountMyInsightByAddressCommandHandler {
public class CountMyInsightByDistrictCommandHandler {

private final MemberSnapshotRepository memberSnapshotRepository;

@Transactional(readOnly = true)
public MyInsightResponse countMyInsightByAddress(UUID _memberId, Address address) {
public MyInsightResponse countMyInsightByDistrict(UUID _memberId, District district) {
MemberId memberId = new MemberId(_memberId);
List<ApartmentComplex> apartmentComplexes = memberSnapshotRepository.findAllDistinctApartmentComplexByMemberIdAndAddress(memberId, address);
int insightCount = memberSnapshotRepository.countAllByMemberIdAndAddress(memberId, address);
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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public Page<InsightResponse> listMyInsight(ListMyInsightQuery listMyInsightQuery
} else {

if (Boolean.TRUE.equals(onlyMine)) {
paged = memberSnapshotRepository.findAllByMemberIdAndAddressAndSnapshotMemberId(memberId, listMyInsightQuery.getAddress(), memberId, pageRequest);
paged = memberSnapshotRepository.findAllByMemberIdAndDistrictAndSnapshotMemberId(memberId, listMyInsightQuery.getDistrict(), memberId, pageRequest);
} else {
paged = memberSnapshotRepository.findAllByMemberIdAndAddress(memberId, listMyInsightQuery.getAddress(), pageRequest);
paged = memberSnapshotRepository.findAllByMemberIdAndDistrict(memberId, listMyInsightQuery.getDistrict(), pageRequest);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.DistrictResponse;
import com.project.imdang.insight.service.domain.ports.output.repository.MemberSnapshotRepository;
import com.project.imdang.insight.service.domain.valueobject.District;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

@Slf4j
@RequiredArgsConstructor
@Component
public class ListMyInsightDistrictCommandHandler {

private final MemberSnapshotRepository memberSnapshotRepository;

@Transactional(readOnly = true)
public List<DistrictResponse> listMyInsightDistrict(UUID _memberId) {
MemberId memberId = new MemberId(_memberId);
List<Object[]> districts = memberSnapshotRepository.findAllDistinctDistrictByMemberId(memberId);

// TODO - 쿼리 개선
return districts.stream()
.map(_district -> {
String siDo = (String) _district[0];
String siGunGu = (String) _district[1];
String eupMyeonDong = (String) _district[2];
District district = new District(siDo, siGunGu, eupMyeonDong);
Long[] result = memberSnapshotRepository.countAllByMemberIdAndDistrict(memberId, district);

Long apartmentComplexCount = result[0];
Long insightCount = result[1];
return DistrictResponse.builder()
.siDo(siDo)
.siGunGu(siGunGu)
.eupMyeonDong(eupMyeonDong)
.apartmentComplexCount(apartmentComplexCount)
.insightCount(insightCount)
.build();
})
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 1c0b74e

Please sign in to comment.