From fd2920f8ce821ea69899185e33666da9605eee4f Mon Sep 17 00:00:00 2001 From: Diger Date: Fri, 6 Sep 2024 00:08:43 +0900 Subject: [PATCH] hotfix: Lemon Response Format --- .../lemon/adapter/LemonPlaceInfoResponse.kt | 131 ++++++++---------- 1 file changed, 56 insertions(+), 75 deletions(-) diff --git a/piikii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/adapter/LemonPlaceInfoResponse.kt b/piikii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/adapter/LemonPlaceInfoResponse.kt index 07e0d646..5395a362 100644 --- a/piikii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/adapter/LemonPlaceInfoResponse.kt +++ b/piikii-output-web/lemon/src/main/kotlin/com/piikii/output/web/lemon/adapter/LemonPlaceInfoResponse.kt @@ -10,29 +10,31 @@ import com.piikii.application.domain.place.OriginPlace @JsonIgnoreProperties(ignoreUnknown = true) data class LemonPlaceInfoResponse( - @JsonProperty("ismapuser") val isMapUser: String?, - @JsonProperty("isexist") val isExist: Boolean?, - @JsonProperty("basicinfo") val basicInfo: BasicInfo?, + val isMapUser: String?, + val isExist: Boolean?, + val basicInfo: BasicInfo?, val comment: Comment?, - @JsonProperty("menuinfo") val menuInfo: MenuInfo?, + val menuInfo: MenuInfo?, val photo: Photo?, ) { fun toOriginPlace(url: String): OriginPlace { requireNotNull(basicInfo) { "BasicInfo is required" } - val fullAddress = "${basicInfo.address.region.newAddrFullName} ${basicInfo.address.newAddr.newAddrFull}".trim() + val fullAddress = + "${basicInfo.address.region.fullname ?: ""} ${basicInfo.address.newaddr?.newaddrfull ?: ""}" + .trim() return OriginPlace( id = LongTypeId(0L), - name = basicInfo.name, + name = basicInfo.placenamefull, originMapId = OriginMapId.of(id = LongTypeId(basicInfo.cid), origin = Origin.LEMON), url = url, - thumbnailLinks = ThumbnailLinks(basicInfo.mainPhotoUrl), + thumbnailLinks = ThumbnailLinks(basicInfo.mainphotourl), address = fullAddress, - phoneNumber = basicInfo.phoneNumber, + phoneNumber = null, starGrade = basicInfo.feedback.calculateStarGrade(), - longitude = basicInfo.longitude, - latitude = basicInfo.latitude, - reviewCount = basicInfo.feedback.countOfBlogReview, - category = basicInfo.category.firstCategoryName, + longitude = basicInfo.wpointx?.toDouble(), + latitude = basicInfo.wpointy?.toDouble(), + reviewCount = basicInfo.feedback.blogrvwcnt, + category = basicInfo.category.cate1name, openingHours = basicInfo.openHour.toPrintFormat(), origin = Origin.LEMON, ) @@ -41,82 +43,71 @@ data class LemonPlaceInfoResponse( @JsonIgnoreProperties(ignoreUnknown = true) data class BasicInfo( val cid: Long, - @JsonProperty("placenamefull") val name: String, - @JsonProperty("mainphotourl") val mainPhotoUrl: String, - @JsonProperty("phonenum") val phoneNumber: String?, + val placenamefull: String, + val mainphotourl: String, val address: Address, val homepage: String?, + val wpointx: Int?, + val wpointy: Int?, val category: Category, val feedback: Feedback, - @JsonProperty("openhour") val openHour: OpenHour, - val tags: List?, - @JsonProperty("x") val longitude: Double?, - @JsonProperty("y") val latitude: Double?, + val openHour: OpenHour, ) @JsonIgnoreProperties(ignoreUnknown = true) data class Address( - @JsonProperty("newaddr") val newAddr: NewAddress, + val newaddr: NewAddress?, val region: Region, - @JsonProperty("addrbunho") val addrBunho: String?, + val addrbunho: String?, ) @JsonIgnoreProperties(ignoreUnknown = true) data class NewAddress( - @JsonProperty("newaddrfull") val newAddrFull: String, - @JsonProperty("bsizonno") val bsiZonNo: String, + val newaddrfull: String?, + val bsizonno: String?, ) @JsonIgnoreProperties(ignoreUnknown = true) data class Region( - val name3: String, - @JsonProperty("fullname") val fullName: String, - @JsonProperty("newaddrfullname") val newAddrFullName: String, + val name3: String?, + val fullname: String?, + val newaddrfullname: String?, ) @JsonIgnoreProperties(ignoreUnknown = true) data class Category( - @JsonProperty("catename") val firstCategoryName: String, - @JsonProperty("cate1name") val secondCategoryName: String, + val catename: String, + val cate1name: String, ) @JsonIgnoreProperties(ignoreUnknown = true) data class Feedback( - @JsonProperty("scoresum") val sumOfScore: Int = 0, - @JsonProperty("scorecnt") val countOfScore: Int = 0, - @JsonProperty("blogrvwcnt") val countOfBlogReview: Int = 0, - @JsonProperty("comntcnt") val countOfReviewComment: Int = 0, - @JsonProperty("allphotocnt") val countOfAllPhoto: Int = 0, - @JsonProperty("reviewphotocnt") val countOfPhotoReview: Int = 0, + val scoresum: Int = 0, + val scorecnt: Int = 0, + val blogrvwcnt: Int = 0, + val comntcnt: Int = 0, + val allphotocnt: Int = 0, ) { - fun calculateStarGrade(): Double? = if (countOfScore > 0) sumOfScore.toDouble() / countOfScore else null + fun calculateStarGrade(): Double? = if (scorecnt > 0) scoresum.toDouble() / scorecnt else null } @JsonIgnoreProperties(ignoreUnknown = true) data class OpenHour( - @JsonProperty("periodlist") val periodList: List?, - @JsonProperty("offdaylist") val offDayList: List?, + val periodList: List?, ) { fun toPrintFormat(): String? { - val openingHour = periodList?.firstOrNull { it.periodName == OPEN_HOUR_PERIOD_NAME }?.toPrintFormat() - val offDaySchedule = offDayList?.mapNotNull { it.toPrintFormat() }?.joinToString(JOINER) - return if (openingHour == null && offDaySchedule.isNullOrEmpty()) { - null - } else { - "$openingHour$JOINER$offDaySchedule".trim() - } + return periodList?.firstOrNull()?.toPrintFormat() } companion object { - const val OPEN_HOUR_PERIOD_NAME = "영업기간" const val JOINER = "\n" } } @JsonIgnoreProperties(ignoreUnknown = true) data class Period( - @JsonProperty("periodname") val periodName: String, - @JsonProperty("timelist") val timeList: List