Skip to content

Commit

Permalink
implement find all locations
Browse files Browse the repository at this point in the history
  • Loading branch information
dojinyou committed Sep 16, 2024
1 parent 94f275b commit 99ba769
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.threedays.application.user.port.inbound

import com.threedays.domain.user.entity.Location

interface QueryLocation {

fun findAll(): List<Location>

}
Original file line number Diff line number Diff line change
@@ -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<Location> {
return locationQueryRepository.findAll()
}

}
Original file line number Diff line number Diff line change
@@ -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<List<Location>> {
val locations = queryLocation.findAll().map {
Location(
id = it.id.value,
region = it.region.value,
subRegion = it.subRegion.value,
)
}.toList()
return ResponseEntity.ok(locations)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location, LocationId>
interface LocationQueryRepository: QueryRepository<Location, LocationId> {

fun findAll(): List<Location>

}
Original file line number Diff line number Diff line change
@@ -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<Location> = 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]),
)

0 comments on commit 99ba769

Please sign in to comment.