mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-18 04:30:48 +01:00
Add converting subsonic api Playlist entity to domain entity.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
e4728af320
commit
d82ff15f57
@ -125,9 +125,47 @@ public class Playlist implements Serializable
|
|||||||
this.pub = pub;
|
this.pub = pub;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
return "Playlist{" +
|
||||||
return name;
|
"id='" + id + '\'' +
|
||||||
}
|
", name='" + name + '\'' +
|
||||||
|
", owner='" + owner + '\'' +
|
||||||
|
", comment='" + comment + '\'' +
|
||||||
|
", songCount='" + songCount + '\'' +
|
||||||
|
", created='" + created + '\'' +
|
||||||
|
", pub=" + pub +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Playlist playlist = (Playlist) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(playlist.id) : playlist.id != null) return false;
|
||||||
|
if (name != null ? !name.equals(playlist.name) : playlist.name != null) return false;
|
||||||
|
if (owner != null ? !owner.equals(playlist.owner) : playlist.owner != null) return false;
|
||||||
|
if (comment != null ? !comment.equals(playlist.comment) : playlist.comment != null)
|
||||||
|
return false;
|
||||||
|
if (songCount != null ? !songCount.equals(playlist.songCount) : playlist.songCount != null)
|
||||||
|
return false;
|
||||||
|
if (created != null ? !created.equals(playlist.created) : playlist.created != null)
|
||||||
|
return false;
|
||||||
|
return pub != null ? pub.equals(playlist.pub) : playlist.pub == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = id != null ? id.hashCode() : 0;
|
||||||
|
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||||
|
result = 31 * result + (owner != null ? owner.hashCode() : 0);
|
||||||
|
result = 31 * result + (comment != null ? comment.hashCode() : 0);
|
||||||
|
result = 31 * result + (songCount != null ? songCount.hashCode() : 0);
|
||||||
|
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||||
|
result = 31 * result + (pub != null ? pub.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,7 +11,9 @@ import org.moire.ultrasonic.domain.Artist
|
|||||||
import org.moire.ultrasonic.domain.Indexes
|
import org.moire.ultrasonic.domain.Indexes
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
import org.moire.ultrasonic.domain.MusicFolder
|
import org.moire.ultrasonic.domain.MusicFolder
|
||||||
|
import org.moire.ultrasonic.domain.Playlist
|
||||||
import org.moire.ultrasonic.domain.SearchResult
|
import org.moire.ultrasonic.domain.SearchResult
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Artist as APIArtist
|
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.Indexes as APIIndexes
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicDirectory as APIMusicDirectory
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectory as APIMusicDirectory
|
||||||
@ -109,3 +111,10 @@ fun APIPlaylist.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory(
|
|||||||
name = this@toMusicDirectoryDomainEntity.name
|
name = this@toMusicDirectoryDomainEntity.name
|
||||||
addAll(this@toMusicDirectoryDomainEntity.entriesList.map { it.toDomainEntity() })
|
addAll(this@toMusicDirectoryDomainEntity.entriesList.map { it.toDomainEntity() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun APIPlaylist.toDomainEntity(): Playlist = Playlist(this.id.toString(), this.name, this.owner,
|
||||||
|
this.comment, this.songCount.toString(),
|
||||||
|
this.created?.let { SimpleDateFormat.getDateTimeInstance().format(it.time) },
|
||||||
|
public.toString())
|
||||||
|
|
||||||
|
fun List<APIPlaylist>.toDomainEntitiesList(): List<Playlist> = this.map { it.toDomainEntity() }
|
||||||
|
@ -17,6 +17,7 @@ import org.moire.ultrasonic.api.subsonic.models.Playlist
|
|||||||
import org.moire.ultrasonic.api.subsonic.models.SearchResult
|
import org.moire.ultrasonic.api.subsonic.models.SearchResult
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult
|
import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult
|
import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +25,7 @@ import java.util.Calendar
|
|||||||
*
|
*
|
||||||
* @author Yahor Berdnikau
|
* @author Yahor Berdnikau
|
||||||
*/
|
*/
|
||||||
@Suppress("TooManyFunctions")
|
@Suppress("TooManyFunctions", "LargeClass")
|
||||||
class APIConverterTest {
|
class APIConverterTest {
|
||||||
@Test
|
@Test
|
||||||
fun `Should convert MusicFolder entity`() {
|
fun `Should convert MusicFolder entity`() {
|
||||||
@ -275,6 +276,39 @@ class APIConverterTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert playlist to domain entity`() {
|
||||||
|
val entity = Playlist(id = 634, name = "some-name", owner = "some-owner",
|
||||||
|
comment = "some-comment", public = false, songCount = 256, duration = 1150,
|
||||||
|
created = Calendar.getInstance(), changed = Calendar.getInstance(),
|
||||||
|
coverArt = "some-art")
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
id `should equal to` entity.id.toString()
|
||||||
|
name `should equal to` entity.name
|
||||||
|
comment `should equal to` entity.comment
|
||||||
|
owner `should equal to` entity.owner
|
||||||
|
public `should equal to` entity.public
|
||||||
|
songCount `should equal to` entity.songCount.toString()
|
||||||
|
created `should equal to` SimpleDateFormat.getDateTimeInstance()
|
||||||
|
.format(entity.created?.time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert list of playlists to list of domain entities`() {
|
||||||
|
val entitiesList = listOf(Playlist(id = 23, name = "some-name", songCount = 10))
|
||||||
|
|
||||||
|
val convertedList = entitiesList.toDomainEntitiesList()
|
||||||
|
|
||||||
|
with(convertedList) {
|
||||||
|
size `should equal to` entitiesList.size
|
||||||
|
this[0] `should equal` entitiesList[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…
x
Reference in New Issue
Block a user