Skip to content

Commit

Permalink
refactor artist logic and screen
Browse files Browse the repository at this point in the history
  • Loading branch information
frknklnc committed Nov 22, 2023
1 parent 75cdfd4 commit 1a5216e
Show file tree
Hide file tree
Showing 25 changed files with 202 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.example.moveeapp_compose_kmm.data.account.login.LoginResponseModel
import com.example.moveeapp_compose_kmm.data.account.login.RequestTokenResponseModel
import com.example.moveeapp_compose_kmm.data.account.login.SessionRequestModel
import com.example.moveeapp_compose_kmm.data.account.login.SessionResponseModel
import com.example.moveeapp_compose_kmm.data.remote.ApiImpl
import com.example.moveeapp_compose_kmm.utils.Constants.SESSION_ID
import io.ktor.client.HttpClient
import io.ktor.client.call.body
Expand Down Expand Up @@ -50,7 +49,7 @@ class AccountServiceImpl(


override suspend fun logout(logoutRequestModel: LogoutRequestModel): LogoutResponseModel {
return client.delete(ApiImpl.LOGOUT) {
return client.delete(LOGOUT) {
setBody(logoutRequestModel)
contentType(ContentType.Application.Json)
}.body()
Expand All @@ -61,5 +60,6 @@ class AccountServiceImpl(
const val REQUEST_TOKEN = "authentication/token/new"
const val LOGIN = "authentication/token/validate_with_login"
const val SESSION = "authentication/session/new"
const val LOGOUT = "authentication/session"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.moveeapp_compose_kmm.data.remote.model.person
package com.example.moveeapp_compose_kmm.data.artist

import com.example.moveeapp_compose_kmm.data.uimodel.ActorCreditUiModel
import com.example.moveeapp_compose_kmm.data.uimodel.ActorDetailUiModel
import com.example.moveeapp_compose_kmm.domain.artist.ArtistCredit
import com.example.moveeapp_compose_kmm.domain.artist.ArtistDetail
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class PersonDetailModel(
data class ArtistDetailModel(
@SerialName("also_known_as") val alsoKnownAs: List<String>,
@SerialName("adult") val adult: Boolean,
@SerialName("biography") val biography: String,
Expand All @@ -20,18 +20,18 @@ data class PersonDetailModel(
@SerialName("popularity") val popularity: Double,
@SerialName("profile_path") val profilePath: String
) {
fun toUiModel(credit: List<PersonCreditsModel.Cast>) = ActorDetailUiModel(
fun toDomain() = ArtistDetail(
name = name,
biography = biography,
birthday = birthday.orEmpty(),
placeOfBirth = placeOfBirth,
profilePath = profilePath,
credit = credit.map { it.toUiModel() }
//credit = credit.map { it.toDomain() }
)
}

@Serializable
data class PersonCreditsModel(
data class ArtistCreditsModel(
@SerialName("cast") val cast: List<Cast>?=null,
@SerialName("crew") val crew: List<Crew>?=null,
@SerialName("id") val id: Int?=null
Expand All @@ -58,8 +58,8 @@ data class PersonCreditsModel(
@SerialName("vote_average") val voteAverage: Double?=null,
@SerialName("vote_count") val voteCount: Int?=null
) {
fun toUiModel() =
ActorCreditUiModel(
fun toDomain() =
ArtistCredit(
id = id ,
name = originalTitle,
imagePath = posterPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.moveeapp_compose_kmm.data.artist

import com.example.moveeapp_compose_kmm.domain.artist.ArtistCredit
import com.example.moveeapp_compose_kmm.domain.artist.ArtistDetail
import com.example.moveeapp_compose_kmm.domain.artist.ArtistRepository
import com.example.moveeapp_compose_kmm.utils.resultOf

class ArtistRepositoryImpl(
private val service: ArtistService
) : ArtistRepository {

override suspend fun getArtistDetail(personId: Int): Result<ArtistDetail> {
return resultOf {
service.artistDetail(personId).toDomain()
}
}

override suspend fun getArtistCredits(personId: Int): Result<List<ArtistCredit>> {
return resultOf {
service.artistCredit(personId).cast?.map { it.toDomain() } ?: listOf()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.moveeapp_compose_kmm.data.artist

interface ArtistService {

suspend fun artistDetail(personId: Int): ArtistDetailModel

suspend fun artistCredit(personId: Int): ArtistCreditsModel
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.moveeapp_compose_kmm.data.artist

import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get

class ArtistServiceImpl(private val client: HttpClient): ArtistService {

override suspend fun artistDetail(personId: Int): ArtistDetailModel {
return client.get("person/$personId").body()
}

override suspend fun artistCredit(personId: Int): ArtistCreditsModel {
return client.get("person/$personId/combined_credits").body()
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.example.moveeapp_compose_kmm.di

import com.example.moveeapp_compose_kmm.data.account.AccountService
import com.example.moveeapp_compose_kmm.data.account.AccountServiceImpl
import com.example.moveeapp_compose_kmm.data.artist.ArtistService
import com.example.moveeapp_compose_kmm.data.artist.ArtistServiceImpl
import com.example.moveeapp_compose_kmm.data.favorite.FavoriteService
import com.example.moveeapp_compose_kmm.data.favorite.FavoriteServiceImpl
import com.example.moveeapp_compose_kmm.data.movie.MovieService
Expand All @@ -10,8 +12,6 @@ import com.example.moveeapp_compose_kmm.data.rate.RatingService
import com.example.moveeapp_compose_kmm.data.rate.RatingServiceImpl
import com.example.moveeapp_compose_kmm.data.map.NominatimServiceImpl
import com.example.moveeapp_compose_kmm.data.map.NominatimService
import com.example.moveeapp_compose_kmm.data.remote.ApiImpl
import com.example.moveeapp_compose_kmm.data.remote.ApiInterface
import com.example.moveeapp_compose_kmm.data.search.SearchService
import com.example.moveeapp_compose_kmm.data.search.SearchServiceImpl
import com.example.moveeapp_compose_kmm.data.tv.TvService
Expand Down Expand Up @@ -63,14 +63,13 @@ val networkModule = module {
}
}

single<ApiInterface> { ApiImpl(get()) }
single<RatingService> { RatingServiceImpl(get()) }
single<AccountService> { AccountServiceImpl(get()) }
single<MovieService> { MovieServiceImpl(get()) }
single<TvService> { TvServiceImpl(get()) }
single<FavoriteService> { FavoriteServiceImpl(get()) }
single<SearchService> { SearchServiceImpl(get()) }

single<ArtistService> { ArtistServiceImpl(get()) }
single<NominatimService> {
val client = get<HttpClient>()
NominatimServiceImpl(client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import com.example.moveeapp_compose_kmm.data.favorite.FavoriteRepositoryImpl
import com.example.moveeapp_compose_kmm.data.map.MapRepositoryImpl
import com.example.moveeapp_compose_kmm.data.movie.MovieRepositoryImpl
import com.example.moveeapp_compose_kmm.data.rate.RatingRepositoryImpl
import com.example.moveeapp_compose_kmm.data.repository.PersonRepository
import com.example.moveeapp_compose_kmm.data.artist.ArtistRepositoryImpl
import com.example.moveeapp_compose_kmm.data.search.SearchRepositoryImpl
import com.example.moveeapp_compose_kmm.data.tv.TvRepositoryImpl
import com.example.moveeapp_compose_kmm.domain.account.AccountRepository
import com.example.moveeapp_compose_kmm.domain.artist.ArtistRepository
import com.example.moveeapp_compose_kmm.domain.favorite.FavoriteRepository
import com.example.moveeapp_compose_kmm.domain.map.MapRepository
import com.example.moveeapp_compose_kmm.domain.movie.MovieRepository
Expand All @@ -21,7 +22,7 @@ val repositoryModule = module {
single<MovieRepository> { MovieRepositoryImpl(get(), get()) }
single<TvRepository> { TvRepositoryImpl(get(), get()) }
single<SearchRepository> { SearchRepositoryImpl(get()) }
single { PersonRepository(get()) }
single<ArtistRepository> { ArtistRepositoryImpl(get()) }
single<AccountRepository> { AccountRepositoryImpl(get(), get()) }
single<RatingRepository> { RatingRepositoryImpl(get(), get()) }
single<FavoriteRepository> { FavoriteRepositoryImpl(get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.example.moveeapp_compose_kmm.di

import com.example.moveeapp_compose_kmm.ui.scene.account.AccountDetailViewModel
import com.example.moveeapp_compose_kmm.ui.scene.account.favoritescreen.FavoriteViewModel
import com.example.moveeapp_compose_kmm.ui.scene.actordetail.ActorDetailViewModel
import com.example.moveeapp_compose_kmm.ui.scene.artistdetail.ArtistDetailViewModel
import com.example.moveeapp_compose_kmm.ui.scene.login.LoginViewModel
import com.example.moveeapp_compose_kmm.ui.scene.map.MapViewModel
import com.example.moveeapp_compose_kmm.ui.scene.main.MainViewModel
Expand All @@ -24,7 +24,7 @@ val viewModelModule = module {
factory { TvViewModel(get()) }
factory { TvDetailViewModel(get(), get(), get(), get(), get(), get()) }
factory { SearchViewModel(get()) }
factory { ActorDetailViewModel(get()) }
factory { ArtistDetailViewModel(get()) }
factory { FavoriteViewModel(get(), get()) }
factory { MapViewModel(get(), get()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.moveeapp_compose_kmm.domain.artist

data class ArtistDetail(
val name: String = "",
val biography: String = "",
val birthday: String = "",
val placeOfBirth: String = "",
val profilePath: String = "",
)

data class ArtistCredit(
val imagePath: String? = null,
val name: String? = null,
val voteAverage: Double? = null,
val releaseDate: String? = null,
val id: Int? = null,
val mediaType: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.moveeapp_compose_kmm.domain.artist

interface ArtistRepository {

suspend fun getArtistDetail(personId: Int): Result<ArtistDetail>

suspend fun getArtistCredits(personId: Int): Result<List<ArtistCredit>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.example.moveeapp_compose_kmm.core.BackHandler
import com.example.moveeapp_compose_kmm.core.viewModel
import com.example.moveeapp_compose_kmm.ui.scene.actordetail.ActorDetailScreen
import com.example.moveeapp_compose_kmm.ui.scene.actordetail.ActorDetailViewModel
import com.example.moveeapp_compose_kmm.ui.scene.artistdetail.ArtistDetailScreen
import com.example.moveeapp_compose_kmm.ui.scene.artistdetail.ArtistDetailViewModel

class ActorDetailScreen(
class ArtistDetailScreen(
private val actorId: Int,
) : Screen {

@Composable
override fun Content() {
val navigator = LocalNavigator.currentOrThrow
val viewModel: ActorDetailViewModel = viewModel()
val viewModel: ArtistDetailViewModel = viewModel()

ActorDetailScreen(
ArtistDetailScreen(
viewModel = viewModel,
actorId = actorId,
navigateToMovie = { navigator.push(MovieDetailScreen(movieId = it)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MovieDetailScreen(
MovieDetailScreen(
viewModel = viewModel,
movieId = movieId,
navigateToActor = { navigator.push(ActorDetailScreen(it)) },
navigateToActor = { navigator.push(ArtistDetailScreen(it)) },
onBackPressed = navigator::pop,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SearchScreen : Screen {
viewModel = viewModel,
navigateToMovie = { navigator.push(MovieDetailScreen(it)) },
navigateToTv = { navigator.push(TvDetailScreen(it)) },
navigateToActor = { navigator.push(ActorDetailScreen(it)) }
navigateToActor = { navigator.push(ArtistDetailScreen(it)) }
)

BackHandler(isEnabled = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TvDetailScreen(private val tvId: Int) : Screen {
TvDetailScreen(
viewModel = viewModel,
tvId = tvId,
navigateToActor = { navigator.push(ActorDetailScreen(it)) },
navigateToActor = { navigator.push(ArtistDetailScreen(it)) },
onBackPressed = navigator::pop
)

Expand Down

This file was deleted.

Loading

0 comments on commit 1a5216e

Please sign in to comment.