|
| 1 | +package com.busan.controller; |
| 2 | + |
| 3 | +import com.busan.dto.common.Response; |
| 4 | +import com.busan.dto.place.PlaceSearchResponseDTO; |
| 5 | +import com.busan.service.CombinedPlaceSearchService; |
| 6 | +import io.swagger.v3.oas.annotations.Operation; |
| 7 | +import io.swagger.v3.oas.annotations.Parameter; |
| 8 | +import io.swagger.v3.oas.annotations.media.Content; |
| 9 | +import io.swagger.v3.oas.annotations.media.ExampleObject; |
| 10 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 11 | +import lombok.RequiredArgsConstructor; |
| 12 | +import org.springdoc.core.annotations.ParameterObject; |
| 13 | +import org.springframework.data.domain.Pageable; |
| 14 | +import org.springframework.http.ResponseEntity; |
| 15 | +import org.springframework.web.bind.annotation.*; |
| 16 | + |
| 17 | +@Tag(name = "places-controller", description = "매물 검색 API") |
| 18 | +@RestController |
| 19 | +@RequiredArgsConstructor |
| 20 | +@RequestMapping("/api/places") |
| 21 | +public class PlaceSearchController { |
| 22 | + |
| 23 | + private final CombinedPlaceSearchService combinedPlaceSearchService; |
| 24 | + |
| 25 | + @Operation( |
| 26 | + summary = "매물 검색 (내부 + 외부 합성 지원)", |
| 27 | + description = """ |
| 28 | + - 입력: |
| 29 | + - q: 주소/키워드 (예: "센텀동로 45"). q만 주어지면 서버가 카카오 주소검색으로 좌표를 얻습니다. |
| 30 | + - lat/lng: 검색 중심 좌표(선택). 있으면 반경 검색에 사용합니다. |
| 31 | + - radiusKm: 반경(km), 기본=1. |
| 32 | + - includeExternal: true 이면 카카오 결과도 함께 병합하여 반환(내부 결과 우선). |
| 33 | + - page/size: 페이징. |
| 34 | + |
| 35 | + - 동작 우선순위: |
| 36 | + 1) lat/lng/radiusKm → 내부 DB 반경 검색 (+옵션: 외부 병합) |
| 37 | + 2) q만 있을 때 → 카카오 주소검색으로 lat/lng 확보 후 1)과 동일 |
| 38 | + 3) 어떤 조건도 없으면 내부 DB 최신순 페이지 반환 |
| 39 | + |
| 40 | + - 예시 호출: |
| 41 | + - /api/places/search?q=센텀&page=0&size=20 |
| 42 | + - /api/places/search?lat=35.1661&lng=129.1322&radiusKm=1&includeExternal=true&page=0&size=20 |
| 43 | + """ |
| 44 | + , |
| 45 | + responses = { |
| 46 | + @io.swagger.v3.oas.annotations.responses.ApiResponse( |
| 47 | + responseCode = "200", |
| 48 | + description = "성공 (내부 결과만)", |
| 49 | + content = @Content(examples = @ExampleObject( |
| 50 | + name = "internal-only", |
| 51 | + value = """ |
| 52 | + { |
| 53 | + "data": { |
| 54 | + "content": [ |
| 55 | + { |
| 56 | + "placeId": 101, |
| 57 | + "landlordId": 55, |
| 58 | + "address": "부산 동래구 ...", |
| 59 | + "addressDetail": "101동 1001호", |
| 60 | + "postCode": "47890", |
| 61 | + "geohash": "u4pruyd...", |
| 62 | + "lat": 35.1952, |
| 63 | + "lng": 129.0871, |
| 64 | + "createdAt": "2025-08-12T13:00:00", |
| 65 | + "updatedAt": "2025-08-18T11:30:00", |
| 66 | + "externalProvider": null, |
| 67 | + "externalPlaceId": null |
| 68 | + } |
| 69 | + ], |
| 70 | + "page": 0, |
| 71 | + "size": 20, |
| 72 | + "totalElements": 42, |
| 73 | + "totalPages": 3 |
| 74 | + }, |
| 75 | + "status": "SUCCESS", |
| 76 | + "serverDateTime": "2025-08-18T20:00:00", |
| 77 | + "errorCode": null, |
| 78 | + "errorMessage": null |
| 79 | + } |
| 80 | + """))) |
| 81 | + , |
| 82 | + @io.swagger.v3.oas.annotations.responses.ApiResponse( |
| 83 | + responseCode = "200", |
| 84 | + description = "성공 (외부 결과 포함)", |
| 85 | + content = @Content(examples = @ExampleObject( |
| 86 | + name = "with-external", |
| 87 | + value = """ |
| 88 | + { |
| 89 | + "data": { |
| 90 | + "content": [ |
| 91 | + { |
| 92 | + "placeId": 101, |
| 93 | + "landlordId": 55, |
| 94 | + "address": "부산 동래구 ...", |
| 95 | + "addressDetail": "101동 1001호", |
| 96 | + "postCode": "47890", |
| 97 | + "geohash": "u4pruyd...", |
| 98 | + "lat": 35.1952, |
| 99 | + "lng": 129.0871, |
| 100 | + "createdAt": "2025-08-12T13:00:00", |
| 101 | + "updatedAt": "2025-08-18T11:30:00", |
| 102 | + "externalProvider": null, |
| 103 | + "externalPlaceId": null |
| 104 | + }, |
| 105 | + { |
| 106 | + "placeId": null, |
| 107 | + "landlordId": null, |
| 108 | + "address": "부산 해운대구 ...", |
| 109 | + "addressDetail": null, |
| 110 | + "postCode": null, |
| 111 | + "geohash": null, |
| 112 | + "lat": 35.1661, |
| 113 | + "lng": 129.1322, |
| 114 | + "createdAt": null, |
| 115 | + "updatedAt": null, |
| 116 | + "externalProvider": "KAKAO", |
| 117 | + "externalPlaceId": "123456" |
| 118 | + } |
| 119 | + ], |
| 120 | + "page": 0, |
| 121 | + "size": 20, |
| 122 | + "totalElements": 2, |
| 123 | + "totalPages": 1 |
| 124 | + }, |
| 125 | + "status": "SUCCESS", |
| 126 | + "serverDateTime": "2025-08-18T20:00:00", |
| 127 | + "errorCode": null, |
| 128 | + "errorMessage": null |
| 129 | + } |
| 130 | + """))) |
| 131 | + |
| 132 | + } |
| 133 | + ) |
| 134 | + @GetMapping("/search") |
| 135 | + public ResponseEntity<Response<PlaceSearchResponseDTO>> search( |
| 136 | + @Parameter(description = "주소 키워드(부분검색)", example = "센텀") |
| 137 | + @RequestParam(required = false) String q, |
| 138 | + |
| 139 | + @Parameter(description = "위도", example = "35.1661") |
| 140 | + @RequestParam(required = false) Double lat, |
| 141 | + |
| 142 | + @Parameter(description = "경도", example = "129.1322") |
| 143 | + @RequestParam(required = false) Double lng, |
| 144 | + |
| 145 | + @Parameter(description = "반경(km)", example = "1") |
| 146 | + @RequestParam(required = false) Double radiusKm, |
| 147 | + |
| 148 | + @Parameter(description = "외부(카카오) 결과 포함 여부", example = "true") |
| 149 | + @RequestParam(defaultValue = "false") boolean includeExternal, |
| 150 | + |
| 151 | + @ParameterObject Pageable pageable |
| 152 | + ) { |
| 153 | + var dto = combinedPlaceSearchService.searchForUser(q, lat, lng, radiusKm, includeExternal, pageable); |
| 154 | + return ResponseEntity.ok(Response.success(dto)); |
| 155 | + } |
| 156 | +} |
0 commit comments