Skip to content

Commit c7d6be2

Browse files
authored
Merge pull request #50 from boostcampwm-2022/22-feature-mission-bus-line
[PR] map의 공통 로직 TMap class 구현 및 버스 실시간 bus line 그리기
2 parents b6ddec8 + 20a54c4 commit c7d6be2

32 files changed

+783
-240
lines changed

data/src/main/java/com/stop/data/di/DataSourceModule.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.stop.data.di
22

33
import com.stop.data.remote.source.nearplace.NearPlaceRemoteDataSource
44
import com.stop.data.remote.source.nearplace.NearPlaceRemoteDataSourceImpl
5+
import com.stop.data.remote.source.nowlocation.NowLocationRemoteDataSource
6+
import com.stop.data.remote.source.nowlocation.NowLocationRemoteDataSourceImpl
57
import com.stop.data.remote.source.route.RouteRemoteDataSource
68
import com.stop.data.remote.source.route.RouteRemoteDataSourceImpl
79
import dagger.Binds
@@ -26,4 +28,10 @@ internal interface DataSourceModule {
2628
routeRemoteDataSourceImpl: RouteRemoteDataSourceImpl
2729
): RouteRemoteDataSource
2830

31+
@Binds
32+
@Singleton
33+
fun provideNowLocationRemoteDataSource(
34+
nowLocationRemoteDataSourceImpl: NowLocationRemoteDataSourceImpl
35+
): NowLocationRemoteDataSource
36+
2937
}

data/src/main/java/com/stop/data/di/RepositoryModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package com.stop.data.di
22

