2022-07-04 17:31:58 +02:00
|
|
|
/*
|
|
|
|
* APIArtistConverter.kt
|
|
|
|
* Copyright (C) 2009-2022 Ultrasonic developers
|
|
|
|
*
|
|
|
|
* Distributed under terms of the GNU GPLv3 license.
|
|
|
|
*/
|
|
|
|
|
2017-09-02 19:40:32 +02:00
|
|
|
// Converts Artist entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
|
|
|
// to app domain entities.
|
|
|
|
@file:JvmName("APIArtistConverter")
|
2018-02-17 20:36:19 +01:00
|
|
|
package org.moire.ultrasonic.domain
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Artist as APIArtist
|
|
|
|
|
2021-06-20 16:31:08 +02:00
|
|
|
// When we like to convert to an Artist
|
2022-07-04 17:31:58 +02:00
|
|
|
fun APIArtist.toDomainEntity(serverId: Int): Artist = Artist(
|
2018-02-22 22:30:39 +01:00
|
|
|
id = this@toDomainEntity.id,
|
2022-07-04 17:31:58 +02:00
|
|
|
serverId = serverId,
|
2020-11-18 21:46:46 +01:00
|
|
|
coverArt = this@toDomainEntity.coverArt,
|
2017-09-02 19:40:32 +02:00
|
|
|
name = this@toDomainEntity.name
|
2018-02-22 22:30:39 +01:00
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
2021-06-20 16:31:08 +02:00
|
|
|
// When we like to convert to an index (eg. a single directory).
|
2022-07-04 17:31:58 +02:00
|
|
|
fun APIArtist.toIndexEntity(serverId: Int): Index = Index(
|
2021-06-20 16:31:08 +02:00
|
|
|
id = this@toIndexEntity.id,
|
2022-07-04 17:31:58 +02:00
|
|
|
serverId = serverId,
|
2021-06-20 16:31:08 +02:00
|
|
|
coverArt = this@toIndexEntity.coverArt,
|
|
|
|
name = this@toIndexEntity.name
|
|
|
|
)
|
|
|
|
|
2022-07-04 17:31:58 +02:00
|
|
|
fun APIArtist.toMusicDirectoryDomainEntity(serverId: Int): MusicDirectory = MusicDirectory().apply {
|
2017-09-02 19:40:32 +02:00
|
|
|
name = this@toMusicDirectoryDomainEntity.name
|
2022-07-04 17:31:58 +02:00
|
|
|
addAll(this@toMusicDirectoryDomainEntity.albumsList.map { it.toDomainEntity(serverId) })
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
2021-11-26 17:03:33 +01:00
|
|
|
|
2022-07-04 17:31:58 +02:00
|
|
|
fun APIArtist.toDomainEntityList(serverId: Int): List<Album> {
|
|
|
|
return this.albumsList.map { it.toDomainEntity(serverId) }
|
2021-11-26 17:03:33 +01:00
|
|
|
}
|