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.
26 lines
729 B
26 lines
729 B
package net.aiterp.git.ykonsole2.infrastructure.testing
|
|
|
|
import net.aiterp.git.ykonsole2.domain.models.Device
|
|
import net.aiterp.git.ykonsole2.domain.models.DeviceRepository
|
|
|
|
class InMemoryDeviceRepository : DeviceRepository {
|
|
private val devices = mutableListOf<Device>()
|
|
|
|
override fun findById(id: String): Device? = devices.firstOrNull { it.id == id }
|
|
|
|
override fun fetchAll() = devices.map(Device::copy)
|
|
|
|
override fun save(device: Device) {
|
|
val index = devices.indexOfFirst { it.id == device.id }
|
|
|
|
if (index >= 0) {
|
|
devices[index] = device
|
|
} else {
|
|
devices += device
|
|
}
|
|
}
|
|
|
|
override fun delete(device: Device) {
|
|
devices.removeIf { it.id == device.id }
|
|
}
|
|
}
|