Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import java.util.UUID

@Repository
interface LocationElasticRepository: ElasticsearchRepository<LocationDocument, UUID> {

fun findFirstByOrderByEditedAtDesc(): LocationDocument?
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import com.retrip.map.domain.entity.Location
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.UUID

interface LocationQueryRepository {
fun findLocations(id: UUID?, page: Pageable): Page<LocationResponse>
fun findLocationsByEditedAt( editedAt: LocalDate): List<Location>
fun findLocationsByEditedAt( editedAt: LocalDateTime): List<Location>
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.retrip.map.infra.adapter.`in`.batch

import co.elastic.clients.elasticsearch.ElasticsearchClient
import com.retrip.map.application.out.repository.LocationElasticRepository
import com.retrip.map.application.out.repository.LocationQueryRepository
import com.retrip.map.domain.entity.Location
import org.springframework.batch.item.ItemReader
import org.springframework.stereotype.Component
import java.time.LocalDate
import java.time.LocalDateTime

@Component
class MapReader(
val locationQueryRepository: LocationQueryRepository

private val locationQueryRepository: LocationQueryRepository,
private val locationElasticRepository: LocationElasticRepository
): ItemReader<List<Location>> {
override fun read(): List<Location>? {
println("TEST")
return locationQueryRepository.findLocationsByEditedAt(LocalDate.now())
val lastUpdateDocument = locationElasticRepository.findFirstByOrderByEditedAtDesc()
return locationQueryRepository.findLocationsByEditedAt(lastUpdateDocument?.editedAt ?: LocalDateTime.now())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.springframework.data.domain.PageImpl
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Repository
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*


Expand Down Expand Up @@ -51,13 +52,10 @@ class LocationQuerydslRepository(
return PageImpl(locations, page, count ?: 0)
}

override fun findLocationsByEditedAt(editedAt: LocalDate): List<Location> {
val startOfDay = editedAt.atStartOfDay()
val endOfDay = editedAt.plusDays(1).atStartOfDay()
override fun findLocationsByEditedAt(editedAt: LocalDateTime): List<Location> {
return query.selectFrom(location)
.where(
location.editedAt.goe(startOfDay),
location.createdAt.lt(endOfDay)
location.editedAt.gt(editedAt)
).fetch()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import jakarta.persistence.Id
import org.springframework.data.elasticsearch.annotations.Document
import org.springframework.data.elasticsearch.annotations.Field
import org.springframework.data.elasticsearch.annotations.FieldType
import java.time.LocalDateTime
import java.util.*

@Document(indexName = "locations")
Expand All @@ -28,7 +29,11 @@ data class LocationDocument(
@Field(type = FieldType.Double)
val latitude: Double?,
@Field(type = FieldType.Double)
val longitude: Double?
val longitude: Double?,
@Field(type = FieldType.Date)
val createdAt: LocalDateTime?,
@Field(type = FieldType.Date)
val editedAt: LocalDateTime?,
) {
companion object {
fun of(location: Location): LocationDocument {
Expand All @@ -42,6 +47,8 @@ data class LocationDocument(
location.address?.roadAddress,
location.geoPoint?.latitude,
location.geoPoint?.longitude,
location.createdAt,
location.editedAt
)
}
}
Expand Down