Change to extension functions in api converter.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
437877750c
commit
3c4f91efef
|
@ -227,8 +227,7 @@ public class RESTMusicService implements MusicService
|
||||||
Response<MusicFoldersResponse> response = subsonicAPIClient.getApi().getMusicFolders().execute();
|
Response<MusicFoldersResponse> response = subsonicAPIClient.getApi().getMusicFolders().execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
List<MusicFolder> musicFolders = APIConverter
|
List<MusicFolder> musicFolders = APIConverter.toDomainEntityList(response.body().getMusicFolders());
|
||||||
.convertMusicFolderList(response.body().getMusicFolders());
|
|
||||||
writeCachedMusicFolders(context, musicFolders);
|
writeCachedMusicFolders(context, musicFolders);
|
||||||
return musicFolders;
|
return musicFolders;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
package org.moire.ultrasonic.data
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
import org.moire.ultrasonic.domain.MusicFolder
|
import org.moire.ultrasonic.domain.MusicFolder
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicFolder as APIMusicFolder
|
||||||
|
|
||||||
typealias APIMusicFolder = org.moire.ultrasonic.api.subsonic.models.MusicFolder
|
fun APIMusicFolder.toDomainEntity(): MusicFolder = MusicFolder(this.id.toString(), this.name)
|
||||||
|
|
||||||
fun convertMusicFolder(entity: APIMusicFolder): MusicFolder {
|
fun List<APIMusicFolder>.toDomainEntityList(): List<MusicFolder>
|
||||||
return MusicFolder(entity.id.toString(), entity.name)
|
= this.map { it.toDomainEntity() }
|
||||||
}
|
|
||||||
|
|
||||||
fun convertMusicFolderList(entitiesList: List<APIMusicFolder>): List<MusicFolder> {
|
fun convertMusicFolderList(entitiesList: List<APIMusicFolder>): List<MusicFolder> {
|
||||||
return entitiesList.map { convertMusicFolder(it) }
|
return entitiesList.map { convertMusicFolder(it) }
|
||||||
|
|
|
@ -16,7 +16,7 @@ class APIConverterTest {
|
||||||
fun `Should convert MusicFolder entity`() {
|
fun `Should convert MusicFolder entity`() {
|
||||||
val entity = createMusicFolder(10, "some-name")
|
val entity = createMusicFolder(10, "some-name")
|
||||||
|
|
||||||
val convertedEntity = convertMusicFolder(entity)
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
convertedEntity.name `should equal to` "some-name"
|
convertedEntity.name `should equal to` "some-name"
|
||||||
convertedEntity.id `should equal to` 10.toString()
|
convertedEntity.id `should equal to` 10.toString()
|
||||||
|
@ -29,7 +29,7 @@ class APIConverterTest {
|
||||||
createMusicFolder(4, "some-name-4")
|
createMusicFolder(4, "some-name-4")
|
||||||
)
|
)
|
||||||
|
|
||||||
val convertedList = convertMusicFolderList(entityList)
|
val convertedList = entityList.toDomainEntityList()
|
||||||
|
|
||||||
convertedList.size `should equal to` 2
|
convertedList.size `should equal to` 2
|
||||||
convertedList[0].id `should equal to` 3.toString()
|
convertedList[0].id `should equal to` 3.toString()
|
||||||
|
|
Loading…
Reference in New Issue