diff --git a/application/src/main/kotlin/com/threedays/application/user/port/inbound/QueryLocation.kt b/application/src/main/kotlin/com/threedays/application/user/port/inbound/QueryLocation.kt new file mode 100644 index 0000000..bf6c531 --- /dev/null +++ b/application/src/main/kotlin/com/threedays/application/user/port/inbound/QueryLocation.kt @@ -0,0 +1,9 @@ +package com.threedays.application.user.port.inbound + +import com.threedays.domain.user.entity.Location + +interface QueryLocation { + + fun findAll(): List + +} diff --git a/application/src/main/kotlin/com/threedays/application/user/service/LocationService.kt b/application/src/main/kotlin/com/threedays/application/user/service/LocationService.kt new file mode 100644 index 0000000..e889aef --- /dev/null +++ b/application/src/main/kotlin/com/threedays/application/user/service/LocationService.kt @@ -0,0 +1,17 @@ +package com.threedays.application.user.service + +import com.threedays.application.user.port.inbound.QueryLocation +import com.threedays.domain.user.entity.Location +import com.threedays.domain.user.repository.LocationQueryRepository +import org.springframework.stereotype.Service + +@Service +class LocationService( + private val locationQueryRepository: LocationQueryRepository, +) : QueryLocation { + + override fun findAll(): List { + return locationQueryRepository.findAll() + } + +} diff --git a/bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/location/LocationsController.kt b/bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/location/LocationsController.kt new file mode 100644 index 0000000..d029f68 --- /dev/null +++ b/bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/location/LocationsController.kt @@ -0,0 +1,25 @@ +package com.threedays.bootstrap.api.location + +import com.threedays.application.user.port.inbound.QueryLocation +import com.threedays.oas.api.LocationsApi +import com.threedays.oas.model.Location +import com.threedays.oas.model.OSType +import org.springframework.http.ResponseEntity +import org.springframework.stereotype.Controller + +@Controller +class LocationsController( + private val queryLocation: QueryLocation, +) : LocationsApi { + override fun locationsGet(xOSType: OSType): ResponseEntity> { + val locations = queryLocation.findAll().map { + Location( + id = it.id.value, + region = it.region.value, + subRegion = it.subRegion.value, + ) + }.toList() + return ResponseEntity.ok(locations) + } + +} diff --git a/domain/src/main/kotlin/com/threedays/domain/user/repository/LocationRepository.kt b/domain/src/main/kotlin/com/threedays/domain/user/repository/LocationQueryRepository.kt similarity index 64% rename from domain/src/main/kotlin/com/threedays/domain/user/repository/LocationRepository.kt rename to domain/src/main/kotlin/com/threedays/domain/user/repository/LocationQueryRepository.kt index f170121..f7bee9a 100644 --- a/domain/src/main/kotlin/com/threedays/domain/user/repository/LocationRepository.kt +++ b/domain/src/main/kotlin/com/threedays/domain/user/repository/LocationQueryRepository.kt @@ -4,4 +4,8 @@ import com.threedays.domain.user.entity.Location import com.threedays.domain.user.vo.LocationId import com.threedays.support.common.base.domain.QueryRepository -interface LocationRepository: QueryRepository +interface LocationQueryRepository: QueryRepository { + + fun findAll(): List + +} diff --git a/infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/LocationQueryPersistenceAdapter.kt b/infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/LocationQueryPersistenceAdapter.kt new file mode 100644 index 0000000..3ea13d8 --- /dev/null +++ b/infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/LocationQueryPersistenceAdapter.kt @@ -0,0 +1,29 @@ +package com.threedays.persistence.user.adapter + +import com.threedays.domain.user.entity.Location +import com.threedays.domain.user.repository.LocationQueryRepository +import com.threedays.domain.user.vo.LocationId +import com.threedays.persistence.user.entity.LocationEntity +import org.jetbrains.exposed.sql.ResultRow +import org.jetbrains.exposed.sql.selectAll +import org.springframework.stereotype.Repository + +@Repository +class LocationQueryPersistenceAdapter : LocationQueryRepository { + override fun findAll(): List = LocationEntity + .selectAll() + .toList() + .map { it.toLocation() } + + override fun find(id: LocationId): Location? = LocationEntity + .selectAll() + .where { LocationEntity.id eq id.value } + .singleOrNull() + ?.toLocation() +} + +private fun ResultRow.toLocation() = Location( + id = LocationId(this[LocationEntity.id].value), + region = Location.Region(this[LocationEntity.region]), + subRegion = Location.SubRegion(this[LocationEntity.subRegion]), +)