Skip to content

Commit

Permalink
Add path search support (not user visible)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed May 15, 2022
1 parent 33b9c93 commit c29fd23
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package com.kylecorry.trail_sense.navigation.paths.infrastructure

import com.kylecorry.trail_sense.navigation.paths.domain.IPath
import com.kylecorry.trail_sense.navigation.paths.domain.IPathService
import com.kylecorry.trail_sense.navigation.paths.domain.Path
import com.kylecorry.trail_sense.shared.extensions.onIO
import com.kylecorry.trail_sense.shared.grouping.filter.GroupFilter
import com.kylecorry.trail_sense.shared.grouping.persistence.ISearchableGroupLoader

class PathGroupLoader(private val pathService: IPathService) : ISearchableGroupLoader<IPath> {

private val loader = pathService.loader()
private val filter = GroupFilter(loader)

override suspend fun load(search: String?, group: Long?): List<IPath> = onIO {
if (search.isNullOrBlank()) {
getPathsByGroup(group)
Expand All @@ -16,15 +21,16 @@ class PathGroupLoader(private val pathService: IPathService) : ISearchableGroupL
}

private suspend fun getPathsBySearch(search: String, groupFilter: Long?) = onIO {
// TODO: Implement this
emptyList<IPath>()
filter.filter(groupFilter) {
(it as Path).name?.contains(search, ignoreCase = true) == true
}
}

private suspend fun getPathsByGroup(group: Long?) = onIO {
pathService.getPaths(group, includeGroups = true)
loader.getChildren(group, 1)
}

override suspend fun getGroup(id: Long): IPath? {
return pathService.getGroup(id)
return loader.getGroup(id)
}
}

0 comments on commit c29fd23

Please sign in to comment.