mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-01-20 20:29:59 +01:00
Add converting Playlist to MusicDirectoryDomainEntity.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
b73cc0f816
commit
b8b53dc81d
@ -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() })
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user