-
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 #89 from mash-up-kr/feature/output-web/dhyeonkim
feat: 방 정보 자동 생성 어댑터 구현 (LEMON)
- Loading branch information
Showing
14 changed files
with
243 additions
and
3 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
7 changes: 7 additions & 0 deletions
7
piikii-application/src/main/kotlin/com/piikii/application/port/output/web/UrlClient.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.piikii.application.port.output.web | ||
|
||
import com.piikii.application.domain.place.OriginPlace | ||
|
||
interface UrlClient { | ||
fun get(url: String): 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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
project(":piikii-output-web:avocado") { | ||
dependencies { | ||
implementation("org.springframework:spring-web") | ||
} | ||
} | ||
|
||
project(":piikii-output-web:lemon") { | ||
dependencies { | ||
implementation("org.springframework:spring-web") | ||
} | ||
} | ||
|
||
allprojects { | ||
dependencies { | ||
implementation(project(":piikii-application")) | ||
} | ||
|
||
tasks.bootJar { | ||
enabled = false | ||
} | ||
|
||
tasks.jar { | ||
enabled = true | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
piikii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/UrlClientResponse.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,135 @@ | ||
package com.piikii.output.web.lemon | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.piikii.application.domain.generic.Origin | ||
import com.piikii.application.domain.generic.ThumbnailLinks | ||
import com.piikii.application.domain.place.OriginPlace | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class UrlClientResponse( | ||
val isMapUser: String?, | ||
val isExist: Boolean?, | ||
val basicInfo: BasicInfo, | ||
val comment: Comment, | ||
val menuInfo: MenuInfo, | ||
val photo: Photo, | ||
) { | ||
fun toOriginPlace(url: String): OriginPlace { | ||
val fullAddress = "${basicInfo.address.region.newaddrfullname} ${basicInfo.address.newaddr.newaddrfull}".trim() | ||
return OriginPlace( | ||
originMapId = basicInfo.cid, | ||
url = url, | ||
thumbnailLinks = ThumbnailLinks(basicInfo.mainphotourl), | ||
address = fullAddress, | ||
phoneNumber = basicInfo.phonenum, | ||
starGrade = basicInfo.feedback.calculateStarGrade(), | ||
origin = Origin.LEMON, | ||
) | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class BasicInfo( | ||
val cid: Long, | ||
val placenamefull: String, | ||
val mainphotourl: String, | ||
val phonenum: String, | ||
val address: Address, | ||
val homepage: String, | ||
val category: Category, | ||
val feedback: Feedback, | ||
val openHour: OpenHour, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Address( | ||
val newaddr: NewAddress, | ||
val region: Region, | ||
val addrbunho: String? = null, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class NewAddress( | ||
val newaddrfull: String, | ||
val bsizonno: String, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Region( | ||
val name3: String, | ||
val fullname: String, | ||
val newaddrfullname: String, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Category( | ||
val catename: String, | ||
val cate1name: String, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Feedback( | ||
val scoresum: Int, | ||
val scorecnt: Int, | ||
) { | ||
fun calculateStarGrade(): Float? = if (scorecnt > 0) scoresum.toFloat() / scorecnt else null | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class OpenHour( | ||
val periodList: List<Period>, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Period( | ||
val periodName: String, | ||
val timeList: List<Time>, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Time( | ||
val timeName: String, | ||
val timeSE: String, | ||
val dayOfWeek: String, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Comment( | ||
val kamapComntcnt: Int, | ||
val scoresum: Int, | ||
val scorecnt: Int, | ||
val list: List<CommentItem>, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class CommentItem( | ||
val contents: String, | ||
val point: Int, | ||
val username: String, | ||
val date: String, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class MenuInfo( | ||
val menuList: List<MenuItem>, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class MenuItem( | ||
val price: String, | ||
val menu: String, | ||
val desc: String, | ||
val img: String, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Photo( | ||
val photoCount: Int, | ||
val photoList: List<PhotoItem>, | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class PhotoItem( | ||
val photoid: String, | ||
val orgurl: String, | ||
) | ||
} |
37 changes: 37 additions & 0 deletions
37
...ii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/adapter/LemonUrlClient.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,37 @@ | ||
package com.piikii.output.web.lemon.adapter | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.piikii.application.domain.place.OriginPlace | ||
import com.piikii.application.port.output.web.UrlClient | ||
import com.piikii.common.exception.ExceptionCode | ||
import com.piikii.common.exception.PiikiiException | ||
import com.piikii.output.web.lemon.UrlClientResponse | ||
import com.piikii.output.web.lemon.util.SaltAdditive | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.client.RestClient | ||
|
||
@Component | ||
class LemonUrlClient( | ||
private val saltAdditive: SaltAdditive, | ||
private val objectMapper: ObjectMapper, | ||
) : UrlClient { | ||
override fun get(url: String): OriginPlace { | ||
val saltedUrl = saltAdditive.execute(url) | ||
val response = fetchResponse(saltedUrl) | ||
val placeResponse = parseResponse(response) | ||
return placeResponse.toOriginPlace(url) | ||
} | ||
|
||
private fun fetchResponse(url: String): String { | ||
val client = RestClient.builder().baseUrl(url).build() | ||
return client.get().retrieve().body(String::class.java) ?: throw PiikiiException( | ||
exceptionCode = ExceptionCode.URL_PROCESS_ERROR, | ||
detailMessage = "url : $url", | ||
) | ||
} | ||
|
||
private fun parseResponse(response: String): UrlClientResponse { | ||
return objectMapper.readValue(response) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/config/LemonProperties.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.piikii.output.web.lemon.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties(prefix = "lemon") | ||
data class LemonProperties( | ||
val baseUrl: String, | ||
val salt: String, | ||
) |
17 changes: 17 additions & 0 deletions
17
piikii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/util/SaltAdditive.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,17 @@ | ||
package com.piikii.output.web.lemon.util | ||
|
||
import com.piikii.output.web.lemon.config.LemonProperties | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SaltAdditive( | ||
private val lemonProperties: LemonProperties, | ||
) { | ||
fun execute(url: String): String { | ||
val regex = """(${lemonProperties.baseUrl})(\d+)""".toRegex() | ||
return regex.replace(url) { matchResult -> | ||
val (baseUrl, id) = matchResult.destructured | ||
"$baseUrl${lemonProperties.salt}$id" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
piikii-output-web/lemon/src/main/resources/lemon-config/application.yml
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,3 @@ | ||
lemon: | ||
base-url: ${LEMON_BASE_URL} | ||
salt: ${LEMON_SALT} |
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