@@ -98,28 +98,32 @@ public MapResponseDTO.SearchHotPlaceListDTO searchHotPlaceListByKeyword(MapReque
9898 @ Override
9999 public MapResponseDTO .HotPlaceListDTO viewHotPlaceList (MapRequestDTO .ViewHotPlaceDTO request , Integer page , Integer size ){
100100
101+ Sort sort = Sort .by (Sort .Direction .ASC , "distance" );
102+
103+ if ("authCount" .equals (request .getSortBy ())) {
104+ sort = Sort .by (Sort .Direction .DESC , "authCount" );
105+ }
106+
101107 // DB에서 sortBy에 따라 addressId, distance, authCount 계산해서 가져오기(Paging 적용)
102- List <Object []> resultPage = addressRepository .findAddressesWithSorting (
108+ Page <Object []> resultPage = addressRepository .findAddressesWithSorting (
103109 request .getMinX (), request .getMaxX (),
104110 request .getMinY (), request .getMaxY (),
105111 (request .getMinX () + request .getMaxX ()) / 2 , // 중심 좌표
106112 (request .getMinY () + request .getMaxY ()) / 2 ,
107- request .getSortBy (),
108- page ,
109- size
113+ PageRequest .of (page , size , sort )
110114 );
111115
112116 // DB에서 가져온 값으로 DTO 생성
113117 MapResponseDTO .HotPlaceListDTO hotPlaceList = new MapResponseDTO .HotPlaceListDTO (
114118 resultPage .stream ()
115119 .map (row -> {
116- // DB에서 addressId , distance, authCount 가져오기
117- Long addressId = (Long ) row [0 ]; // addressId
118- Double distance = (Double ) row [1 ]; // 거리
119- Long authCount = (Long ) row [2 ]; // 인증된 개수
120+ // DB에서 address , distance, authCount 가져오기
121+ Address address = (Address ) row [0 ]; // address
122+ Long authCount = (Long ) row [1 ]; // authCount
123+ Double distance = (Double ) row [2 ]; //distance
120124
121125 // Plan을 거쳐서 Post 목록 가져오기(15개)
122- List <Post > latestPosts = postRepository .findLatestPostsByAddressId (addressId , PageRequest .of (0 , 15 , Sort .by (Sort .Direction .DESC , "createdAt" )));
126+ List <Post > latestPosts = postRepository .findLatestPostsByAddressId (address . getId () , PageRequest .of (0 , 15 , Sort .by (Sort .Direction .DESC , "createdAt" )));
123127
124128 List <MapResponseDTO .HotPlaceListDTO .HotPlaceDTO .PostDTO > postList = latestPosts .stream ()
125129 .map (post -> new MapResponseDTO .HotPlaceListDTO .HotPlaceDTO .PostDTO (
@@ -128,10 +132,7 @@ public MapResponseDTO.HotPlaceListDTO viewHotPlaceList(MapRequestDTO.ViewHotPlac
128132 .collect (Collectors .toList ());
129133
130134 // 저장된 횟수 계산 (my_address 테이블에서 address_id로 저장된 레코드 수 조회)
131- Long saveCount = myAddressRepository .countByAddressId (addressId );
132-
133- Address address = addressRepository .findById (addressId )
134- .orElseThrow (() -> new IllegalArgumentException ("해당 장소를 찾을 수 없습니다." ));
135+ Long saveCount = myAddressRepository .countByAddressId (address .getId ());
135136
136137 return new MapResponseDTO .HotPlaceListDTO .HotPlaceDTO (
137138 address .getId (),
0 commit comments