-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
application/src/main/kotlin/com/threedays/application/user/port/inbound/QueryLocation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
application/src/main/kotlin/com/threedays/application/user/service/LocationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/location/LocationsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...src/main/kotlin/com/threedays/persistence/user/adapter/LocationQueryPersistenceAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]), | ||
) |