Skip to content

Commit 3e34061

Browse files
authored
Merge pull request #48 from boostcampwm-2022/modify/codereview
[PR] ๋ฉ˜ํ† ๋‹˜ ๋ฆฌ๋ทฐ ๋ฐ›์€ ๋ถ€๋ถ„ ์ˆ˜์ •
2 parents e60893b + d2e62d2 commit 3e34061

File tree

12 files changed

+104
-95
lines changed

12 files changed

+104
-95
lines changed

โ€Ždata/src/main/java/com/stop/data/di/DataSourceModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ internal interface DataSourceModule {
3232
@Singleton
3333
fun provideAlarmLocalDataSource(
3434
alarmLocalDataSourceImpl: AlarmLocalDataSourceImpl
35-
): AlarmLocalDataSource
36-
35+
): AlarmLocalDataSourc
36+
3737
}

โ€Ždata/src/main/java/com/stop/data/di/RepositoryModule.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ internal interface RepositoryModule {
2424

2525
@Binds
2626
@Singleton
27-
fun provideNearPlaceRepository(nearPlaceRepositoryImpl: NearPlaceRepositoryImpl): NearPlaceRepository
27+
fun provideNearPlaceRepository(
28+
nearPlaceRepositoryImpl: NearPlaceRepositoryImpl
29+
): NearPlaceRepository
30+
2831

2932
@Binds
3033
@Singleton
3134
fun provideAlarmRepository(alarmRepositoryImpl: AlarmRepositoryImpl): AlarmRepository
35+
3236
}

โ€Ždata/src/main/java/com/stop/data/remote/source/nearplace/NearPlaceRemoteDataSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import com.stop.data.model.nearplace.Place
55
interface NearPlaceRemoteDataSource {
66

77
suspend fun getNearPlaces(
8-
version : Int,
8+
version: Int,
99
searchKeyword: String,
1010
centerLon: Double,
1111
centerLat: Double,
1212
appKey: String
13-
): List<Place>
13+
): Result<List<Place>>
1414

1515
}

