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();
|
||||
checkResponseSuccessful(response);
|
||||
|
||||
List<MusicFolder> musicFolders = APIConverter
|
||||
.convertMusicFolderList(response.body().getMusicFolders());
|
||||
List<MusicFolder> musicFolders = APIConverter.toDomainEntityList(response.body().getMusicFolders());
|
||||
writeCachedMusicFolders(context, musicFolders);
|
||||
return musicFolders;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
package org.moire.ultrasonic.data
|
||||
|
||||
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 {
|
||||
return MusicFolder(entity.id.toString(), entity.name)
|
||||
}
|
||||
fun List<APIMusicFolder>.toDomainEntityList(): List<MusicFolder>
|
||||
= this.map { it.toDomainEntity() }
|
||||
|
||||
fun convertMusicFolderList(entitiesList: List<APIMusicFolder>): List<MusicFolder> {
|
||||
return entitiesList.map { convertMusicFolder(it) }
|
||||
|
|
|
@ -16,7 +16,7 @@ class APIConverterTest {
|
|||
fun `Should convert MusicFolder entity`() {
|
||||
val entity = createMusicFolder(10, "some-name")
|
||||
|
||||
val convertedEntity = convertMusicFolder(entity)
|
||||
val convertedEntity = entity.toDomainEntity()
|
||||
|
||||
convertedEntity.name `should equal to` "some-name"
|
||||
convertedEntity.id `should equal to` 10.toString()
|
||||
|
@ -29,7 +29,7 @@ class APIConverterTest {
|
|||
createMusicFolder(4, "some-name-4")
|
||||
)
|
||||
|
||||
val convertedList = convertMusicFolderList(entityList)
|
||||
val convertedList = entityList.toDomainEntityList()
|
||||
|
||||
convertedList.size `should equal to` 2
|
||||
convertedList[0].id `should equal to` 3.toString()
|
||||
|
|
Loading…
Reference in New Issue