Skip to content

Commit 942e82a

Browse files
committed
feat: PlaceRepository에 api 호출 메서드를 구현
1 parent 505ac4e commit 942e82a

4 files changed

Lines changed: 148 additions & 1 deletion

File tree

data/place/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ android {
1818
dependencies {
1919
implementation(projects.core.util)
2020
implementation(projects.data.domain)
21+
implementation(projects.data.remote)
2122
implementation(projects.domain.place)
2223

2324
testImplementation(libs.kotlinx.coroutines.test)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.ku_stacks.ku_ring.place.mapper
2+
3+
import com.ku_stacks.ku_ring.domain.Place
4+
import com.ku_stacks.ku_ring.domain.PlaceCategory
5+
import com.ku_stacks.ku_ring.domain.PlaceFacility
6+
import com.ku_stacks.ku_ring.domain.PlaceOperationHours
7+
import com.ku_stacks.ku_ring.remote.place.response.PlaceBuildingDetailResponse
8+
import com.ku_stacks.ku_ring.remote.place.response.PlaceBuildingResponse
9+
import com.ku_stacks.ku_ring.remote.place.response.PlaceCampusPlaceResponse
10+
import com.ku_stacks.ku_ring.remote.place.response.PlaceCategoryResponse
11+
import com.ku_stacks.ku_ring.remote.place.response.PlaceOperatingHoursResponse
12+
13+
internal fun PlaceBuildingResponse.toDomain() = Place(
14+
id = id.toString(),
15+
name = name,
16+
category = "",
17+
address = address,
18+
latitude = latitude,
19+
longitude = longitude,
20+
priority = Place.Priority.MIDDLE,
21+
)
22+
23+
internal fun PlaceBuildingDetailResponse.toDomain() = Place(
24+
id = id.toString(),
25+
name = name,
26+
category = "",
27+
address = address,
28+
latitude = latitude,
29+
longitude = longitude,
30+
priority = Place.Priority.MIDDLE,
31+
imageUrl = imageUrl,
32+
operationHours = currentOperatingHours?.toDomain(),
33+
facilities = campusPlaces.map { it.toDomain() },
34+
)
35+
36+
internal fun PlaceCampusPlaceResponse.toDomain() = PlaceFacility(
37+
name = name,
38+
category = categoryKorName,
39+
location = listOfNotNull(floor, locationDetail).joinToString(" ").ifBlank { null },
40+
operationHours = currentOperatingHours?.toDomain(),
41+
id = id,
42+
imageUrl = imageUrl,
43+
quantity = quantity,
44+
externalUrl = externalUrl,
45+
)
46+
47+
internal fun PlaceOperatingHoursResponse.toDomain() = PlaceOperationHours(
48+
current = toDisplayText(),
49+
)
50+
51+
private fun PlaceOperatingHoursResponse.toDisplayText(): String = when (status) {
52+
"OPEN_24_HOURS" -> "24시간 운영"
53+
"CLOSED" -> "휴무"
54+
else -> if (opensAt != null && closesAt != null) "$opensAt - $closesAt" else "-"
55+
}
56+
57+
internal fun PlaceCategoryResponse.toDomain() = PlaceCategory(
58+
name = name,
59+
korName = korName,
60+
displayOrder = displayOrder,
61+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,60 @@
11
package com.ku_stacks.ku_ring.place.repository
22

33
import com.ku_stacks.ku_ring.domain.Place
4+
import com.ku_stacks.ku_ring.domain.PlaceCategory
5+
import com.ku_stacks.ku_ring.domain.PlaceFacility
46
import com.ku_stacks.ku_ring.domain.place.repository.PlaceRepository
57
import com.ku_stacks.ku_ring.place.datasource.PlaceDataSource
68
import com.ku_stacks.ku_ring.place.mapper.toDomain
9+
import com.ku_stacks.ku_ring.remote.place.PlaceClient
710
import javax.inject.Inject
811

912
class PlaceRepositoryImpl @Inject constructor(
1013
private val placeDataSource: PlaceDataSource,
14+
private val placeClient: PlaceClient,
1115
): PlaceRepository {
1216
override suspend fun getPlaces(): List<Place> {
1317
return placeDataSource.getJsonPlaces().map { it.toDomain() }
1418
}
19+
20+
override suspend fun getPlaceBuildingDetail(buildingId: Long): Result<Place> = runCatching {
21+
val response = placeClient.fetchBuildingDetail(buildingId)
22+
when {
23+
response.isSuccessAndDataExists -> response.data!!.toDomain()
24+
else -> throw IllegalStateException(response.resultMsg)
25+
}
26+
}
27+
28+
override suspend fun searchPlaceBuildings(keyword: String): Result<List<Place>> = runCatching {
29+
val response = placeClient.searchBuildings(keyword)
30+
when {
31+
response.isSuccessAndDataExists -> response.data!!.buildings.map { it.toDomain() }
32+
else -> throw IllegalStateException(response.resultMsg)
33+
}
34+
}
35+
36+
override suspend fun getPlaceBuildings(): Result<List<Place>> = runCatching {
37+
val response = placeClient.fetchBuildings()
38+
when {
39+
response.isSuccessAndDataExists -> response.data!!.buildings.map { it.toDomain() }
40+
else -> throw IllegalStateException(response.resultMsg)
41+
}
42+
}
43+
44+
override suspend fun getPlaceCampusPlaces(category: String): Result<List<PlaceFacility>> =
45+
runCatching {
46+
val response = placeClient.fetchCampusPlaces(category)
47+
when {
48+
response.isSuccessAndDataExists -> response.data!!.campusPlaces.map { it.toDomain() }
49+
else -> throw IllegalStateException(response.resultMsg)
50+
}
51+
}
52+
53+
override suspend fun getPlaceCategories(): Result<List<PlaceCategory>> = runCatching {
54+
val response = placeClient.fetchCategories()
55+
when {
56+
response.isSuccessAndDataExists -> response.data!!.categories.map { it.toDomain() }
57+
else -> throw IllegalStateException(response.resultMsg)
58+
}
59+
}
1560
}
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
11
package com.ku_stacks.ku_ring.domain.place.repository
22

33
import com.ku_stacks.ku_ring.domain.Place
4+
import com.ku_stacks.ku_ring.domain.PlaceCategory
5+
import com.ku_stacks.ku_ring.domain.PlaceFacility
46

57
interface PlaceRepository {
68
suspend fun getPlaces(): List<Place>
7-
}
9+
10+
/**
11+
* 캠퍼스맵 건물의 상세 정보를 가져온다.
12+
*
13+
* @param buildingId 건물 ID
14+
* @return 정상 처리 시 건물 상세 정보를 [Result]에 담아 반환. 실패 시 [Result.Failure]
15+
*/
16+
suspend fun getPlaceBuildingDetail(buildingId: Long): Result<Place>
17+
18+
/**
19+
* 키워드로 캠퍼스맵 건물을 검색한다.
20+
*
21+
* @param keyword 검색 키워드
22+
* @return 정상 처리 시 검색된 건물 목록을 [Result]에 담아 반환. 실패 시 [Result.Failure]
23+
*/
24+
suspend fun searchPlaceBuildings(keyword: String): Result<List<Place>>
25+
26+
/**
27+
* 캠퍼스맵 전체 건물 목록을 가져온다.
28+
*
29+
* @return 정상 처리 시 건물 목록을 [Result]에 담아 반환. 실패 시 [Result.Failure]
30+
*/
31+
suspend fun getPlaceBuildings(): Result<List<Place>>
32+
33+
/**
34+
* 카테고리에 해당하는 캠퍼스맵 시설 목록을 가져온다.
35+
*
36+
* @param category 시설 카테고리
37+
* @return 정상 처리 시 시설 목록을 [Result]에 담아 반환. 실패 시 [Result.Failure]
38+
*/
39+
suspend fun getPlaceCampusPlaces(category: String): Result<List<PlaceFacility>>
40+
41+
/**
42+
* 캠퍼스맵 카테고리 목록을 가져온다.
43+
*
44+
* @return 정상 처리 시 카테고리 목록을 [Result]에 담아 반환. 실패 시 [Result.Failure]
45+
*/
46+
suspend fun getPlaceCategories(): Result<List<PlaceCategory>>
47+
}

0 commit comments

Comments
 (0)