You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
925 B
28 lines
925 B
package net.aiterp.git.ykonsole2.infrastructure.testing
|
|
|
|
import net.aiterp.git.ykonsole2.domain.models.WorkoutState
|
|
import net.aiterp.git.ykonsole2.domain.models.WorkoutStateRepository
|
|
|
|
class InMemoryWorkoutStateRepository : WorkoutStateRepository {
|
|
private val map = mutableMapOf<String, MutableList<WorkoutState>>()
|
|
|
|
override fun fetchByWorkoutId(workoutId: String): List<WorkoutState> {
|
|
return map[workoutId]?.sortedBy { it.time.toInt() } ?: emptyList()
|
|
}
|
|
|
|
override fun save(state: WorkoutState) {
|
|
if (map[state.workoutId] != null) {
|
|
val list = map[state.workoutId]!!
|
|
list.removeIf { it.time == state.time }
|
|
list += state
|
|
} else {
|
|
map[state.workoutId] = mutableListOf(state)
|
|
}
|
|
}
|
|
|
|
override fun deleteAll(states: Collection<WorkoutState>) {
|
|
for (state in states) {
|
|
map[state.workoutId]?.removeIf { it.time == state.time }
|
|
}
|
|
}
|
|
}
|