Add mapping from subsonic api album entity to MusicDirectory domain entity.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
6c0f43b2ff
commit
03fbf3dbfe
|
@ -49,6 +49,10 @@ fun Album.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply
|
||||||
genre = this@toDomainEntity.genre
|
genre = this@toDomainEntity.genre
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
||||||
|
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toDomainEntity() })
|
||||||
|
}
|
||||||
|
|
||||||
fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
|
fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
|
||||||
id = this@toDomainEntity.id.toString()
|
id = this@toDomainEntity.id.toString()
|
||||||
parent = this@toDomainEntity.parent.toString()
|
parent = this@toDomainEntity.parent.toString()
|
||||||
|
@ -65,13 +69,13 @@ fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.
|
||||||
suffix = this@toDomainEntity.suffix
|
suffix = this@toDomainEntity.suffix
|
||||||
transcodedContentType = this@toDomainEntity.transcodedContentType
|
transcodedContentType = this@toDomainEntity.transcodedContentType
|
||||||
transcodedSuffix = this@toDomainEntity.transcodedSuffix
|
transcodedSuffix = this@toDomainEntity.transcodedSuffix
|
||||||
coverArt = this@toDomainEntity.coverArt.toString()
|
coverArt = this@toDomainEntity.coverArt
|
||||||
size = this@toDomainEntity.size
|
size = this@toDomainEntity.size
|
||||||
duration = this@toDomainEntity.duration
|
duration = this@toDomainEntity.duration
|
||||||
bitRate = this@toDomainEntity.bitRate
|
bitRate = this@toDomainEntity.bitRate
|
||||||
path = this@toDomainEntity.path
|
path = this@toDomainEntity.path
|
||||||
setIsVideo(this@toDomainEntity.isVideo)
|
setIsVideo(this@toDomainEntity.isVideo)
|
||||||
setCreated(this@toDomainEntity.created?.time)
|
created = this@toDomainEntity.created?.time
|
||||||
starred = this@toDomainEntity.starred != null
|
starred = this@toDomainEntity.starred != null
|
||||||
discNumber = this@toDomainEntity.discNumber
|
discNumber = this@toDomainEntity.discNumber
|
||||||
type = this@toDomainEntity.type
|
type = this@toDomainEntity.type
|
||||||
|
|
|
@ -176,6 +176,22 @@ class APIConverterTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert to MusicDirectory domain entity`() {
|
||||||
|
val entity = Album(id = 101L, name = "some-album", artist = "some-artist", artistId = 54L,
|
||||||
|
coverArt = "some-id", songCount = 10, duration = 456,
|
||||||
|
created = Calendar.getInstance(), year = 2022, genre = "Hard Rock",
|
||||||
|
songList = listOf(MusicDirectoryChild()))
|
||||||
|
|
||||||
|
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
name `should equal` null
|
||||||
|
children.size `should equal to` entity.songList.size
|
||||||
|
children[0] `should equal` entity.songList[0].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createMusicFolder(id: Long = 0, name: String = ""): MusicFolder =
|
private fun createMusicFolder(id: Long = 0, name: String = ""): MusicFolder =
|
||||||
MusicFolder(id, name)
|
MusicFolder(id, name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue