Skip to content

Commit

Permalink
feat: Add Lemon Redirect Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Diger committed Sep 3, 2024
1 parent 32fe78f commit 99e0303
Showing 1 changed file with 71 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import com.piikii.application.domain.place.OriginPlace

@JsonIgnoreProperties(ignoreUnknown = true)
data class LemonPlaceInfoResponse(
val isMapUser: String? = null,
val isExist: Boolean? = null,
val basicInfo: BasicInfo? = null,
val comment: Comment? = null,
val menuInfo: MenuInfo? = null,
val photo: Photo? = null,
@JsonProperty("ismapuser") val isMapUser: String?,
@JsonProperty("isexist") val isExist: Boolean?,
@JsonProperty("basicinfo") val basicInfo: BasicInfo?,
val comment: Comment?,
@JsonProperty("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.newAddrFullName} ${basicInfo.address.newAddr.newAddrFull}".trim()
return OriginPlace(
id = LongTypeId(0L),
name = basicInfo.name,
Expand All @@ -41,83 +41,70 @@ 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? = null,
@JsonProperty("placenamefull") val name: String,
@JsonProperty("mainphotourl") val mainPhotoUrl: String,
@JsonProperty("phonenum") val phoneNumber: String?,
val address: Address,
val homepage: String? = null,
val homepage: String?,
val category: Category,
val feedback: Feedback,
val openHour: OpenHour,
val tags: List<String>? = null,
@JsonProperty("x")
val longitude: Double? = null,
@JsonProperty("y")
val latitude: Double? = null,
@JsonProperty("openhour") val openHour: OpenHour,
val tags: List<String>?,
@JsonProperty("x") val longitude: Double?,
@JsonProperty("y") val latitude: Double?,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Address(
val newaddr: NewAddress,
@JsonProperty("newaddr") val newAddr: NewAddress,
val region: Region,
val addrbunho: String? = null,
@JsonProperty("addrbunho") val addrBunho: String?,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class NewAddress(
val newaddrfull: String,
val bsizonno: String,
@JsonProperty("newaddrfull") val newAddrFull: String,
@JsonProperty("bsizonno") val bsiZonNo: String,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Region(
val name3: String,
val fullname: String,
val newaddrfullname: String,
@JsonProperty("fullname") val fullName: String,
@JsonProperty("newaddrfullname") val newAddrFullName: String,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Category(
@JsonProperty("catename")
val firstCategoryName: String,
@JsonProperty("cate1name")
val secondCategoryName: String,
@JsonProperty("catename") val firstCategoryName: String,
@JsonProperty("cate1name") val secondCategoryName: 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,
@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,
) {
fun calculateStarGrade(): Double? = if (countOfScore > 0) sumOfScore.toDouble() / countOfScore else null
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class OpenHour(
val periodList: List<Period>? = null,
val offdayList: List<Offday>? = null,
@JsonProperty("periodlist") val periodList: List<Period>?,
@JsonProperty("offdaylist") val offDayList: List<OffDay>?,
) {
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()
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()
}
}

companion object {
Expand All @@ -128,70 +115,74 @@ data class LemonPlaceInfoResponse(

@JsonIgnoreProperties(ignoreUnknown = true)
data class Period(
val periodName: String,
val timeList: List<Time>? = null,
@JsonProperty("periodname") val periodName: String,
@JsonProperty("timelist") val timeList: List<Time>?,
) {
fun toPrintFormat(): String? {
return timeList?.joinToString(OpenHour.JOINER) { "${it.timeName}: ${it.dayOfWeek} ${it.timeSE}" }
}
fun toPrintFormat(): String? =
timeList?.joinToString(OpenHour.JOINER) {
"${it.timeName}: ${it.dayOfWeek} ${it.timeSE}"
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class Time(
val timeName: String,
val timeSE: String,
val dayOfWeek: String,
@JsonProperty("timename") val timeName: String,
@JsonProperty("timese") val timeSE: String,
@JsonProperty("dayofweek") val dayOfWeek: String,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Offday(
val holidayName: String,
val weekAndDay: String,
val temporaryHolidays: String? = null,
data class OffDay(
@JsonProperty("holidayname") val holidayName: String,
@JsonProperty("weekandday") val weekAndDay: String,
@JsonProperty("temporaryholidays") val temporaryHolidays: String?,
) {
fun toPrintFormat(): String? {
return if (holidayName.isNotBlank() && weekAndDay.isNotBlank()) "$holidayName: $weekAndDay" else null
}
fun toPrintFormat(): String? =
if (holidayName.isNotBlank() && weekAndDay.isNotBlank()) {
"$holidayName: $weekAndDay"
} else {
null
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class Comment(
val kamapComntcnt: Int = 0,
val scoresum: Int = 0,
val scorecnt: Int = 0,
val list: List<CommentItem>? = null,
@JsonProperty("kamapcomntcnt") val kamapComntCnt: Int = 0,
@JsonProperty("scoresum") val scoreSum: Int = 0,
@JsonProperty("scorecnt") val scoreCnt: Int = 0,
val list: List<CommentItem>?,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class CommentItem(
val contents: String,
val point: Int,
val username: String,
@JsonProperty("username") val userName: String,
val date: String,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class MenuInfo(
val menuList: List<MenuItem>? = null,
@JsonProperty("menulist") val menuList: List<MenuItem>?,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class MenuItem(
val price: String? = null,
val menu: String? = null,
val desc: String? = null,
val img: String? = null,
val price: String?,
val menu: String?,
val desc: String?,
val img: String?,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Photo(
val photoCount: Int = 0,
val photoList: List<PhotoItem>? = null,
@JsonProperty("photocount") val photoCount: Int = 0,
@JsonProperty("photolist") val photoList: List<PhotoItem>?,
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class PhotoItem(
val photoid: String,
val orgurl: String,
@JsonProperty("photoid") val photoId: String,
@JsonProperty("orgurl") val orgUrl: String,
)
}

0 comments on commit 99e0303

Please sign in to comment.