โ€Ždata/src/main/java/com/stop/data/remote/source/nearplace/NearPlaceRemoteDataSourceImpl.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@ internal class NearPlaceRemoteDataSourceImpl @Inject constructor(
1515
centerLon: Double,
1616
centerLat: Double,
1717
appKey: String
18-
): List<Place> {
18+
): Result<List<Place>> {
1919
val result = nearPlaceApiService.getNearPlaces(
2020
version,
2121
searchKeyword,
2222
centerLon,
2323
centerLat,
2424
appKey
2525
)
26-
27-
when (result) {
28-
is NetworkResult.Failure -> {
29-
throw Exception(result.message)
30-
}
31-
is NetworkResult.Success -> {
32-
return result.data.searchPoiInfo.pois.poi.map {
33-
it.toRepositoryModel()
26+
return runCatching {
27+
when (result) {
28+
is NetworkResult.Failure -> {
29+
throw Exception(result.message)
30+
}
31+
is NetworkResult.Success -> {
32+
result.data.searchPoiInfo.pois.poi.map {
33+
it.toRepositoryModel()
34+
}
35+
}
36+
is NetworkResult.NetworkError -> {
37+
throw result.exception
38+
}
39+
is NetworkResult.Unexpected -> {
40+
throw result.exception
3441
}
35-
}
36-
is NetworkResult.NetworkError -> {
37-
throw result.exception
38-
}
39-
is NetworkResult.Unexpected -> {
40-
throw result.exception
4142
}
4243
}
4344
}

โ€Ždata/src/main/java/com/stop/data/repository/NearPlaceRepositoryImpl.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package com.stop.data.repository
33
import com.stop.data.remote.source.nearplace.NearPlaceRemoteDataSource
44
import com.stop.domain.model.nearplace.Place
55
import com.stop.domain.repository.NearPlaceRepository
6-
import kotlinx.coroutines.flow.Flow
7-
import kotlinx.coroutines.flow.flow
86
import javax.inject.Inject
97

108
internal class NearPlaceRepositoryImpl @Inject constructor(
@@ -17,18 +15,20 @@ internal class NearPlaceRepositoryImpl @Inject constructor(
1715
centerLon: Double,
1816
centerLat: Double,
1917
appKey: String
20-
): Flow<List<Place>> = flow {
21-
emit(
22-
nearPlaceRemoteDataSource.getNearPlaces(
23-
version,
24-
searchKeyword,
25-
centerLon,
26-
centerLat,
27-
appKey
28-
).map {
18+
): List<Place> {
19+
nearPlaceRemoteDataSource.getNearPlaces(
20+
version,
21+
searchKeyword,
22+
centerLon,
23+
centerLat,
24+
appKey
25+
).onSuccess { places ->
26+
return places.map {
2927
it.toUseCaseModel()
3028
}
31-
)
29+
}.onFailure {
30+
throw it
31+
}
32+
return emptyList()
3233
}
33-
3434
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.stop.domain.repository
22

33
import com.stop.domain.model.nearplace.Place
4-
import kotlinx.coroutines.flow.Flow
54

65
interface NearPlaceRepository {
76

@@ -11,6 +10,6 @@ interface NearPlaceRepository {
1110
centerLon: Double,
1211
centerLat: Double,
1312
appKey: String
14-
): Flow<List<Place>>
13+
): List<Place>
1514

1615
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.stop.domain.usecase.nearplace
22

33
import com.stop.domain.model.nearplace.Place
4-
import kotlinx.coroutines.flow.Flow
54

65
interface GetNearPlacesUseCase {
76

@@ -11,6 +10,6 @@ interface GetNearPlacesUseCase {
1110
centerLon: Double,
1211
centerLat: Double,
1312
appKey: String
14-
) : Flow<List<Place>>
13+
): List<Place>
1514

1615
}

โ€Ždomain/src/main/java/com/stop/domain/usecase/nearplace/GetNearPlacesUseCaseImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.stop.domain.usecase.nearplace
22

33
import com.stop.domain.model.nearplace.Place
44
import com.stop.domain.repository.NearPlaceRepository
5-
import kotlinx.coroutines.flow.Flow
65
import javax.inject.Inject
76

87
internal class GetNearPlacesUseCaseImpl @Inject constructor(
@@ -15,7 +14,7 @@ internal class GetNearPlacesUseCaseImpl @Inject constructor(
1514
centerLon: Double,
1615
centerLat: Double,
1716
appKey: String
18-
): Flow<List<Place>> =
17+
): List<Place> =
1918
nearPlaceRepository.getNearPlaces(
2019
version,
2120
searchKeyword,

โ€Žpresentation/src/main/java/com/stop/ui/map/MapFragment.kt

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,22 @@ class MapFragment : Fragment() {
256256
}
257257

258258
private fun observeClickCurrentLocation() {
259-
viewLifecycleOwner.lifecycleScope.launch {
260-
launch {
261-
placeSearchViewModel.clickCurrentLocation
262-
.flowWithLifecycle(viewLifecycleOwner.lifecycle)
263-
.collect {
264-
val currentLocation = placeSearchViewModel.currentLocation
265-
val currentTMapPoint = TMapPoint(currentLocation.latitude, currentLocation.longitude)
266-
267-
tMapView.setCenterPoint(currentTMapPoint.latitude, currentTMapPoint.longitude)
268-
269-
setPanel(currentTMapPoint)
270-
271-
makeMarker(
272-
MARKER,
273-
R.drawable.ic_baseline_location_on_32,
274-
currentTMapPoint
275-
)
276-
}
277-
}
259+
lifecycleScope.launch {
260+
placeSearchViewModel.clickCurrentLocation
261+
.flowWithLifecycle(viewLifecycleOwner.lifecycle)
262+
.collect {
263+
val currentLocation = placeSearchViewModel.currentLocation
264+
val currentTmapPoint = TMapPoint(currentLocation.latitude, currentLocation.longitude)
265+
266+
tMapView.setCenterPoint(currentTmapPoint.latitude, currentTmapPoint.longitude)
267+
268+
setPanel(currentTmapPoint)
269+
270+
makeMarker(
271+
R.drawable.ic_baseline_location_on_32,
272+
currentTmapPoint
273+
)
274+
}
278275
}
279276
}
280277

โ€Žpresentation/src/main/java/com/stop/ui/placesearch/NearPlaceAdapter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class NearPlaceAdapter : ListAdapter<Place, NearPlaceAdapter.ViewHolder>(diffUti
1515
class ViewHolder(private val binding: ItemNearPlaceBinding) : RecyclerView.ViewHolder(binding.root) {
1616
fun bind(place: Place) {
1717
binding.place = place
18+
binding.executePendingBindings()
1819
}
1920
}
2021

0 commit comments

Comments
ย (0)