Skip to content

Commit

Permalink
Add stopfinder impl for RealTripPlanningRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Sep 18, 2024
1 parent d4168a3 commit 7cc5d56
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 3 deletions.
2 changes: 2 additions & 0 deletions feature/trip-planner/network/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.krail.android.library)
alias(libs.plugins.krail.android.hilt)
alias(libs.plugins.kotlin.serialization)
}

android {
Expand All @@ -12,4 +13,5 @@ dependencies {
implementation(platform(libs.okhttp.bom))
implementation(libs.okhttp)
implementation(libs.retrofit)
implementation(libs.kotlinx.serialization.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package xyz.ksharma.krail.trip_planner.network.api.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class StopFinderResponse(
@SerialName("version")
val version: String,

@SerialName("locations")
val locations: List<Location>
)

@Serializable
data class Location(
@SerialName("id")
val id: String,

@SerialName("isGlobalId")
val isGlobalId: Boolean,

@SerialName("name")
val name: String,

@SerialName("disassembledName")
val disassembledName: String? = null,

@SerialName("coord")
val coord: List<Double>,

@SerialName("type")
val type: String,

@SerialName("matchQuality")
val matchQuality: Int,

@SerialName("isBest")
val isBest: Boolean,

@SerialName("parent")
val parent: Parent? = null,

@SerialName("assignedStops")
val assignedStops: List<AssignedStop>? = null,

@SerialName("properties")
val properties: Properties? = null
)

@Serializable
data class Parent(
@SerialName("id")
val id: String? = null,

@SerialName("name")
val name: String,

@SerialName("type")
val type: String
)

@Serializable
data class AssignedStop(
@SerialName("id")
val id: String,

@SerialName("isGlobalId")
val isGlobalId: Boolean,

@SerialName("name")
val name: String,

@SerialName("type")
val type: String,

@SerialName("coord")
val coord: List<Double>,

@SerialName("parent")
val parent: Parent,

@SerialName("productClasses")
val productClasses: List<Int>,

@SerialName("connectingMode")
val connectingMode: Int,

@SerialName("properties")
val properties: Properties
)

@Serializable
data class Properties(
@SerialName("stopId")
val stopId: String
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package xyz.ksharma.krail.trip_planner.network.api.repository

import xyz.ksharma.krail.trip_planner.network.api.model.StopFinderResponse
import xyz.ksharma.krail.trip_planner.network.api.model.StopType

interface TripPlanningRepository {

suspend fun stopFinder(stopType: StopType, stopSearchQuery: String)
suspend fun stopFinder(stopType: StopType, stopSearchQuery: String): Result<StopFinderResponse>

fun trip()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package xyz.ksharma.krail.trip_planner.network.api.service

import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
import xyz.ksharma.krail.trip_planner.network.api.model.StopFinderResponse

/**
* https://opendata.transport.nsw.gov.au/dataset/trip-planner-apis/resource/917c66c3-8123-4a0f-b1b1-b4220f32585d
Expand Down Expand Up @@ -74,7 +76,7 @@ interface TripPlanningService {
* Default value : 10.2.1.42
*/
@Query("version") version: String = "10.2.1.42",
)
): Response<StopFinderResponse>

/**
* This endpoint is used to find a list of journeys between two locations at the specified
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package xyz.ksharma.krail.trip_planner.network.real.repository

import kotlinx.coroutines.CoroutineDispatcher
import xyz.ksharma.krail.coroutines.ext.suspendSafeResult
import xyz.ksharma.krail.di.AppDispatchers
import xyz.ksharma.krail.di.Dispatcher
import xyz.ksharma.krail.network.toSafeResult
import xyz.ksharma.krail.trip_planner.network.api.model.StopFinderResponse
import xyz.ksharma.krail.trip_planner.network.api.model.StopType
import xyz.ksharma.krail.trip_planner.network.api.repository.TripPlanningRepository
import xyz.ksharma.krail.trip_planner.network.api.service.TripPlanningService
Expand All @@ -9,10 +15,15 @@ import javax.inject.Singleton
@Singleton
class RealTripPlanningRepository @Inject constructor(
private val tripPlanningService: TripPlanningService,
@Dispatcher(AppDispatchers.IO) private val ioDispatcher: CoroutineDispatcher,
) : TripPlanningRepository {

override suspend fun stopFinder(stopType: StopType, stopSearchQuery: String) {
override suspend fun stopFinder(
stopType: StopType,
stopSearchQuery: String,
): Result<StopFinderResponse> = suspendSafeResult(ioDispatcher) {
tripPlanningService.stopFinder(typeSf = stopType.type, nameSf = stopSearchQuery)
.toSafeResult()
}

override fun trip() {
Expand Down

0 comments on commit 7cc5d56

Please sign in to comment.