-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 지역 관련 코드 추가 * feat: 통합 검색 UseCase 작성 * feat: 통합 검색 API 작성 * chore: ktlint 적용 * feat: 리뷰 반영
- Loading branch information
1 parent
361ecfd
commit 54e20a2
Showing
27 changed files
with
407 additions
and
9 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
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
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/celuveat/region/adapter/out/persistence/RegionPersistenceAdapter.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,18 @@ | ||
package com.celuveat.region.adapter.out.persistence | ||
|
||
import com.celuveat.common.annotation.Adapter | ||
import com.celuveat.region.adapter.out.persistence.entity.RegionJpaRepository | ||
import com.celuveat.region.adapter.out.persistence.entity.RegionPersistenceMapper | ||
import com.celuveat.region.application.port.out.ReadRegionPort | ||
import com.celuveat.region.domain.Region | ||
|
||
@Adapter | ||
class RegionPersistenceAdapter( | ||
private val regionJpaRepository: RegionJpaRepository, | ||
private val regionPersistenceMapper: RegionPersistenceMapper, | ||
) : ReadRegionPort { | ||
override fun readByName(name: String): List<Region> { | ||
val regions = regionJpaRepository.readByNameContains(name) | ||
return regions.map { regionPersistenceMapper.toDomain(it) } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/celuveat/region/adapter/out/persistence/entity/RegionJpaEntity.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,24 @@ | ||
package com.celuveat.region.adapter.out.persistence.entity | ||
|
||
import com.celuveat.common.adapter.out.persistence.entity.RootEntity | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
|
||
@Table(name = "region") | ||
@Entity | ||
class RegionJpaEntity( | ||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0, | ||
@Column(nullable = false) | ||
val name: String, | ||
val latitude: Double, | ||
val longitude: Double, | ||
) : RootEntity<Long>() { | ||
override fun id(): Long { | ||
return this.id | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/celuveat/region/adapter/out/persistence/entity/RegionJpaRepository.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,9 @@ | ||
package com.celuveat.region.adapter.out.persistence.entity | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
interface RegionJpaRepository : JpaRepository<RegionJpaEntity, Long> { | ||
@Query(value = "SELECT r FROM RegionJpaEntity r WHERE r.name LIKE %:name%") | ||
fun readByNameContains(name: String): List<RegionJpaEntity> | ||
} |
20 changes: 20 additions & 0 deletions
20
...main/kotlin/com/celuveat/region/adapter/out/persistence/entity/RegionPersistenceMapper.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,20 @@ | ||
package com.celuveat.region.adapter.out.persistence.entity | ||
|
||
import com.celuveat.common.annotation.Mapper | ||
import com.celuveat.region.domain.Region | ||
|
||
@Mapper | ||
class RegionPersistenceMapper { | ||
fun toDomain(region: RegionJpaEntity): Region { | ||
return Region(id = region.id, name = region.name, latitude = region.latitude, longitude = region.longitude) | ||
} | ||
|
||
fun toEntity(region: Region): RegionJpaEntity { | ||
return RegionJpaEntity( | ||
id = region.id, | ||
name = region.name, | ||
latitude = region.latitude, | ||
longitude = region.longitude, | ||
) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/celuveat/region/application/port/out/ReadRegionPort.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,7 @@ | ||
package com.celuveat.region.application.port.out | ||
|
||
import com.celuveat.region.domain.Region | ||
|
||
interface ReadRegionPort { | ||
fun readByName(name: String): List<Region> | ||
} |
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.celuveat.region.domain | ||
|
||
data class Region( | ||
val id: Long = 0, | ||
val name: String, | ||
val latitude: Double = 0.0, | ||
val longitude: Double = 0.0, | ||
) |
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
2 changes: 1 addition & 1 deletion
2
...m/celuveat/restaurant/adapter/out/persistence/entity/InterestedRestaurantJpaRepository.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
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
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/celuveat/search/adapter/in/rest/SearchApi.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,24 @@ | ||
package com.celuveat.search.adapter.`in`.rest | ||
|
||
import com.celuveat.search.adapter.`in`.rest.response.IntegratedSearchResponse | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
|
||
@Tag(name = "검색 API") | ||
interface SearchApi { | ||
@Operation(summary = "지역, 셀럽, 음식점 통합 검색") | ||
@GetMapping("/integrated") | ||
fun integratedSearch( | ||
@Parameter( | ||
`in` = ParameterIn.QUERY, | ||
description = "이름", | ||
example = "감자", | ||
required = true, | ||
) | ||
@RequestParam(name = "name") name: String, | ||
): IntegratedSearchResponse | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/celuveat/search/adapter/in/rest/SearchController.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,22 @@ | ||
package com.celuveat.search.adapter.`in`.rest | ||
|
||
import com.celuveat.search.adapter.`in`.rest.response.IntegratedSearchResponse | ||
import com.celuveat.search.application.port.`in`.IntegratedSearchUseCase | ||
import com.celuveat.search.application.port.`in`.query.IntegratedSearchQuery | ||
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 | ||
|
||
@RequestMapping("/search") | ||
@RestController | ||
class SearchController( | ||
private val integratedSearchUseCase: IntegratedSearchUseCase, | ||
) : SearchApi { | ||
@GetMapping("/integrated") | ||
override fun integratedSearch( | ||
@RequestParam(name = "name") name: String, | ||
): IntegratedSearchResponse { | ||
return IntegratedSearchResponse.from(integratedSearchUseCase.searchByName(IntegratedSearchQuery(name))) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/com/celuveat/search/adapter/in/rest/response/IntegratedSearchResonse.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,52 @@ | ||
package com.celuveat.search.adapter.`in`.rest.response | ||
|
||
import com.celuveat.search.application.port.`in`.result.IntegratedSearchResult | ||
import com.celuveat.search.application.port.`in`.result.RegionResult | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
data class IntegratedSearchResponse( | ||
val regionResults: List<RegionResponse>, | ||
val restaurantResults: List<ResponseWithId>, | ||
val celebrityResults: List<ResponseWithId>, | ||
) { | ||
companion object { | ||
fun from(result: IntegratedSearchResult): IntegratedSearchResponse { | ||
return IntegratedSearchResponse( | ||
regionResults = result.regionResults.map { RegionResponse.from(it) }, | ||
restaurantResults = result.restaurantResults.map { ResponseWithId(id = it.id, name = it.name) }, | ||
celebrityResults = result.celebrityResults.map { ResponseWithId(id = it.id, name = it.name) }, | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class ResponseWithId( | ||
val id: Long, | ||
val name: String, | ||
) | ||
|
||
data class RegionResponse( | ||
val id: Long, | ||
val name: String, | ||
@Schema( | ||
description = "위도", | ||
example = "37.123456", | ||
) | ||
val latitude: Double, | ||
@Schema( | ||
description = "경도", | ||
example = "127.123456", | ||
) | ||
val longitude: Double, | ||
) { | ||
companion object { | ||
fun from(result: RegionResult): RegionResponse { | ||
return RegionResponse( | ||
id = result.id, | ||
name = result.name, | ||
latitude = result.latitude, | ||
longitude = result.longitude, | ||
) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/celuveat/search/application/SearchQueryService.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.celuveat.search.application | ||
|
||
import com.celuveat.celeb.application.port.out.ReadCelebritiesPort | ||
import com.celuveat.region.application.port.out.ReadRegionPort | ||
import com.celuveat.restaurant.application.port.out.ReadRestaurantPort | ||
import com.celuveat.search.application.port.`in`.IntegratedSearchUseCase | ||
import com.celuveat.search.application.port.`in`.query.IntegratedSearchQuery | ||
import com.celuveat.search.application.port.`in`.result.IntegratedSearchResult | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SearchQueryService( | ||
private val readRegionPort: ReadRegionPort, | ||
private val readRestaurantPort: ReadRestaurantPort, | ||
private val readCelebritiesPort: ReadCelebritiesPort, | ||
) : IntegratedSearchUseCase { | ||
override fun searchByName(query: IntegratedSearchQuery): IntegratedSearchResult { | ||
val regions = readRegionPort.readByName(query.name) | ||
val restaurants = readRestaurantPort.readByName(query.name) | ||
val celebrities = readCelebritiesPort.readByName(query.name) | ||
return IntegratedSearchResult.of(regions = regions, restaurants = restaurants, celebrities = celebrities) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/celuveat/search/application/port/in/IntegratedSearchUseCase.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.celuveat.search.application.port.`in` | ||
|
||
import com.celuveat.search.application.port.`in`.query.IntegratedSearchQuery | ||
import com.celuveat.search.application.port.`in`.result.IntegratedSearchResult | ||
|
||
interface IntegratedSearchUseCase { | ||
fun searchByName(query: IntegratedSearchQuery): IntegratedSearchResult | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/celuveat/search/application/port/in/query/IntegratedSearchQuery.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,5 @@ | ||
package com.celuveat.search.application.port.`in`.query | ||
|
||
data class IntegratedSearchQuery( | ||
val name: String, | ||
) |
Oops, something went wrong.