Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.1.3-2'
ext.kotlin_version = '1.1.4'
repositories {
google()
jcenter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,36 @@ import javax.inject.Inject
* data sources
*/
class BufferooDataRepository @Inject constructor(private val factory: BufferooDataStoreFactory,
private val bufferooMapper: BufferooMapper):
private val bufferooMapper: BufferooMapper) :
BufferooRepository {

override fun clearBufferoos(): Completable {
return factory.retrieveCacheDataStore().clearBufferoos()
}

override fun saveBufferoos(bufferoos: List<Bufferoo>): Completable {
val bufferooEntities = mutableListOf<BufferooEntity>()
bufferoos.map { bufferooEntities.add(bufferooMapper.mapToEntity(it)) }
return factory.retrieveCacheDataStore().saveBufferoos(bufferooEntities)
val bufferooEntities = bufferoos.map { bufferooMapper.mapToEntity(it) }
return saveBufferooEntities(bufferooEntities)
}

private fun saveBufferooEntities(bufferoos: List<BufferooEntity>): Completable {
return factory.retrieveCacheDataStore().saveBufferoos(bufferoos)
}

override fun getBufferoos(): Single<List<Bufferoo>> {
val dataStore = factory.retrieveDataStore()
return dataStore.getBufferoos()
.flatMap {
val bufferoos = mutableListOf<Bufferoo>()
it.map { bufferoos.add(bufferooMapper.mapFromEntity(it)) }
Single.just(bufferoos)
}
.flatMap {
if (dataStore is BufferooRemoteDataStore) {
saveBufferoos(it).toSingle { it }
saveBufferooEntities(it).toSingle { it }
} else {
Single.just(it)
}
}
.map { list ->
list.map { listItem ->
bufferooMapper.mapFromEntity(listItem)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import javax.inject.Inject
* operations in which data store implementation layers can carry out.
*/
class BufferooRemoteImpl @Inject constructor(private val bufferooService: BufferooService,
private val entityMapper: BufferooEntityMapper):
private val entityMapper: BufferooEntityMapper) :
BufferooRemote {

/**
Expand All @@ -22,9 +22,9 @@ class BufferooRemoteImpl @Inject constructor(private val bufferooService: Buffer
return bufferooService.getBufferoos()
.map { it.team }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do all of it in here instead of another map where we do it.map?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you right. It should be done in a single map.

.map {
val entities = mutableListOf<BufferooEntity>()
it.forEach { entities.add(entityMapper.mapFromRemote(it)) }
entities
it.map { listItem ->
entityMapper.mapFromRemote(listItem)
}
}
}

Expand Down