-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
268 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/routebox/routebox/application/route/SearchRoutesUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.routebox.routebox.application.route | ||
|
||
import com.routebox.routebox.application.route.dto.GetRouteDetailResult | ||
import com.routebox.routebox.application.route.dto.SearchCommand | ||
import com.routebox.routebox.domain.route.RouteService | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SearchRoutesUseCase( | ||
private val routeService: RouteService, | ||
) { | ||
/** | ||
* 루트 검색. | ||
* | ||
* @param request 검색 조건 | ||
* @return 루트 상세 정보 | ||
* @throws | ||
*/ | ||
operator fun invoke(request: SearchCommand): List<GetRouteDetailResult> { | ||
val routes = routeService.searchRoutes(request).map { GetRouteDetailResult.from(it) } | ||
return routes | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/routebox/routebox/application/route/dto/SearchCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.routebox.routebox.application.route.dto | ||
|
||
import com.routebox.routebox.controller.route.dto.RouteSortBy | ||
import com.routebox.routebox.controller.route.dto.SearchFilters | ||
|
||
data class SearchCommand( | ||
val page: Int, | ||
val size: Int, | ||
val filters: SearchFilters, | ||
val query: String?, | ||
val sortBy: RouteSortBy, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/com/routebox/routebox/controller/route/RouteSearchController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.routebox.routebox.controller.route | ||
|
||
import com.routebox.routebox.application.route.SearchRoutesUseCase | ||
import com.routebox.routebox.application.route.dto.SearchCommand | ||
import com.routebox.routebox.controller.route.dto.RouteSortBy | ||
import com.routebox.routebox.controller.route.dto.SearchFilters | ||
import com.routebox.routebox.controller.route.dto.SearchRouteDto | ||
import com.routebox.routebox.controller.route.dto.SearchRoutesResponse | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.Parameters | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.validation.annotation.Validated | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = "루트 검색 관련 API") | ||
@RestController | ||
@Validated | ||
@RequestMapping("/api") | ||
class RouteSearchController( | ||
private val searchRoutesUseCase: SearchRoutesUseCase, | ||
) { | ||
@Operation( | ||
summary = "루트 검색", | ||
description = "검색어, 검색 필터, 정렬 등을 이용한 루트 검색", | ||
security = [SecurityRequirement(name = "access-token")], | ||
) | ||
@ApiResponses( | ||
ApiResponse(responseCode = "200"), | ||
) | ||
@Parameters( | ||
Parameter(name = "sortBy", description = "정렬 기준 (NEWEST, OLDEST, POPULAR, COMMENTS)"), | ||
Parameter(name = "whoWith", description = "대상 (예: 친구, 가족)"), | ||
Parameter(name = "numberOfPeople", description = "인원수 (예: 2, 3)"), | ||
Parameter(name = "numberOfDays", description = "머무는 기간 (일 수)"), | ||
Parameter(name = "style", description = "루트 스타일 (예: 모험, 휴식)"), | ||
Parameter(name = "transportation", description = "이동수단 (예: 자동차, 자전거)"), | ||
) | ||
@GetMapping("/v1/search") | ||
fun searchRoutes( | ||
@RequestParam(defaultValue = "0") page: Int, | ||
@RequestParam(defaultValue = "10") size: Int, | ||
@RequestParam(required = false) query: String? = null, | ||
@RequestParam(required = false) sortBy: RouteSortBy = RouteSortBy.NEWEST, | ||
@RequestParam(required = false) whoWith: List<String> = emptyList(), | ||
@RequestParam(required = false) numberOfPeople: List<Int> = emptyList(), | ||
@RequestParam(required = false) numberOfDays: List<String> = emptyList(), | ||
@RequestParam(required = false) style: List<String> = emptyList(), | ||
@RequestParam(required = false) transportation: List<String> = emptyList(), | ||
): SearchRoutesResponse { | ||
val filters = SearchFilters.from(whoWith, numberOfPeople, numberOfDays, style, transportation) | ||
val request = SearchCommand(page, size, filters, query, sortBy) | ||
return SearchRoutesResponse.from(searchRoutesUseCase(request).map { SearchRouteDto.from(it) }) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/routebox/routebox/controller/route/dto/RouteSortBy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
enum class RouteSortBy { | ||
NEWEST, | ||
OLDEST, | ||
POPULAR, | ||
COMMENTS, | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/routebox/routebox/controller/route/dto/SearchFilters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
data class SearchFilters( | ||
val whoWith: List<String>, | ||
|
||
val numberOfPeople: List<Int>, | ||
|
||
val numberOfDays: List<String>, | ||
|
||
val style: List<String>, | ||
|
||
val transportation: List<String>, | ||
) { | ||
companion object { | ||
fun from(whoWith: List<String>, numberOfPeople: List<Int>, numberOfDays: List<String>, style: List<String>, transportation: List<String>): SearchFilters = SearchFilters( | ||
whoWith = whoWith, | ||
numberOfPeople = numberOfPeople, | ||
numberOfDays = numberOfDays, | ||
style = style, | ||
transportation = transportation, | ||
) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/kotlin/com/routebox/routebox/controller/route/dto/SearchRouteDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
import com.routebox.routebox.application.route.dto.GetRouteDetailResult | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import java.time.LocalDateTime | ||
|
||
data class SearchRouteDto( | ||
@Schema(description = "Id(PK) of route", example = "1") | ||
val routeId: Long, | ||
|
||
@Schema(description = "Id(PK) of user", example = "1") | ||
val userId: Long, | ||
|
||
@Schema(description = "유저 프로필 이미지(url)", example = "https://user-profile-image") | ||
val profileImageUrl: String, | ||
|
||
@Schema(description = "닉네임", example = "고작가") | ||
val nickname: String, | ||
|
||
@Schema(description = "루트 제목", example = "서울의 작가들") | ||
val routeName: String?, | ||
|
||
@Schema(description = "루트 설명", example = "서울의 작가들을 만나보세요.") | ||
val routeDescription: String?, | ||
|
||
@Schema(description = "루트 이미지", example = "https://route-image1") | ||
val routeImageUrl: String, | ||
|
||
@Schema(description = "루트 구매 수", example = "0") | ||
val purchaseCount: Int, | ||
|
||
@Schema(description = "루트 댓글 수", example = "0") | ||
val commentCount: Int, | ||
|
||
@Schema(description = "루트 생성일", example = "2021-08-01T00:00:00") | ||
val createdAt: LocalDateTime?, | ||
) { | ||
companion object { | ||
fun from( | ||
getRouteDetailResult: GetRouteDetailResult, | ||
): SearchRouteDto = SearchRouteDto( | ||
routeId = getRouteDetailResult.routeId, | ||
userId = getRouteDetailResult.userId, | ||
profileImageUrl = getRouteDetailResult.profileImageUrl, | ||
nickname = getRouteDetailResult.nickname, | ||
routeName = getRouteDetailResult.routeName, | ||
routeDescription = getRouteDetailResult.routeDescription, | ||
routeImageUrl = getRouteDetailResult.routeImageUrls.firstOrNull() ?: "", | ||
purchaseCount = getRouteDetailResult.purchaseCount, | ||
commentCount = getRouteDetailResult.commentCount, | ||
createdAt = getRouteDetailResult.recordFinishedAt, | ||
) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/routebox/routebox/controller/route/dto/SearchRoutesResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
data class SearchRoutesResponse( | ||
@Schema(description = "검색된 루트 리스트") | ||
val routes: List<SearchRouteDto>, | ||
) { | ||
companion object { | ||
fun from(routes: List<SearchRouteDto>): SearchRoutesResponse = SearchRoutesResponse( | ||
routes = routes, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters