|
| 1 | +package com.back.koreaTravelGuide.domain.search |
| 2 | + |
| 3 | +import com.back.koreaTravelGuide.common.ApiResponse |
| 4 | +import io.swagger.v3.oas.annotations.Operation |
| 5 | +import io.swagger.v3.oas.annotations.Parameter |
| 6 | +import io.swagger.v3.oas.annotations.tags.Tag |
| 7 | +import org.springframework.data.domain.Page |
| 8 | +import org.springframework.web.bind.annotation.GetMapping |
| 9 | +import org.springframework.web.bind.annotation.PostMapping |
| 10 | +import org.springframework.web.bind.annotation.RequestMapping |
| 11 | +import org.springframework.web.bind.annotation.RequestParam |
| 12 | +import org.springframework.web.bind.annotation.RestController |
| 13 | + |
| 14 | +/** |
| 15 | + * 가이드 검색 API |
| 16 | + */ |
| 17 | +@RestController |
| 18 | +@RequestMapping("/api/search") |
| 19 | +@Tag(name = "Search", description = "가이드 검색 API (Elasticsearch)") |
| 20 | +class GuideSearchController( |
| 21 | + private val guideSearchService: GuideSearchService, |
| 22 | +) { |
| 23 | + @PostMapping("/guides/index") |
| 24 | + @Operation( |
| 25 | + summary = "전체 가이드 인덱싱", |
| 26 | + description = "DB의 모든 가이드를 Elasticsearch에 인덱싱합니다. (관리자 전용, 개발용)", |
| 27 | + ) |
| 28 | + fun indexAllGuides(): ApiResponse<String> { |
| 29 | + guideSearchService.indexAllGuides() |
| 30 | + return ApiResponse(msg = "All guides indexed successfully") |
| 31 | + } |
| 32 | + |
| 33 | + @GetMapping("/guides") |
| 34 | + @Operation( |
| 35 | + summary = "가이드 검색", |
| 36 | + description = "키워드, 언어, 지역, 평점으로 가이드를 검색합니다.", |
| 37 | + ) |
| 38 | + fun searchGuides( |
| 39 | + @Parameter(description = "검색 키워드 (이름, 소개글)") |
| 40 | + @RequestParam(required = false) |
| 41 | + keyword: String?, |
| 42 | + @Parameter(description = "언어 필터 (예: Korean, English)") |
| 43 | + @RequestParam(required = false) |
| 44 | + language: String?, |
| 45 | + @Parameter(description = "지역 필터 (예: 서울, 부산)") |
| 46 | + @RequestParam(required = false) |
| 47 | + region: String?, |
| 48 | + @Parameter(description = "최소 평점") |
| 49 | + @RequestParam(required = false) |
| 50 | + minRating: Double?, |
| 51 | + @Parameter(description = "페이지 번호 (0부터 시작)") |
| 52 | + @RequestParam(defaultValue = "0") |
| 53 | + page: Int, |
| 54 | + @Parameter(description = "페이지 크기") |
| 55 | + @RequestParam(defaultValue = "20") |
| 56 | + size: Int, |
| 57 | + ): ApiResponse<Page<GuideDocument>> { |
| 58 | + val results = |
| 59 | + guideSearchService.searchGuides( |
| 60 | + keyword = keyword, |
| 61 | + language = language, |
| 62 | + region = region, |
| 63 | + minRating = minRating, |
| 64 | + page = page, |
| 65 | + size = size, |
| 66 | + ) |
| 67 | + return ApiResponse(msg = "Search completed", data = results) |
| 68 | + } |
| 69 | + |
| 70 | + @GetMapping("/guides/keyword") |
| 71 | + @Operation( |
| 72 | + summary = "키워드 검색", |
| 73 | + description = "가이드 이름 또는 소개글에서 키워드를 검색합니다.", |
| 74 | + ) |
| 75 | + fun searchByKeyword( |
| 76 | + @RequestParam keyword: String, |
| 77 | + @RequestParam(defaultValue = "0") page: Int, |
| 78 | + @RequestParam(defaultValue = "20") size: Int, |
| 79 | + ): ApiResponse<Page<GuideDocument>> { |
| 80 | + val results = guideSearchService.searchByKeyword(keyword, page, size) |
| 81 | + return ApiResponse(msg = "Keyword search completed", data = results) |
| 82 | + } |
| 83 | + |
| 84 | + @GetMapping("/guides/language") |
| 85 | + @Operation( |
| 86 | + summary = "언어별 검색", |
| 87 | + description = "특정 언어를 사용하는 가이드를 검색합니다.", |
| 88 | + ) |
| 89 | + fun searchByLanguage( |
| 90 | + @RequestParam language: String, |
| 91 | + @RequestParam(defaultValue = "0") page: Int, |
| 92 | + @RequestParam(defaultValue = "20") size: Int, |
| 93 | + ): ApiResponse<Page<GuideDocument>> { |
| 94 | + val results = guideSearchService.searchByLanguage(language, page, size) |
| 95 | + return ApiResponse(msg = "Language search completed", data = results) |
| 96 | + } |
| 97 | + |
| 98 | + @GetMapping("/guides/region") |
| 99 | + @Operation( |
| 100 | + summary = "지역별 검색", |
| 101 | + description = "특정 지역에서 활동하는 가이드를 검색합니다.", |
| 102 | + ) |
| 103 | + fun searchByRegion( |
| 104 | + @RequestParam region: String, |
| 105 | + @RequestParam(defaultValue = "0") page: Int, |
| 106 | + @RequestParam(defaultValue = "20") size: Int, |
| 107 | + ): ApiResponse<Page<GuideDocument>> { |
| 108 | + val results = guideSearchService.searchByRegion(region, page, size) |
| 109 | + return ApiResponse(msg = "Region search completed", data = results) |
| 110 | + } |
| 111 | +} |
0 commit comments