Skip to content

Commit

Permalink
fix: 바뀐 데이터 형식도 넣을 수 있게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
korECM committed Mar 20, 2023
1 parent 8d2b333 commit 7dbc5f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/main/kotlin/zip/cafe/util/importdata/ImportData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import zip.cafe.entity.Point
import zip.cafe.entity.cafe.Cafe
import zip.cafe.util.createPoint
import zip.cafe.util.importdata.item.ImportDataItem
import zip.cafe.util.logger
import java.io.FileReader
import java.io.Reader
import javax.annotation.PostConstruct
Expand All @@ -20,7 +21,7 @@ class ImportData(
) {

@PostConstruct
fun importData() {
fun importDataFn() {
val objectMapper = jacksonObjectMapper()
val reader: Reader = FileReader("/Users/korecm/Programming/Study/cafe-server/cafe/data.json")

Expand All @@ -33,8 +34,6 @@ class ImportData(
dataList += data
}
}

println("import data")
importService.importData(dataList)
}

Expand All @@ -44,13 +43,18 @@ class ImportData(
private val em: EntityManager,
) {
fun importData(dataList: List<ImportDataItem>) {
dataList.forEach { data ->
createCafe(
name = data.name,
address = data.fullAddress,
location = createPoint(longitude = data.longitude, latitude = data.latitude),
openingHours = data.businessHours
)
val chunked = dataList.chunked(100)
val numberOfChunk = chunked.size
chunked.forEachIndexed { index, data ->
logger().info("Importing data: $index / $numberOfChunk")
data.forEach {
createCafe(
name = it.name,
address = it.fullAddress,
location = createPoint(longitude = it.longitude, latitude = it.latitude),
openingHours = it.businessHours
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package zip.cafe.util.importdata.item

import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class ImportDataItem(
val businessHours: String,
val category: String,
Expand Down

0 comments on commit 7dbc5f8

Please sign in to comment.