Skip to content

Commit

Permalink
Remove unnecessary overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Feb 28, 2025
1 parent 6c532ef commit d254c91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xyz.ksharma.core.test.fakes
import xyz.ksharma.krail.sandook.NswStops
import xyz.ksharma.krail.sandook.Sandook
import xyz.ksharma.krail.sandook.SavedTrip
import xyz.ksharma.krail.sandook.SelectProductClassesForStop
import xyz.ksharma.krail.sandook.SelectServiceAlertsByJourneyId

class FakeSandook : Sandook {
Expand Down Expand Up @@ -89,42 +90,20 @@ class FakeSandook : Sandook {
productClasses.add(productClass)
}

override fun selectStopsByPartialName(stopName: String): List<NswStops> {
return stops.filter { it.stopName.contains(stopName, ignoreCase = true) }
override fun insertTransaction(block: () -> Unit) {
block()
}

override fun selectStopsByNameAndProductClass(
stopName: String,
includeProductClassList: List<Int>,
): List<NswStops> {
return stops.filter { stop ->
stop.stopName.contains(stopName, ignoreCase = true) &&
stopProductClasses[stop.stopId]?.any { it in includeProductClassList } == true
}
override fun clearNswStopsTable() {
}

override fun selectStopsByNameExcludingProductClass(
stopName: String,
excludeProductClassList: List<Int>,
): List<NswStops> {
return stops.filter { stop ->
stop.stopName.contains(stopName, ignoreCase = true) &&
stopProductClasses[stop.stopId]?.none { it in excludeProductClassList } == true
}
override fun clearNswProductClassTable() {
}

override fun selectStopsByNameExcludingProductClassOrExactId(
override fun selectStops(
stopName: String,
excludeProductClassList: List<Int>,
): List<NswStops> {
return stops.filter { stop ->
(stop.stopName.contains(stopName, ignoreCase = true) ||
stop.stopId == stopName) &&
stopProductClasses[stop.stopId]?.none { it in excludeProductClassList } == true
}
}

override fun insertTransaction(block: () -> Unit) {
block()
): List<SelectProductClassesForStop> {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,48 +106,9 @@ internal class RealSandook(factory: SandookDriverFactory) : Sandook {
nswStopsQueries.insertStopProductClass(stopId, productClass.toLong())
}

override fun selectStopsByPartialName(stopName: String): List<NswStops> {
return nswStopsQueries.selectStopsByPartialName(stopName).executeAsList()
}

override fun selectStopsByNameAndProductClass(
stopName: String,
includeProductClassList: List<Int>,
): List<NswStops> {
return nswStopsQueries.selectStopsByNameAndProductClass(
stopName,
includeProductClassList.map { it.toLong() }
).executeAsList()
}

override fun selectStopsByNameExcludingProductClass(
stopName: String,
excludeProductClassList: List<Int>
): List<NswStops> {
return nswStopsQueries.selectStopsByNameExcludingProductClass(
stopName,
excludeProductClassList.map { it.toLong() }
).executeAsList()
}

/**
* Combines exact stopId and partial [stopName] search logic while excluding stops
* based on the given list of product classes.
*/
override fun selectStopsByNameExcludingProductClassOrExactId(
stopName: String,
excludeProductClassList: List<Int>
): List<NswStops> {
val stopId = stopName
return nswStopsQueries.selectStopsByNameExcludingProductClassOrExactStopId(
stopId,
stopName,
excludeProductClassList.map { it.toLong() }
).executeAsList()
}

override fun insertTransaction(block: () -> Unit) {
nswStopsQueries.transaction { block() }
}

override fun clearNswStopsTable() {
nswStopsQueries.clearNswStopsTable()
Expand All @@ -159,8 +120,8 @@ internal class RealSandook(factory: SandookDriverFactory) : Sandook {

override fun selectStops(
stopName: String,
excludeProductClassList: List<Int>
) : List<SelectProductClassesForStop>{
excludeProductClassList: List<Int>,
): List<SelectProductClassesForStop> {
return nswStopsQueries.selectProductClassesForStop(
stopName,
stopName,
Expand Down
38 changes: 2 additions & 36 deletions sandook/src/commonMain/kotlin/xyz/ksharma/krail/sandook/Sandook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,6 @@ interface Sandook {

fun insertNswStopProductClass(stopId: String, productClass: Int)

fun selectStopsByPartialName(stopName: String): List<NswStops>

/**
* Select stops by name and product class. This is useful for selecting stops that are of a certain product class.
* Use with care, because it may also include those stops which are of multiple product classes,
* that are not included in the include list.
*/
fun selectStopsByNameAndProductClass(
stopName: String,
includeProductClassList: List<Int>,
): List<NswStops>

/**
* Select stops by name excluding product classes. This is useful for selecting stops that are
* not of a certain product class.
*/
fun selectStopsByNameExcludingProductClass(
stopName: String,
excludeProductClassList: List<Int> = emptyList(),
): List<NswStops>

/**
* Retrieves stops by matching an exact stop \id\ or partially matching a stop \name\.
* Excludes stops having product classes in the given \excludeProductClassList\.
* \param stopId Exact stop \id\ to match.
* \param stopName Partial stop \name\ to match.
* \param excludeProductClassList Product class IDs to exclude.
* \return List of matching NswStops.
*/
fun selectStopsByNameExcludingProductClassOrExactId(
stopName: String,
excludeProductClassList: List<Int> = emptyList(),
): List<NswStops>

/**
* Inserts a list of stops in a single transaction.
*/
Expand All @@ -84,8 +50,8 @@ interface Sandook {
fun clearNswProductClassTable()

/**
* * Retrieves stops by matching an exact stop \id\ or partially matching a stop \name\.
* * Excludes stops having product classes in the given \excludeProductClassList\.
* Retrieves stops by matching an exact stop \id\ or partially matching a stop \name\.
* Excludes stops having product classes in the given \excludeProductClassList\.
*/
fun selectStops(
stopName: String,
Expand Down

0 comments on commit d254c91

Please sign in to comment.