Skip to content

Commit

Permalink
[CHORE] #32 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
l5x5l committed Aug 11, 2024
1 parent 29befea commit eb2e904
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import pokitmons.pokit.domain.usecase.pokit.GetPokitUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitsUseCase
import pokitmons.pokit.domain.usecase.pokit.ModifyPokitUseCase
import javax.inject.Inject
import pokitmons.pokit.domain.model.pokit.Pokit as DomainPokit

@HiltViewModel
class AddPokitViewModel @Inject constructor(
Expand All @@ -48,7 +47,7 @@ class AddPokitViewModel @Inject constructor(
private val pokitId = savedStateHandle.get<String>("pokit_id")?.toIntOrNull()

private val pokitPaging = PokitPaging(
getPokits = ::getPokits,
getPokits = getPokitsUseCase,
perPage = 10,
coroutineScope = viewModelScope,
initPage = 0
Expand Down Expand Up @@ -105,10 +104,6 @@ class AddPokitViewModel @Inject constructor(
}
}

private suspend fun getPokits(size: Int, page: Int): PokitResult<List<DomainPokit>> {
return getPokitsUseCase.getPokits(size = size, page = page)
}

fun inputPokitName(pokitName: String) {
_pokitName.update { pokitName }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import pokitmons.pokit.domain.commom.PokitResult
import kotlin.reflect.KSuspendFunction2
import pokitmons.pokit.domain.model.pokit.Pokit as DomainPokit
import pokitmons.pokit.domain.usecase.pokit.GetPokitsUseCase

class PokitPaging(
private val getPokits: KSuspendFunction2<Int, Int, PokitResult<List<DomainPokit>>>,
private val getPokits: GetPokitsUseCase,
private val perPage: Int = 10,
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO),
private val initPage: Int = 0,
Expand All @@ -37,7 +36,7 @@ class PokitPaging(
requestJob = coroutineScope.launch {
try {
currentPageIndex = initPage
val response = getPokits(perPage * firstRequestPage, currentPageIndex)
val response = getPokits.getPokits(size = perPage * firstRequestPage, page = currentPageIndex)
when (response) {
is PokitResult.Success -> {
val pokitList = response.result.map { domainPokit ->
Expand Down Expand Up @@ -66,7 +65,7 @@ class PokitPaging(

requestJob = coroutineScope.launch {
try {
val response = getPokits(perPage, currentPageIndex)
val response = getPokits.getPokits(size = perPage, page = currentPageIndex)
when (response) {
is PokitResult.Success -> {
val pokitList = response.result.map { domainPokit ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import pokitmons.pokit.domain.usecase.pokit.GetPokitUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitsUseCase
import javax.inject.Inject
import pokitmons.pokit.domain.model.link.Link as DomainLink
import pokitmons.pokit.domain.model.pokit.Pokit as DomainPokit

@HiltViewModel
class PokitDetailViewModel @Inject constructor(
Expand All @@ -36,7 +35,7 @@ class PokitDetailViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
) : ViewModel() {
private val pokitPaging = PokitPaging(
getPokits = ::getPokits,
getPokits = getPokitsUseCase,
perPage = 10,
coroutineScope = viewModelScope,
initPage = 0
Expand Down Expand Up @@ -69,10 +68,6 @@ class PokitDetailViewModel @Inject constructor(
}
}

private suspend fun getPokits(size: Int, page: Int): PokitResult<List<DomainPokit>> {
return getPokitsUseCase.getPokits(size = size, page = page)
}

private suspend fun getLinks(categoryId: Int, size: Int, page: Int, sort: LinksSort): PokitResult<List<DomainLink>> {
val currentFilter = state.value.currentFilter
return getLinksUseCase.getLinks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import pokitmons.pokit.domain.commom.PokitResult
import kotlin.reflect.KSuspendFunction2
import pokitmons.pokit.domain.model.pokit.Pokit as DomainPokit
import pokitmons.pokit.domain.usecase.pokit.GetPokitsUseCase

class PokitPaging(
private val getPokits: KSuspendFunction2<Int, Int, PokitResult<List<DomainPokit>>>,
private val getPokits: GetPokitsUseCase,
private val perPage: Int = 10,
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO),
private val initPage: Int = 0,
Expand All @@ -37,7 +36,7 @@ class PokitPaging(
requestJob = coroutineScope.launch {
try {
currentPageIndex = initPage
val response = getPokits(perPage * firstRequestPage, currentPageIndex)
val response = getPokits.getPokits(size = perPage * firstRequestPage, page = currentPageIndex)
when (response) {
is PokitResult.Success -> {
val pokitList = response.result.map { domainPokit ->
Expand Down Expand Up @@ -66,7 +65,7 @@ class PokitPaging(

requestJob = coroutineScope.launch {
try {
val response = getPokits(perPage, currentPageIndex)
val response = getPokits.getPokits(size = perPage, page = currentPageIndex)
when (response) {
is PokitResult.Success -> {
val pokitList = response.result.map { domainPokit ->
Expand Down

0 comments on commit eb2e904

Please sign in to comment.