-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate some Artist Endpoints (#109)
* changed the gradle version to 8.6 * added albumDto, album model, Album mapper * Artist Album in progress * Artist's ALbum error: service not found * Fix service definition * Able to fetch Artist's Album * Moved artist Api call to ArtistApi class * Clean up * Added Artist's tracks and related artist Dtos * Added the dtos neeed for ArtistTracks and related artists * in progress * Unable to fetch Artist Top tracks in ArtistDomainManager * fetched Album from ArtistTopTracks endpoint * Not sure if the error has been resolved, phone logs not showing... * Error has been resolved * Code clean up * Several Artist Api endpoint setup * it works without hitting the top-tracks endpoint * Issue resolved: I can not hit the top_tracks endpoint without getting error * issue in ArtistViewModel: trying to debug... * issue resolved :) * issue: several_artist endpoint giving me a 400 error * issue resolved: Several Artist Api error resolved * PR Reviews * PR Reviews --------- Co-authored-by: efedaniel <[email protected]> Co-authored-by: Ejemudaro Ufuoma Isaac <[email protected]>
- Loading branch information
1 parent
6ff5a9c
commit 1853526
Showing
25 changed files
with
441 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/efedaniel/spotifystats/domain/manager/ArtistDomainManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.efedaniel.spotifystats.domain.manager | ||
|
||
import com.efedaniel.spotifystats.domain.mapper.AlbumMapper | ||
import com.efedaniel.spotifystats.domain.mapper.ArtistMapper | ||
import com.efedaniel.spotifystats.domain.mapper.ArtistTrackMapper | ||
import com.efedaniel.spotifystats.domain.mapper.SeveralArtistsMapper | ||
import com.efedaniel.spotifystats.domain.model.Album | ||
import com.efedaniel.spotifystats.domain.model.Artist | ||
import com.efedaniel.spotifystats.domain.model.ArtistTrack | ||
import com.efedaniel.spotifystats.network.dto.AlbumDto | ||
import com.efedaniel.spotifystats.network.dto.PaginatedResponse | ||
import com.efedaniel.spotifystats.network.dto.SeveralArtistsDto | ||
import com.efedaniel.spotifystats.network.service.ArtistApi | ||
import io.reactivex.rxjava3.core.Single | ||
import javax.inject.Inject | ||
|
||
class ArtistDomainManager @Inject constructor( | ||
private val artistApi: ArtistApi, | ||
private val artistMapper: ArtistMapper, | ||
private val albumMapper: AlbumMapper, | ||
private val artistTrackMapper: ArtistTrackMapper, | ||
private val severalArtistsMapper: SeveralArtistsMapper, | ||
) { | ||
|
||
fun getArtist(id: String): Single<Artist> = artistApi | ||
.getArtist(id) | ||
.map(artistMapper::dtoToDomain) | ||
|
||
fun getArtistAlbum(id: String): Single<List<Album>> = artistApi | ||
.getArtistAlbum(id) | ||
.map(PaginatedResponse<AlbumDto>::items) | ||
.map(albumMapper::dtoListToDomainList) | ||
|
||
fun getArtistTopTracks(id: String): Single<List<ArtistTrack>> = artistApi | ||
.getArtistTopTracks(id) | ||
.map { it.track } | ||
.map { artistTrackMapper.dtoListToDomainList(it) } | ||
|
||
fun getSeveralArtists(ids: List<String>): Single<List<Artist>> = artistApi | ||
.getSeveralArtist(ids) | ||
.map (SeveralArtistsDto::artists) | ||
.map {severalArtistsMapper.dtoListToDomainList(it)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/efedaniel/spotifystats/domain/mapper/AlbumMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.efedaniel.spotifystats.domain.mapper | ||
|
||
import com.efedaniel.spotifystats.domain.model.Album | ||
import com.efedaniel.spotifystats.network.dto.AlbumDto | ||
import javax.inject.Inject | ||
|
||
class AlbumMapper @Inject constructor() { | ||
|
||
fun dtoToDomain( | ||
dto: AlbumDto, | ||
): Album = Album( | ||
id = dto.id, | ||
name = dto.name, | ||
imageUrl = dto.images.firstOrNull()?.url, | ||
artists = dto.artists, | ||
spotifyUrl = dto.externalUrls.spotify, | ||
uri = dto.uri, | ||
) | ||
|
||
fun dtoListToDomainList( | ||
dtos: List<AlbumDto> | ||
) = dtos.map { albumDto -> | ||
dtoToDomain(dto = albumDto) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ class ArtistMapper @Inject constructor() { | |
name = dto.name, | ||
popularity = dto.popularity | ||
) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/efedaniel/spotifystats/domain/mapper/ArtistTopTracksMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.efedaniel.spotifystats.domain.mapper | ||
|
||
import com.efedaniel.spotifystats.domain.model.ArtistTrack | ||
import com.efedaniel.spotifystats.network.dto.ArtistTrackDto | ||
import javax.inject.Inject | ||
|
||
class ArtistTrackMapper @Inject constructor() { | ||
|
||
private fun dtoToDomain( | ||
dto: ArtistTrackDto, | ||
) = ArtistTrack( | ||
id = dto.id, | ||
name = dto.name, | ||
imageUrl = dto.images?.firstOrNull()?.url, | ||
popularity = dto.popularity, | ||
isExplicit = dto.explicit, | ||
previewUrl = dto.previewUrl, | ||
uri = dto.uri, | ||
images = dto.images, | ||
album = dto.album, | ||
) | ||
|
||
fun dtoListToDomainList( | ||
dtos: List<ArtistTrackDto> | ||
) = dtos.map { artistTrackDto -> | ||
dtoToDomain(dto = artistTrackDto) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/efedaniel/spotifystats/domain/mapper/RelatedArtistMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.efedaniel.spotifystats.domain.mapper | ||
|
||
import com.efedaniel.spotifystats.domain.model.RelatedArtist | ||
import com.efedaniel.spotifystats.network.dto.RelatedArtistDto | ||
import javax.inject.Inject | ||
|
||
class RelatedArtistMapper @Inject constructor() { | ||
|
||
private fun dtoToDomain( | ||
dto: RelatedArtistDto, | ||
) = RelatedArtist( | ||
id = dto.id, | ||
name = dto.name, | ||
imageUrl = dto.images.firstOrNull()?.url, | ||
popularity = dto.popularity, | ||
followersDto = dto.followers, | ||
genres = dto.genres | ||
) | ||
|
||
fun dtoListToDomainList( | ||
dtos: List<RelatedArtistDto> | ||
) = dtos.mapIndexed { index, relatedArtistDto -> | ||
dtoToDomain(dto = relatedArtistDto) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/efedaniel/spotifystats/domain/mapper/SeveralArtistsMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.efedaniel.spotifystats.domain.mapper | ||
|
||
import com.efedaniel.spotifystats.domain.model.Artist | ||
import com.efedaniel.spotifystats.network.dto.ArtistDto | ||
import javax.inject.Inject | ||
|
||
class SeveralArtistsMapper @Inject constructor() { | ||
|
||
fun dtoToDomain( | ||
dto: ArtistDto, | ||
): Artist = Artist( | ||
id = dto.id, | ||
name = dto.name, | ||
imageUrl = dto.images.firstOrNull()?.url, | ||
spotifyUrl = dto.externalUrls.spotify, | ||
genres = dto.genres, | ||
popularity = dto.popularity, | ||
) | ||
|
||
fun dtoListToDomainList( | ||
dtos: List<ArtistDto> | ||
) = dtos.map { artistDto -> | ||
dtoToDomain(dto = artistDto) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/efedaniel/spotifystats/domain/model/Album.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.efedaniel.spotifystats.domain.model | ||
|
||
import androidx.compose.runtime.Immutable | ||
|
||
@Immutable | ||
data class Album( | ||
val id: String, | ||
val imageUrl: String?, | ||
val name: String, | ||
val artists: List<String>?, | ||
val spotifyUrl: String, | ||
val uri: String?, | ||
) |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/efedaniel/spotifystats/domain/model/ArtistTrack.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.efedaniel.spotifystats.domain.model | ||
|
||
import androidx.compose.runtime.Immutable | ||
import com.efedaniel.spotifystats.network.dto.AlbumDto | ||
import com.efedaniel.spotifystats.network.dto.ImageDto | ||
|
||
@Immutable | ||
data class ArtistTrack( | ||
val id: String, | ||
val name: String, | ||
val imageUrl: String?, | ||
val isExplicit: Boolean?, | ||
val popularity: Int?, | ||
val previewUrl: String?, | ||
val uri: String?, | ||
val images: List<ImageDto>?, | ||
val album: AlbumDto? | ||
) |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/efedaniel/spotifystats/domain/model/RelatedArtist.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.efedaniel.spotifystats.domain.model | ||
|
||
import com.efedaniel.spotifystats.network.dto.FollowersDto | ||
|
||
data class RelatedArtist( | ||
val id: String = "", | ||
val genres: List<String> = emptyList(), // Fixme: Change to ImmutableList | ||
val imageUrl: String? = null, | ||
val name: String = "", | ||
val popularity: Int = 0, | ||
val followersDto: FollowersDto? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/efedaniel/spotifystats/network/dto/AlbumDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.efedaniel.spotifystats.network.dto | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class AlbumDto( | ||
@SerializedName("id") | ||
val id: String, | ||
@SerializedName("images") | ||
val images: List<ImageDto>, | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("external_urls") | ||
val externalUrls: ExternalUrls, | ||
@SerializedName("release_date") | ||
val releaseDate: String, | ||
@SerializedName("release_date_precision") | ||
val releaseDatePrecision : String, | ||
@SerializedName("type") | ||
val type: String, | ||
@SerializedName("uri") | ||
val uri: String, | ||
@SerializedName("artist") | ||
val artists: List<String>, | ||
@SerializedName("total_tracks") | ||
val totalTracks: Int, | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/efedaniel/spotifystats/network/dto/ArtistTopTracksDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.efedaniel.spotifystats.network.dto | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ArtistTopTracksDto( | ||
@SerializedName("tracks") | ||
val track: List<ArtistTrackDto>, | ||
) |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/efedaniel/spotifystats/network/dto/ArtistTrackDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.efedaniel.spotifystats.network.dto | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ArtistTrackDto( | ||
@SerializedName("id") | ||
val id: String, | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("album") | ||
val album: AlbumDto, | ||
@SerializedName("explicit") | ||
val explicit: Boolean, | ||
@SerializedName("popularity") | ||
val popularity: Int, | ||
@SerializedName("preview_url") | ||
val previewUrl: String?, | ||
@SerializedName("uri") | ||
val uri: String, | ||
@SerializedName("external_urls") | ||
val externalUrls: ExternalUrls, | ||
@SerializedName("track_number") | ||
val trackNumber: Int, | ||
@SerializedName("images") | ||
val images: List<ImageDto>?, | ||
) |
Oops, something went wrong.