-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from VictorKabata/feat-tv-shows
Feat tv shows
- Loading branch information
Showing
33 changed files
with
771 additions
and
169 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
86 changes: 86 additions & 0 deletions
86
...App/src/commonMain/kotlin/com/vickbt/composeApp/data/datasources/TvShowsRepositoryImpl.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,86 @@ | ||
package com.vickbt.composeApp.data.datasources | ||
|
||
import app.cash.paging.Pager | ||
import app.cash.paging.PagingConfig | ||
import app.cash.paging.PagingData | ||
import com.vickbt.composeApp.data.mappers.toDomain | ||
import com.vickbt.composeApp.data.network.models.TvShowResultsDto | ||
import com.vickbt.composeApp.data.network.utils.safeApiCall | ||
import com.vickbt.composeApp.data.paging.BasePagingSource | ||
import com.vickbt.composeApp.domain.models.TvShow | ||
import com.vickbt.composeApp.domain.repositories.TvShowsRepository | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.parameter | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class TvShowsRepositoryImpl(private val httpClient: HttpClient) : TvShowsRepository { | ||
|
||
private val pagingConfig = PagingConfig(pageSize = 20, enablePlaceholders = false) | ||
|
||
override suspend fun fetchAiringTodayTvShows( | ||
language: String, | ||
sortBy: String | ||
): Result<Flow<List<TvShow>?>> { | ||
return safeApiCall { | ||
val response = | ||
httpClient.get(urlString = "discover/tv?include_adult=true&language=$language&page=1&sort_by=$sortBy&air_date.lte={max_date}&air_date.gte={min_date}").body<TvShowResultsDto>() | ||
|
||
response.tvShows?.map { it.toDomain() } | ||
} | ||
} | ||
|
||
override suspend fun fetchTrendingTVShows( | ||
timeWindow: String, | ||
language: String | ||
): Result<Flow<PagingData<TvShow>>> { | ||
val pagingSource = BasePagingSource { page -> | ||
val response = | ||
httpClient.get(urlString = "trending/tv/$timeWindow?language=$language") { | ||
parameter("page", page) | ||
}.body<TvShowResultsDto>().tvShows | ||
|
||
response?.map { it.toDomain() } | ||
} | ||
|
||
return runCatching { | ||
Pager(config = pagingConfig, pagingSourceFactory = { pagingSource }).flow | ||
} | ||
} | ||
|
||
override suspend fun fetchTopRatedTvShows( | ||
language: String, | ||
sortBy: String, | ||
voteCount: String | ||
): Result<Flow<PagingData<TvShow>>> { | ||
val pagingSource = BasePagingSource { page -> | ||
val response = | ||
httpClient.get(urlString = "discover/tv?include_adult=true&language=$language&page=$page&sort_by=$sortBy&vote_count.gte=$voteCount") | ||
.body<TvShowResultsDto>().tvShows | ||
|
||
response?.map { it.toDomain() } | ||
} | ||
|
||
return runCatching { | ||
Pager(config = pagingConfig, pagingSourceFactory = { pagingSource }).flow | ||
} | ||
} | ||
|
||
override suspend fun fetchPopularTvShows( | ||
language: String, | ||
sortBy: String | ||
): Result<Flow<PagingData<TvShow>>> { | ||
val pagingSource = BasePagingSource { page -> | ||
val response = | ||
httpClient.get(urlString = "discover/tv?include_adult=true&language=$language&page=$page&sort_by=$sortBy") | ||
.body<TvShowResultsDto>().tvShows | ||
|
||
response?.map { it.toDomain() } | ||
} | ||
|
||
return runCatching { | ||
Pager(config = pagingConfig, pagingSourceFactory = { pagingSource }).flow | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
composeApp/src/commonMain/kotlin/com/vickbt/composeApp/data/network/models/TvShowDto.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,41 @@ | ||
package com.vickbt.composeApp.data.network.models | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TvShowDto( | ||
val adult: Boolean? = null, | ||
|
||
@SerialName("backdrop_path") | ||
val backdropPath: String? = null, | ||
|
||
val id: Int, | ||
|
||
val name: String? = null, | ||
|
||
val overview: String? = null, | ||
|
||
@SerialName("poster_path") | ||
val posterPath: String? = null, | ||
|
||
@SerialName("media_type") | ||
val mediaType: String? = null, | ||
|
||
@SerialName("genre_ids") | ||
val genreIds: List<Int>? = null, | ||
|
||
val popularity: Double? = null, | ||
|
||
@SerialName("first_air_date") | ||
val firstAirDate: String? = null, | ||
|
||
@SerialName("vote_average") | ||
val voteAverage: Double? = null, | ||
|
||
@SerialName("vote_count") | ||
val voteCount: Int? = null, | ||
|
||
@SerialName("origin_country") | ||
val originCountry: List<String>? = null, | ||
) |
19 changes: 19 additions & 0 deletions
19
...seApp/src/commonMain/kotlin/com/vickbt/composeApp/data/network/models/TvShowResultsDto.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,19 @@ | ||
package com.vickbt.composeApp.data.network.models | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TvShowResultsDto( | ||
@SerialName("page") | ||
val page: Int? = null, | ||
|
||
@SerialName("results") | ||
val tvShows: List<TvShowDto>? = null, | ||
|
||
@SerialName("total_pages") | ||
val totalPages: Int? = null, | ||
|
||
@SerialName("total_results") | ||
val totalResults: Int? = 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
12 changes: 0 additions & 12 deletions
12
composeApp/src/commonMain/kotlin/com/vickbt/composeApp/domain/models/MovieResults.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
composeApp/src/commonMain/kotlin/com/vickbt/composeApp/domain/models/PopularMovies.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
composeApp/src/commonMain/kotlin/com/vickbt/composeApp/domain/models/TrendingMovies.kt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
composeApp/src/commonMain/kotlin/com/vickbt/composeApp/domain/models/TvShow.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,17 @@ | ||
package com.vickbt.composeApp.domain.models | ||
|
||
data class TvShow( | ||
val adult: Boolean? = null, | ||
val backdropPath: String? = null, | ||
val id: Int, | ||
val name: String? = null, | ||
val overview: String? = null, | ||
val posterPath: String? = null, | ||
val mediaType: String? = null, | ||
val genreIds: List<Int>? = null, | ||
val popularity: Double? = null, | ||
val firstAirDate: String? = null, | ||
val voteAverage: Double? = null, | ||
val voteCount: Int? = null, | ||
val originCountry: List<String>? = null, | ||
) |
14 changes: 0 additions & 14 deletions
14
composeApp/src/commonMain/kotlin/com/vickbt/composeApp/domain/models/UpcomingMovies.kt
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...eApp/src/commonMain/kotlin/com/vickbt/composeApp/domain/repositories/TvShowsRepository.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,32 @@ | ||
package com.vickbt.composeApp.domain.repositories | ||
|
||
import app.cash.paging.PagingData | ||
import com.vickbt.composeApp.domain.models.TvShow | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface TvShowsRepository { | ||
/** Fetch Tv Shows airing today from data source*/ | ||
suspend fun fetchAiringTodayTvShows( | ||
language: String = "en-US", | ||
sortBy: String = "popularity.desc" | ||
): Result<Flow<List<TvShow>?>> | ||
|
||
/** Fetch trending Tv Shows from data source*/ | ||
suspend fun fetchTrendingTVShows( | ||
timeWindow: String = "week", | ||
language: String = "en-US" | ||
): Result<Flow<PagingData<TvShow>>> | ||
|
||
/** Fetch top rated Tv Shows from data source*/ | ||
suspend fun fetchTopRatedTvShows( | ||
language: String = "en-US", | ||
sortBy: String = "vote_average.desc", | ||
voteCount: String = "200" | ||
): Result<Flow<PagingData<TvShow>>> | ||
|
||
/** Fetch popular Tv Shows from data source*/ | ||
suspend fun fetchPopularTvShows( | ||
language: String = "en-US", | ||
sortBy: String = "popularity.desc" | ||
): Result<Flow<PagingData<TvShow>>> | ||
} |
5 changes: 3 additions & 2 deletions
5
composeApp/src/commonMain/kotlin/com/vickbt/composeApp/domain/utils/Enums.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package com.vickbt.composeApp.domain.utils | ||
|
||
object Enums { | ||
enum class MovieCategories { | ||
NOW_PLAYING, POPULAR, TRENDING, UPCOMING | ||
|
||
enum class MediaType { | ||
TV_SHOW, MOVIE | ||
} | ||
} |
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
Oops, something went wrong.