File tree Expand file tree Collapse file tree 6 files changed +45
-47
lines changed
data/src/main/java/com/stop/data Expand file tree Collapse file tree 6 files changed +45
-47
lines changed Original file line number Diff line number Diff line change 1
1
package com.stop.data.di
2
2
3
+ import com.stop.data.remote.source.nearplace.NearPlaceRemoteDataSource
4
+ import com.stop.data.remote.source.nearplace.NearPlaceRemoteDataSourceImpl
3
5
import com.stop.data.remote.source.route.RouteRemoteDataSource
4
6
import com.stop.data.remote.source.route.RouteRemoteDataSourceImpl
5
7
import dagger.Binds
6
8
import dagger.Module
7
9
import dagger.hilt.InstallIn
8
10
import dagger.hilt.components.SingletonComponent
11
+ import javax.inject.Singleton
9
12
10
13
@InstallIn(SingletonComponent ::class )
11
14
@Module
12
15
internal interface DataSourceModule {
13
16
14
17
@Binds
18
+ @Singleton
15
19
fun provideRouteRemoteDataSource (
16
20
routeRemoteDataSourceImpl : RouteRemoteDataSourceImpl
17
21
): RouteRemoteDataSource
22
+
23
+ @Binds
24
+ @Singleton
25
+ fun provideNearPlaceDataSource (
26
+ nearPlaceRemoteDataSourceImpl : NearPlaceRemoteDataSourceImpl
27
+ ) : NearPlaceRemoteDataSource
28
+
18
29
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ internal interface RepositoryModule {
22
22
23
23
@Binds
24
24
@Singleton
25
- abstract fun provideNearPlaceRepository (
25
+ fun provideNearPlaceRepository (
26
26
nearPlaceRepositoryImpl : NearPlaceRepositoryImpl
27
27
): NearPlaceRepository
28
+
28
29
}
Original file line number Diff line number Diff line change @@ -10,6 +10,6 @@ interface NearPlaceRemoteDataSource {
10
10
centerLon : Double ,
11
11
centerLat : Double ,
12
12
appKey : String
13
- ): List <Place >
13
+ ): Result < List <Place > >
14
14
15
15
}
Original file line number Diff line number Diff line change @@ -15,29 +15,30 @@ internal class NearPlaceRemoteDataSourceImpl @Inject constructor(
15
15
centerLon : Double ,
16
16
centerLat : Double ,
17
17
appKey : String
18
- ): List <Place > {
18
+ ): Result < List <Place > > {
19
19
val result = nearPlaceApiService.getNearPlaces(
20
20
version,
21
21
searchKeyword,
22
22
centerLon,
23
23
centerLat,
24
24
appKey
25
25
)
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
34
41
}
35
- }
36
- is NetworkResult .NetworkError -> {
37
- throw result.exception
38
- }
39
- is NetworkResult .Unexpected -> {
40
- throw result.exception
41
42
}
42
43
}
43
44
}
Original file line number Diff line number Diff line change @@ -15,14 +15,20 @@ internal class NearPlaceRepositoryImpl @Inject constructor(
15
15
centerLon : Double ,
16
16
centerLat : Double ,
17
17
appKey : String
18
- ): List <Place > = nearPlaceRemoteDataSource.getNearPlaces(
19
- version,
20
- searchKeyword,
21
- centerLon,
22
- centerLat,
23
- appKey
24
- ).map {
25
- it.toUseCaseModel()
18
+ ): List <Place > {
19
+ nearPlaceRemoteDataSource.getNearPlaces(
20
+ version,
21
+ searchKeyword,
22
+ centerLon,
23
+ centerLat,
24
+ appKey
25
+ ).onSuccess { places ->
26
+ return places.map {
27
+ it.toUseCaseModel()
28
+ }
29
+ }.onFailure {
30
+ throw it
31
+ }
32
+ return emptyList()
26
33
}
27
-
28
34
}
You can’t perform that action at this time.
0 commit comments