Skip to content

Commit

Permalink
add: Trakt id lookup by TMDB ID implemented #31
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadi Norouzi authored and hadi-norouzi committed Jan 21, 2024
1 parent 8e0876b commit 5bb7506
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ class TraktSearchRemoteSourceImpl @Inject constructor(
) : TraktSearchRemoteSource {
override suspend fun getByTmdbId(id: String, type: TmdbType?): Result<Long, GeneralError> {
return when (val result = traktIDLookupService.movieIDLookup(idType = "tmdb", id = id)) {
is NetworkResponse.ApiError -> TODO() // Will be handled in #31
is NetworkResponse.ApiError -> {
val errorResponse = result.body
Result.Failure(GeneralError.ApiError(errorResponse.error, result.code))
}
is NetworkResponse.NetworkError -> Result.Failure(GeneralError.NetworkError)
is NetworkResponse.Success -> {
val body = result.body ?: emptyList()
val movieItemId = body.find { it.movie.ids.tmdb == id.toLong() }?.movie?.ids?.trakt ?: -1
return Result.Success(movieItemId)
}

is NetworkResponse.UnknownError -> TODO() // Will be handled in #31
is NetworkResponse.UnknownError -> Result.Failure(GeneralError.UnknownError(result.error))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fun TraktLoginWebView(
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize()
modifier = Modifier.fillMaxSize(),
) {
CircularProgressIndicator(
modifier = Modifier.wrapContentSize(),
Expand Down

0 comments on commit 5bb7506

Please sign in to comment.