33
import com.stop.data.repository.AlarmRepositoryImpl
44
import com.stop.data.repository.NearPlaceRepositoryImpl
5+
import com.stop.data.repository.NowLocationRepositoryImpl
56
import com.stop.data.repository.RouteRepositoryImpl
67
import com.stop.domain.repository.AlarmRepository
78
import com.stop.domain.repository.NearPlaceRepository
9+
import com.stop.domain.repository.NowLocationRepository
810
import com.stop.domain.repository.RouteRepository
911
import dagger.Binds
1012
import dagger.Module
@@ -33,4 +35,8 @@ internal interface RepositoryModule {
3335
@Singleton
3436
fun provideAlarmRepository(alarmRepositoryImpl: AlarmRepositoryImpl): AlarmRepository
3537

38+
@Binds
39+
@Singleton
40+
fun provideNowLocationRepository(nowLocationRepositoryImpl: NowLocationRepositoryImpl): NowLocationRepository
41+
3642
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.stop.data.model.nowlocation
2+
3+
import com.stop.domain.model.nowlocation.BusInfoUseCaseItem
4+
5+
data class BusInfoRepositoryItem(
6+
val isArrivedAtStation: String,
7+
val sectionId: String,
8+
val latitude: String,
9+
val longitude: String,
10+
val busId: String,
11+
val busNumber: String,
12+
val isRun: String,
13+
) {
14+
fun toUseCaseModel() = BusInfoUseCaseItem(
15+
isArrivedAtStation,
16+
sectionId,
17+
latitude.toDouble(),
18+
longitude.toDouble(),
19+
busId,
20+
busNumber,
21+
isRun,
22+
)
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.stop.data.remote.model.nowlocation
2+
3+
import com.squareup.moshi.Json
4+
5+
data class BusBody(
6+
@Json(name = "itemList")
7+
val busInfo: List<BusInfo>
8+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.stop.data.remote.model.nowlocation
2+
3+
import com.squareup.moshi.Json
4+
import com.stop.data.model.nowlocation.BusInfoRepositoryItem
5+
6+
data class BusInfo(
7+
@Json(name = "stopFlag")
8+
val isArrivedAtStation: String,
9+
val sectionId: String,
10+
@Json(name = "gpsX")
11+
val longitude: String,
12+
@Json(name = "gpsY")
13+
val latitude: String,
14+
@Json(name = "vehId")
15+
val busId: String,
16+
@Json(name = "plainNo")
17+
val busNumber: String,
18+
@Json(name = "isrunyn")
19+
val isRun: String,
20+
) {
21+
fun toRepositoryModel() = BusInfoRepositoryItem(
22+
isArrivedAtStation = isArrivedAtStation,
23+
sectionId = sectionId,
24+
latitude = latitude,
25+
longitude = longitude,
26+
busId = busId,
27+
busNumber = busNumber,
28+
isRun = isRun,
29+
)
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.stop.data.remote.model.nowlocation
2+
3+
import com.squareup.moshi.Json
4+
import com.squareup.moshi.JsonClass
5+
6+
@JsonClass(generateAdapter = true)
7+
data class GetBusNowLocationResponse(
8+
@Json(name = "msgBody")
9+
val busBody: BusBody,
10+
)

data/src/main/java/com/stop/data/remote/network/WsBusApiService.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.stop.data.remote.network
22

3+
import com.stop.data.BuildConfig
34
import com.stop.data.remote.model.NetworkResult
5+
import com.stop.data.remote.model.nowlocation.GetBusNowLocationResponse
46
import com.stop.domain.model.route.seoul.bus.GetBusLastTimeResponse
57
import com.stop.domain.model.route.seoul.bus.GetBusLineResponse
68
import com.stop.domain.model.route.seoul.bus.GetBusStationArsIdResponse
@@ -15,6 +17,12 @@ internal interface WsBusApiService {
1517
@Query("resultType") resultType: String = "json",
1618
): NetworkResult<GetBusStationArsIdResponse>
1719

20+
@GET(GET_BUS_NOW_LOCATION_URL)
21+
suspend fun getBusNowLocation(
22+
@Query("busRouteId") busRouteId: String,
23+
@Query("resultType") resultType: String = JSON
24+
): NetworkResult<GetBusNowLocationResponse>
25+
1826
@GET(GET_BUS_LINE_URL)
1927
suspend fun getBusLine(
2028
@Query("arsId") stationId: String,
@@ -30,6 +38,8 @@ internal interface WsBusApiService {
3038

3139
companion object {
3240
private const val GET_BUS_ARS_URL = "stationinfo/getStationByName"
41+
private const val GET_BUS_NOW_LOCATION_URL = "buspos/getBusPosByRtid"
42+
private const val JSON = "json"
3343
private const val GET_BUS_LINE_URL = "stationinfo/getRouteByStation"
3444
private const val GET_BUS_LAST_TIME_URL = "stationinfo/getBustimeByStation"
3545
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.stop.data.remote.source.nowlocation
2+
3+
import com.stop.data.model.nowlocation.BusInfoRepositoryItem
4+
5+
interface NowLocationRemoteDataSource {
6+
7+
suspend fun getBusNowLocation(busRouteId: String, order: Int): BusInfoRepositoryItem
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.stop.data.remote.source.nowlocation
2+
3+
import com.stop.data.model.nowlocation.BusInfoRepositoryItem
4+
import com.stop.data.remote.model.NetworkResult
5+
import com.stop.data.remote.network.WsBusApiService
6+
import javax.inject.Inject
7+
8+
internal class NowLocationRemoteDataSourceImpl @Inject constructor(
9+
private val wsBusApiService: WsBusApiService
10+
) : NowLocationRemoteDataSource {
11+
12+
override suspend fun getBusNowLocation(busRouteId: String, order: Int): BusInfoRepositoryItem {
13+
with(wsBusApiService.getBusNowLocation(busRouteId = busRouteId)) {
14+
return when (this) {
15+
is NetworkResult.Success -> this.data.busBody.busInfo[order].toRepositoryModel()
16+
is NetworkResult.Failure -> throw IllegalArgumentException(this.message)
17+
is NetworkResult.NetworkError -> throw this.exception
18+
is NetworkResult.Unexpected -> throw this.exception
19+
}
20+
}
21+
}
22+
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.stop.data.repository
2+
3+
import com.stop.data.remote.source.nowlocation.NowLocationRemoteDataSource
4+
import com.stop.domain.model.nowlocation.BusInfoUseCaseItem
5+
import com.stop.domain.repository.NowLocationRepository
6+
import javax.inject.Inject
7+
8+
class NowLocationRepositoryImpl @Inject constructor(
9+
private val nowLocationRemoteDataSource: NowLocationRemoteDataSource
10+
) : NowLocationRepository{
11+
12+
override suspend fun getBusNowLocation(busRouteId: String, order: Int): BusInfoUseCaseItem {
13+
return nowLocationRemoteDataSource.getBusNowLocation(busRouteId, order).toUseCaseModel()
14+
}
15+
16+
}

0 commit comments

Comments
 (0)