Skip to content

Commit

Permalink
Merge pull request #371 from skedgo/feature/18080_18363
Browse files Browse the repository at this point in the history
  • Loading branch information
lenganngoh authored Nov 13, 2022
2 parents 36d1e37 + 497b905 commit 2e41cd1
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import com.skedgo.tripkit.configuration.AppVersionNameRepository
import com.skedgo.tripkit.configuration.GetAppVersion
import com.skedgo.tripkit.configuration.Server
import com.skedgo.tripkit.data.HttpClientCustomDataStore
import com.skedgo.tripkit.regionrouting.GetRegionRoutingService
import com.skedgo.tripkit.data.regions.RegionService
import com.skedgo.tripkit.regionrouting.RegionRoutingRepository
import com.skedgo.tripkit.regionrouting.RegionRoutingApi
import dagger.Lazy
import dagger.Module
Expand Down Expand Up @@ -139,8 +140,8 @@ open class HttpClientModule(

@Singleton
@Provides
open fun getRegionRoutingService(api: RegionRoutingApi): GetRegionRoutingService {
return GetRegionRoutingService.GetRegionRoutingServiceImpl(api)
open fun getRegionRoutingService(api: RegionRoutingApi, regionService: RegionService): RegionRoutingRepository {
return RegionRoutingRepository.RegionRoutingRepositoryImpl(api, regionService)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.skedgo.tripkit.regionrouting

import com.skedgo.tripkit.regionrouting.data.GetRegionRouteRequest
import com.skedgo.tripkit.regionrouting.data.GetRouteDetailsRequest
import com.skedgo.tripkit.regionrouting.data.RegionRoute
import com.skedgo.tripkit.regionrouting.data.RouteDetails
import io.reactivex.Single
import retrofit2.http.Body
import retrofit2.http.POST

interface RegionRoutingApi {
@POST("info/routes.json")
fun getRegionRoutes(request: GetRegionRouteRequest): Single<GetRegionRouteResponse>
fun getRegionRoutes(@Body request: GetRegionRouteRequest): Single<List<RegionRoute>>

@POST("info/routeInfo.json")
fun getRegionRouteInfo(@Body request: GetRouteDetailsRequest): Single<RouteDetails>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.skedgo.tripkit.regionrouting

import com.skedgo.tripkit.common.model.Location
import com.skedgo.tripkit.data.regions.RegionService
import com.skedgo.tripkit.regionrouting.data.GetRegionRouteRequest
import com.skedgo.tripkit.regionrouting.data.GetRouteDetailsRequest
import com.skedgo.tripkit.regionrouting.data.RegionRoute
import com.skedgo.tripkit.regionrouting.data.RouteDetails
import io.reactivex.Observable
import io.reactivex.Single

interface RegionRoutingRepository {

fun getRegionRoutes(
region: String,
query: String? = null,
modes: List<String> = emptyList(),
operatorId: String? = null
): Single<List<RegionRoute>>

fun getRoutes(
query: String,
location: Location?
): Observable<List<RegionRoute>>

fun getRoutes(
regionName: String,
query: String
): Single<List<RegionRoute>>

fun getRegionRouteInfo(
region: String,
operatorId: String,
routeID: Int
): Single<RouteDetails>

class RegionRoutingRepositoryImpl(
private val regionRoutingApi: RegionRoutingApi,
private val regionService: RegionService
) : RegionRoutingRepository {
override fun getRegionRoutes(
region: String,
query: String?,
modes: List<String>,
operatorId: String?
): Single<List<RegionRoute>> {
return regionRoutingApi.getRegionRoutes(
GetRegionRouteRequest(
region = region,
query = query,
modes = modes,
operatorId = operatorId
)
)
}

override fun getRoutes(regionName: String, query: String): Single<List<RegionRoute>> {
val request = GetRegionRouteRequest(
region = regionName,
query = query
)
return regionRoutingApi.getRegionRoutes(request)
}

override fun getRoutes(query: String, location: Location?): Observable<List<RegionRoute>> {
return (
if (location != null) {
regionService.getRegionByLocationAsync(location)
} else {
regionService.getRegionsAsync().map { it.first() }
}
).flatMapSingle { region ->
val request = GetRegionRouteRequest(
region = region.name ?: "",
query = query
)
regionRoutingApi.getRegionRoutes(request)
}
}

override fun getRegionRouteInfo(region: String, operatorId: String, routeID: Int): Single<RouteDetails> {
val request =
GetRouteDetailsRequest(region, operatorId, routeID)

return regionRoutingApi.getRegionRouteInfo(request)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.skedgo.tripkit.regionrouting.data

data class Direction(
val encodedShape: String,
val id: String,
val name: String,
val shapeIsDetailed: Boolean,
val stops: List<Stop>
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.skedgo.tripkit.regionrouting
package com.skedgo.tripkit.regionrouting.data

import com.google.gson.annotations.SerializedName

Expand All @@ -7,7 +7,7 @@ data class GetRegionRouteRequest(
val query: String? = null,
@SerializedName("operatorID")
val operatorId: String? = null,
val modes: List<String> = emptyList(),
val modes: List<String>? = null,
@SerializedName("routesIDs")
val routesIds: List<String> = emptyList(),
val routesNames: List<String> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.skedgo.tripkit.regionrouting.data

data class GetRouteDetailsRequest(
val operatorID: String,
val region: String,
val routeID: Int
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.skedgo.tripkit.regionrouting
package com.skedgo.tripkit.regionrouting.data

import com.skedgo.tripkit.routing.ModeInfo
import com.skedgo.tripkit.routing.ServiceColor

data class GetRegionRouteResponse(
data class RegionRoute(
val id: String,
val operatorID: String,
val shortName: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skedgo.tripkit.regionrouting.data

import com.skedgo.tripkit.routing.ModeInfo
import com.skedgo.tripkit.routing.ServiceColor

data class RouteDetails(
val directions: List<Direction>,
val id: String,
val mode: String,
val modeInfo: ModeInfo,
val operatorId: String,
val operatorName: String,
val region: String,
val routeColor: ServiceColor,
val routeName: String,
val shortName: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.skedgo.tripkit.regionrouting.data

data class Stop(
val common: Boolean,
val lat: Int,
val lng: Int,
val name: String,
val stopCode: String
)

0 comments on commit 2e41cd1

Please sign in to comment.