-
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.
Merge pull request #110 from mash-up-kr/feature/auto-complete-save
feat: 장소 입력자동화 정보 DB 저장
- Loading branch information
Showing
26 changed files
with
206 additions
and
195 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
piikii-application/src/main/kotlin/com/piikii/application/domain/generic/Origin.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.piikii.application.domain.generic | ||
|
||
enum class Origin { | ||
AVOCADO, | ||
LEMON, | ||
MANUAL, | ||
enum class Origin(val prefix: String) { | ||
AVOCADO("A"), | ||
LEMON("L"), | ||
MANUAL("M"), | ||
} |
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
12 changes: 2 additions & 10 deletions
12
...ication/src/main/kotlin/com/piikii/application/port/output/persistence/OriginPlacePort.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 |
---|---|---|
@@ -1,20 +1,12 @@ | ||
package com.piikii.application.port.output.persistence | ||
|
||
import com.piikii.application.domain.place.OriginMapId | ||
import com.piikii.application.domain.place.OriginPlace | ||
|
||
interface OriginPlaceQueryPort { | ||
fun retrieve(id: Long): OriginPlace | ||
|
||
fun retrieveAll(ids: List<Long>): List<OriginPlace> | ||
fun findByOriginMapId(originMapId: OriginMapId): OriginPlace? | ||
} | ||
|
||
interface OriginPlaceCommandPort { | ||
fun save(originPlace: OriginPlace): OriginPlace | ||
|
||
fun update( | ||
originPlace: OriginPlace, | ||
id: Long, | ||
) | ||
|
||
fun delete(id: Long) | ||
} |
5 changes: 3 additions & 2 deletions
5
...n/src/main/kotlin/com/piikii/application/port/output/web/OriginPlaceAutoCompleteClient.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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package com.piikii.application.port.output.web | ||
|
||
import com.piikii.application.domain.place.OriginMapId | ||
import com.piikii.application.domain.place.OriginPlace | ||
|
||
interface OriginPlaceAutoCompleteClient { | ||
fun isAutoCompleteSupportedUrl(url: String): Boolean | ||
|
||
fun extractPlaceId(url: String): String | ||
fun extractOriginMapId(url: String): OriginMapId | ||
|
||
fun getAutoCompletedPlace( | ||
url: String, | ||
placeId: String, | ||
originMapId: OriginMapId, | ||
): OriginPlace | ||
} |
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
5 changes: 4 additions & 1 deletion
5
.../com/piikii/output/persistence/postgresql/persistence/repository/OriginPlaceRepository.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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package com.piikii.output.persistence.postgresql.persistence.repository | ||
|
||
import com.piikii.application.domain.place.OriginMapId | ||
import com.piikii.output.persistence.postgresql.persistence.entity.OriginPlaceEntity | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface OriginPlaceRepository : JpaRepository<OriginPlaceEntity, Long> | ||
interface OriginPlaceRepository : JpaRepository<OriginPlaceEntity, Long> { | ||
fun findByOriginMapId(originMapId: OriginMapId): OriginPlaceEntity? | ||
} |
15 changes: 8 additions & 7 deletions
15
...o/src/main/kotlin/com/piikii/output/web/avocado/adapter/AvocadoPlaceAutoCompleteClient.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ data class AvocadoUrl( | |
) { | ||
data class Regex( | ||
val web: String, | ||
val mobileWeb: String, | ||
val share: String, | ||
) | ||
} |
77 changes: 77 additions & 0 deletions
77
.../avocado/src/main/kotlin/com/piikii/output/web/avocado/parser/AvocadoOriginMapIdParser.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,77 @@ | ||
package com.piikii.output.web.avocado.parser | ||
|
||
import com.piikii.application.domain.generic.Origin | ||
import com.piikii.application.domain.place.OriginMapId | ||
import com.piikii.output.web.avocado.config.AvocadoProperties | ||
import com.piikii.output.web.avocado.parser.AvocadoOriginMapIdParser.Companion.ORIGIN_MAP_IP_REGEX | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.client.RestClient | ||
|
||
@Component | ||
class AvocadoOriginMapIdParserStrategy(private val parsers: List<AvocadoOriginMapIdParser>) { | ||
fun getParserBySupportedUrl(url: String): AvocadoOriginMapIdParser? { | ||
return parsers.firstOrNull { it.getParserBySupportedUrl(url) != null } | ||
} | ||
} | ||
|
||
interface AvocadoOriginMapIdParser { | ||
fun getParserBySupportedUrl(url: String): AvocadoOriginMapIdParser? | ||
|
||
fun parseOriginMapId(url: String): OriginMapId? | ||
|
||
/** | ||
* Regex를 이용해 OriginMapId 반환 | ||
* - Regex Match 결과로부터 첫 번째 값을 꺼내 OriginMapId 변환 및 반환 | ||
* | ||
* @return OriginMapId | ||
*/ | ||
fun MatchResult?.parseFromMatchResult(): OriginMapId? { | ||
return this?.groupValues | ||
?.getOrNull(1) | ||
?.toLongOrNull() | ||
?.let { OriginMapId.of(id = it, origin = Origin.AVOCADO) } | ||
} | ||
|
||
companion object { | ||
const val ORIGIN_MAP_IP_REGEX = "\\d+" | ||
} | ||
} | ||
|
||
@Component | ||
class MapUrlIdParser(properties: AvocadoProperties) : AvocadoOriginMapIdParser { | ||
private val regexes: List<Regex> = | ||
listOf( | ||
"${properties.url.regex.web}($ORIGIN_MAP_IP_REGEX)".toRegex(), | ||
"${properties.url.regex.mobileWeb}($ORIGIN_MAP_IP_REGEX)/home".toRegex(), | ||
) | ||
|
||
override fun getParserBySupportedUrl(url: String): AvocadoOriginMapIdParser? = | ||
takeIf { regexes.any { regex -> regex.matches(url) } } | ||
|
||
override fun parseOriginMapId(url: String): OriginMapId? { | ||
return regexes.first { it.matches(url) }.find(url).parseFromMatchResult() | ||
} | ||
} | ||
|
||
@Component | ||
class ShareUrlIdParser( | ||
properties: AvocadoProperties, | ||
) : AvocadoOriginMapIdParser { | ||
private val regex: Regex = properties.url.regex.share.toRegex() | ||
private val idParameterRegex: Regex = "id=(\\d+)".toRegex() | ||
private val client: RestClient = RestClient.builder().build() | ||
|
||
override fun getParserBySupportedUrl(url: String): AvocadoOriginMapIdParser? = takeIf { regex.matches(url) } | ||
|
||
override fun parseOriginMapId(url: String): OriginMapId? { | ||
val response = | ||
client.get().uri(url) | ||
.retrieve() | ||
.toEntity(Map::class.java) | ||
if (response.statusCode.is3xxRedirection && response.headers.location != null) { | ||
return idParameterRegex.find(response.headers.location.toString()) | ||
.parseFromMatchResult() | ||
} | ||
return null | ||
} | ||
} |
Oops, something went wrong.