Skip to content

Commit

Permalink
feat: 지역 리스트 조회 api (#83)
Browse files Browse the repository at this point in the history
* feat: 대표 지역 정보 저장

* feat: 대표 지역 조회 로직 추가

* feat: 대표 지역 조회 API 추가
  • Loading branch information
TaeyeonRoyce authored Oct 17, 2024
1 parent 76bf8fe commit 93e9674
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server-profile-submodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.celuveat.common.adapter.out.aws

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "aws.cloudfront")
data class CloudFrontProperty(
val domain: String,
)
13 changes: 13 additions & 0 deletions src/main/kotlin/com/celuveat/region/adapter/in/rest/RegionApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.celuveat.region.adapter.`in`.rest

import com.celuveat.region.adapter.`in`.rest.response.RepresentativeRegionResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping

@Tag(name = "지역 API")
interface RegionApi {
@Operation(summary = "대표 지역 조회")
@GetMapping("/regions/representative")
fun readRepresentativeRegions(): List<RepresentativeRegionResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.celuveat.region.adapter.`in`.rest

import com.celuveat.region.adapter.`in`.rest.response.RepresentativeRegionResponse
import com.celuveat.region.application.port.`in`.ReadRepresentativeRegionsUseCase
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RequestMapping("/regions")
@RestController
class RegionController(
private val readRepresentativeRegionsUseCase: ReadRepresentativeRegionsUseCase,
) : RegionApi {

@GetMapping("/representative")
override fun readRepresentativeRegions(): List<RepresentativeRegionResponse> {
return readRepresentativeRegionsUseCase.readRepresentativeRegions()
.map { RepresentativeRegionResponse.from(it) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.celuveat.region.adapter.`in`.rest.response

import com.celuveat.region.application.port.`in`.result.RepresentativeRegionResult

data class RepresentativeRegionResponse(
val name: String,
val imageUrl: String,
) {
companion object {
fun from(result: RepresentativeRegionResult): RepresentativeRegionResponse {
return RepresentativeRegionResponse(
name = result.name,
imageUrl = result.imageUrl,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ package com.celuveat.region.adapter.out.persistence
import com.celuveat.common.annotation.Adapter
import com.celuveat.region.adapter.out.persistence.entity.RegionJpaRepository
import com.celuveat.region.adapter.out.persistence.entity.RegionPersistenceMapper
import com.celuveat.region.adapter.out.static.RegionStaticRepository
import com.celuveat.region.application.port.`in`.result.RepresentativeRegionResult
import com.celuveat.region.application.port.out.ReadRegionPort
import com.celuveat.region.domain.Region

@Adapter
class RegionPersistenceAdapter(
private val regionJpaRepository: RegionJpaRepository,
private val regionStaticRepository: RegionStaticRepository,
private val regionPersistenceMapper: RegionPersistenceMapper,
) : ReadRegionPort {
override fun readByName(name: String): List<Region> {
val regions = regionJpaRepository.readByNameContains(name)
return regions.map { regionPersistenceMapper.toDomain(it) }
}

override fun readRepresentativeRegions(): List<RepresentativeRegionResult> {
return regionStaticRepository.readRepresentativeRegions()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.celuveat.region.adapter.out.static

import com.celuveat.common.adapter.out.aws.CloudFrontProperty
import com.celuveat.common.annotation.Adapter
import com.celuveat.region.application.port.`in`.result.RepresentativeRegionResult

@Adapter
class RegionStaticRepository(
property: CloudFrontProperty,
) {
private val representedRegions: List<RepresentativeRegionResult> = listOf(
RepresentativeRegionResult("잠실", "${property.domain}/regions/jamsil.webp"),
RepresentativeRegionResult("성수", "${property.domain}/regions/seongsu.webp"),
RepresentativeRegionResult("홍대", "${property.domain}/regions/hongdae.webp"),
RepresentativeRegionResult("을지로", "${property.domain}/regions/euljiro.webp"),
RepresentativeRegionResult("압구정", "${property.domain}/regions/apgujeong.webp"),
RepresentativeRegionResult("여의도", "${property.domain}/regions/yeouido.webp"),
RepresentativeRegionResult("이태원", "${property.domain}/regions/itaewon.webp"),
)

fun readRepresentativeRegions(): List<RepresentativeRegionResult> {
return representedRegions
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.celuveat.region.application

import com.celuveat.region.application.port.`in`.ReadRepresentativeRegionsUseCase
import com.celuveat.region.application.port.`in`.result.RepresentativeRegionResult
import com.celuveat.region.application.port.out.ReadRegionPort
import org.springframework.stereotype.Service

@Service
class RegionQueryService(
private val readRegionPort: ReadRegionPort,
) : ReadRepresentativeRegionsUseCase {

override fun readRepresentativeRegions(): List<RepresentativeRegionResult> {
return readRegionPort.readRepresentativeRegions()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.celuveat.region.application.port.`in`

import com.celuveat.region.application.port.`in`.result.RepresentativeRegionResult

interface ReadRepresentativeRegionsUseCase {
fun readRepresentativeRegions(): List<RepresentativeRegionResult>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.celuveat.region.application.port.`in`.result

data class RepresentativeRegionResult(
val name: String,
val imageUrl: String,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.celuveat.region.application.port.out

import com.celuveat.region.application.port.`in`.result.RepresentativeRegionResult
import com.celuveat.region.domain.Region

interface ReadRegionPort {
fun readByName(name: String): List<Region>
fun readRepresentativeRegions(): List<RepresentativeRegionResult>
}

0 comments on commit 93e9674

Please sign in to comment.