|
| 1 | +package com.busan.controller; |
| 2 | + |
| 3 | +import com.busan.dto.common.Response; |
| 4 | +import com.busan.dto.diagnosis.DiagnosisRequestDTO; |
| 5 | +import com.busan.dto.diagnosis.DiagnosisResponseDTO; |
| 6 | +import io.swagger.v3.oas.annotations.Operation; |
| 7 | +import io.swagger.v3.oas.annotations.media.Content; |
| 8 | +import io.swagger.v3.oas.annotations.media.ExampleObject; |
| 9 | +import io.swagger.v3.oas.annotations.media.Schema; |
| 10 | +import io.swagger.v3.oas.annotations.responses.ApiResponse; |
| 11 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 12 | +import lombok.RequiredArgsConstructor; |
| 13 | +import org.springframework.http.ResponseEntity; |
| 14 | +import org.springframework.web.bind.annotation.*; |
| 15 | + |
| 16 | +@Tag(name = "Diagnosis", description = "진단하기(합성 API)") |
| 17 | +@RestController |
| 18 | +@RequiredArgsConstructor |
| 19 | +@RequestMapping("/api") |
| 20 | +public class DiagnosisController { |
| 21 | + |
| 22 | + private final com.busan.service.DiagnosisService diagnosisService; |
| 23 | + |
| 24 | + /** |
| 25 | + * 진단하기 버튼 액션. |
| 26 | + * - 주소/상세주소/주택유형/전세금만 받아서 |
| 27 | + * - 위험도 요약 + 임대인 + 신뢰도 + 임대인 매물 리스트를 한 번에 반환 |
| 28 | + */ |
| 29 | + @Operation( |
| 30 | + summary = "진단하기", |
| 31 | + description = """ |
| 32 | + 주소/상세주소/주택유형/전세금으로 대상 매물을 식별하고, |
| 33 | + 위험도 요약·임대인 정보·임대인 신뢰도·임대인 소유 매물 목록을 한 번에 반환합니다. |
| 34 | + """ |
| 35 | + ) |
| 36 | + @ApiResponse( |
| 37 | + responseCode = "200", |
| 38 | + description = "성공", |
| 39 | + content = @Content( |
| 40 | + mediaType = "application/json", |
| 41 | + // 제네릭 Response<T>를 정확히 타입으로 매핑하기 어렵다면 example로 보여주는 게 가장 실용적입니다. |
| 42 | + examples = @ExampleObject( |
| 43 | + name = "성공 응답 예시", |
| 44 | + value = """ |
| 45 | + { |
| 46 | + "data": { |
| 47 | + "riskSummary": { |
| 48 | + "score": 15, |
| 49 | + "grade": "위험", |
| 50 | + "factors": [ |
| 51 | + { "name": "전세가율", "percent": 20 }, |
| 52 | + { "name": "가격하락", "percent": 33 }, |
| 53 | + { "name": "미분양(재고)", "percent": 13 }, |
| 54 | + { "name": "정책/규제", "percent": 20 }, |
| 55 | + { "name": "법적 리스크", "percent": 13 } |
| 56 | + ] |
| 57 | + }, |
| 58 | + "landlord": { |
| 59 | + "landlordId": 1, |
| 60 | + "name": "홍길동", |
| 61 | + "normalizedKey": "부산-사업자번호-해시", |
| 62 | + "ownedCount": 1, |
| 63 | + "grade": "A", |
| 64 | + "createdAt": "2025-08-21T02:26:22.055226", |
| 65 | + "updatedAt": "2025-08-21T02:26:22.055226" |
| 66 | + }, |
| 67 | + "landlordTrust": { |
| 68 | + "trustScore": 85, |
| 69 | + "subrogationCount": 0, |
| 70 | + "arrearsCount": 0, |
| 71 | + "litigationCount": 0, |
| 72 | + "ownedUnsoldCount": 2, |
| 73 | + "grade": "A" |
| 74 | + }, |
| 75 | + "landlordPlaces": [ |
| 76 | + { |
| 77 | + "placeId": 1, |
| 78 | + "label": "부산광역시 해운대구 센텀동로 45", |
| 79 | + "address": "부산광역시 해운대구 센텀동로 45", |
| 80 | + "addressDetail": "101동 1001호" |
| 81 | + } |
| 82 | + ] |
| 83 | + }, |
| 84 | + "status": "SUCCESS", |
| 85 | + "serverDateTime": "2025-08-21T02:28:11.398139", |
| 86 | + "errorCode": null, |
| 87 | + "errorMessage": null |
| 88 | + } |
| 89 | + """ |
| 90 | + ) |
| 91 | + ) |
| 92 | + ) |
| 93 | + @PostMapping("/diagnosis") |
| 94 | + public ResponseEntity<Response<DiagnosisResponseDTO>> diagnose(@RequestBody DiagnosisRequestDTO req) { |
| 95 | + var dto = diagnosisService.diagnose( |
| 96 | + req.getAddress(), |
| 97 | + req.getAddressDetail(), |
| 98 | + req.getHouseType(), |
| 99 | + req.getDeposit() |
| 100 | + ); |
| 101 | + return ResponseEntity.ok(Response.success(dto)); |
| 102 | + } |
| 103 | +} |
0 commit comments