From b8b53dc81d73d6c8baba7ed7c34a965d1113ef0b Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sun, 27 Aug 2017 22:30:52 +0200 Subject: [PATCH] Add converting Playlist to MusicDirectoryDomainEntity. Signed-off-by: Yahor Berdnikau --- .../ultrasonic/data/SubsonicAPIConverter.kt | 6 ++++++ .../moire/ultrasonic/data/APIConverterTest.kt | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/SubsonicAPIConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/SubsonicAPIConverter.kt index 048b5412..1f424417 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/SubsonicAPIConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/SubsonicAPIConverter.kt @@ -16,6 +16,7 @@ import org.moire.ultrasonic.api.subsonic.models.Artist as APIArtist import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes import org.moire.ultrasonic.api.subsonic.models.MusicDirectory as APIMusicDirectory import org.moire.ultrasonic.api.subsonic.models.MusicFolder as APIMusicFolder +import org.moire.ultrasonic.api.subsonic.models.Playlist as APIPlaylist import org.moire.ultrasonic.api.subsonic.models.SearchResult as APISearchResult fun APIMusicFolder.toDomainEntity(): MusicFolder = MusicFolder(this.id.toString(), this.name) @@ -103,3 +104,8 @@ fun SearchThreeResult.toDomainEntity(): SearchResult = SearchResult( this.artistList.map { it.toDomainEntity() }, this.albumList.map { it.toDomainEntity() }, this.songList.map { it.toDomainEntity() }) + +fun APIPlaylist.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply { + name = this@toMusicDirectoryDomainEntity.name + addAll(this@toMusicDirectoryDomainEntity.entriesList.map { it.toDomainEntity() }) +} diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIConverterTest.kt index 4e95a95b..291662b0 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIConverterTest.kt @@ -13,6 +13,7 @@ import org.moire.ultrasonic.api.subsonic.models.Indexes import org.moire.ultrasonic.api.subsonic.models.MusicDirectory import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild import org.moire.ultrasonic.api.subsonic.models.MusicFolder +import org.moire.ultrasonic.api.subsonic.models.Playlist import org.moire.ultrasonic.api.subsonic.models.SearchResult import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult @@ -257,6 +258,23 @@ class APIConverterTest { } } + @Test + fun `Should convert Playlist to MusicDirectory domain entity`() { + val entity = Playlist(name = "some-playlist-name", entriesList = listOf( + MusicDirectoryChild(id = 10L, parent = 1393), + MusicDirectoryChild(id = 11L, parent = 1393) + )) + + val convertedEntity = entity.toMusicDirectoryDomainEntity() + + with(convertedEntity) { + name `should equal to` entity.name + children.size `should equal to` entity.entriesList.size + children[0] `should equal` entity.entriesList[0].toDomainEntity() + children[1] `should equal` entity.entriesList[1].toDomainEntity() + } + } + private fun createMusicFolder(id: Long = 0, name: String = ""): MusicFolder = MusicFolder(id, name)