Skip to content

Commit

Permalink
�[AN] feat: 모임 Paging & 로딩 구현 (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong authored Oct 23, 2024
1 parent ae0cbef commit 8d98354
Show file tree
Hide file tree
Showing 35 changed files with 673 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.happy.friendogly.data.repository.MyClubRepositoryImpl
import com.happy.friendogly.data.repository.PetRepositoryImpl
import com.happy.friendogly.data.repository.PlaygroundRepositoryImpl
import com.happy.friendogly.data.repository.RecentPetsRepositoryImpl
import com.happy.friendogly.data.repository.SearchClubRepositoryImpl
import com.happy.friendogly.data.repository.TokenRepositoryImpl
import com.happy.friendogly.data.repository.WebSocketRepositoryImpl
import com.happy.friendogly.domain.repository.AddressRepository
Expand All @@ -30,6 +31,7 @@ import com.happy.friendogly.domain.repository.MyClubRepository
import com.happy.friendogly.domain.repository.PetRepository
import com.happy.friendogly.domain.repository.PlaygroundRepository
import com.happy.friendogly.domain.repository.RecentPetsRepository
import com.happy.friendogly.domain.repository.SearchClubRepository
import com.happy.friendogly.domain.repository.TokenRepository
import com.happy.friendogly.domain.repository.WebSocketRepository
import dagger.Binds
Expand Down Expand Up @@ -69,6 +71,10 @@ abstract class RepositoryModule {
@Singleton
abstract fun bindsClubRepository(repositoryImpl: ClubRepositoryImpl): ClubRepository

@Binds
@Singleton
abstract fun bindSearchClubRepository(repositoryImpl: SearchClubRepositoryImpl): SearchClubRepository

@Binds
@Singleton
abstract fun bindsKakaoLoginRepository(repositoryImpl: KakaoLoginRepositoryImpl): KakaoLoginRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.happy.friendogly.remote.api.MemberService
import com.happy.friendogly.remote.api.MyClubService
import com.happy.friendogly.remote.api.PetService
import com.happy.friendogly.remote.api.PlaygroundService
import com.happy.friendogly.remote.api.SearchingClubService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -37,6 +38,10 @@ object ServiceModule {
@Singleton
fun providesClubService(retrofit: Retrofit): ClubService = retrofit.create(ClubService::class.java)

@Provides
@Singleton
fun providesSearchingClubService(retrofit: Retrofit): SearchingClubService = retrofit.create(SearchingClubService::class.java)

@Provides
@Singleton
fun providesMemberService(retrofit: Retrofit): MemberService = retrofit.create(MemberService::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.happy.friendogly.data.mapper

import androidx.paging.PagingData
import androidx.paging.map
import com.happy.friendogly.data.model.ClubDto
import com.happy.friendogly.domain.model.Club

fun List<ClubDto>.toDomain(): List<Club> {
return this.map { it.toDomain() }
}

fun PagingData<ClubDto>.toDomain(): PagingData<Club> {
return this.map { it.toDomain() }
}

fun ClubDto.toDomain(): Club {
return Club(
id = id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.happy.friendogly.data.mapper

import androidx.paging.PagingData
import androidx.paging.map
import com.happy.friendogly.data.model.ClubDto
import com.happy.friendogly.data.model.SearchClubPageInfoDto
import com.happy.friendogly.domain.model.Club
import com.happy.friendogly.domain.model.SearchClubPageInfo
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

fun SearchClubPageInfo.toData(): SearchClubPageInfoDto {
return SearchClubPageInfoDto(
pageSize = pageSize,
lastFoundId = lastFoundId.toString(),
lastFoundCreatedAt = lastFoundCreatedAt.toString(),
)
}

fun Flow<PagingData<ClubDto>>.toDomain(): Flow<PagingData<Club>> {
return this.map { pagingData ->
pagingData.map { it.toDomain() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.happy.friendogly.data.model

data class SearchClubPageInfoDto(
val pageSize: Int,
val lastFoundCreatedAt: String,
val lastFoundId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import com.happy.friendogly.data.mapper.toDomain
import com.happy.friendogly.data.source.ClubDataSource
import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.model.Club
import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.ClubDetail
import com.happy.friendogly.domain.model.ClubFilterCondition
import com.happy.friendogly.domain.model.ClubParticipation
import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.domain.model.Gender
Expand Down Expand Up @@ -52,27 +50,6 @@ class ClubRepositoryImpl
)
}

override suspend fun getSearchingClubs(
filterCondition: ClubFilterCondition,
address: ClubAddress,
genderParams: List<Gender>,
sizeParams: List<SizeType>,
): DomainResult<List<Club>, DataError.Network> {
return source.getSearchingClubs(
filterCondition = filterCondition.toData(),
address = address.toData(),
genderParams = genderParams.map { it.toData() },
sizeParams = sizeParams.map { it.toData() },
).fold(
onSuccess = { clubs ->
DomainResult.Success(clubs.toDomain())
},
onFailure = { error ->
error.toDomainError()
},
)
}

override suspend fun getClub(clubId: Long): DomainResult<ClubDetail, DataError.Network> {
return source.getClub(clubId).fold(
onSuccess = { clubDetail ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.happy.friendogly.data.repository

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.happy.friendogly.data.mapper.toData
import com.happy.friendogly.data.mapper.toDomain
import com.happy.friendogly.domain.model.Club
import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.ClubFilterCondition
import com.happy.friendogly.domain.model.Gender
import com.happy.friendogly.domain.model.SearchClubPageInfo
import com.happy.friendogly.domain.model.SizeType
import com.happy.friendogly.domain.repository.SearchClubRepository
import com.happy.friendogly.remote.api.SearchingClubService
import com.happy.friendogly.remote.paging.SearchingClubPagingSource
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class SearchClubRepositoryImpl
@Inject
constructor(
private val service: SearchingClubService,
) : SearchClubRepository {
override suspend fun getSearchingClubs(
searchClubPageInfo: SearchClubPageInfo,
filterCondition: ClubFilterCondition,
address: ClubAddress,
genderParams: List<Gender>,
sizeParams: List<SizeType>,
): Flow<PagingData<Club>> {
return Pager(
config =
PagingConfig(
pageSize = searchClubPageInfo.pageSize,
enablePlaceholders = false,
),
pagingSourceFactory = {
SearchingClubPagingSource(
service = service,
searchClubPageInfoDto = searchClubPageInfo.toData(),
filterCondition = filterCondition.toData(),
address = address.toData(),
genderParams = genderParams.map { it.toData() },
sizeParams = sizeParams.map { it.toData() },
)
},
).flow.toDomain()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.happy.friendogly.data.source

import com.happy.friendogly.data.model.ClubAddressDto
import com.happy.friendogly.data.model.ClubDetailDto
import com.happy.friendogly.data.model.ClubDto
import com.happy.friendogly.data.model.ClubFilterConditionDto
import com.happy.friendogly.data.model.ClubParticipationDto
import com.happy.friendogly.data.model.ClubStateDto
import com.happy.friendogly.data.model.GenderDto
Expand All @@ -22,13 +20,6 @@ interface ClubDataSource {
petIds: List<Long>,
): Result<Unit>

suspend fun getSearchingClubs(
filterCondition: ClubFilterConditionDto,
address: ClubAddressDto,
genderParams: List<GenderDto>,
sizeParams: List<SizeTypeDto>,
): Result<List<ClubDto>>

suspend fun getClub(clubId: Long): Result<ClubDetailDto>

suspend fun postClubMember(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.happy.friendogly.domain.model

import kotlinx.datetime.LocalDateTime

data class SearchClubPageInfo(
val pageSize: Int = DEFAULT_PAGE_SIZE,
val lastFoundCreatedAt: LocalDateTime = LocalDateTime.parse(DEFAULT_FOUND_CREATE),
val lastFoundId: Long = DEFAULT_FOUND_ID,
) {
companion object {
private const val DEFAULT_PAGE_SIZE = 20
private const val DEFAULT_FOUND_CREATE = "9999-12-31T23:59:59"
private const val DEFAULT_FOUND_ID = 0x7fffffffffffffff
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package com.happy.friendogly.domain.repository

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.model.Club
import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.ClubDetail
import com.happy.friendogly.domain.model.ClubFilterCondition
import com.happy.friendogly.domain.model.ClubParticipation
import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.domain.model.Gender
Expand All @@ -24,13 +22,6 @@ interface ClubRepository {
petIds: List<Long>,
): DomainResult<Unit, DataError.Network>

suspend fun getSearchingClubs(
filterCondition: ClubFilterCondition,
address: ClubAddress,
genderParams: List<Gender>,
sizeParams: List<SizeType>,
): DomainResult<List<Club>, DataError.Network>

suspend fun getClub(clubId: Long): DomainResult<ClubDetail, DataError.Network>

suspend fun postClubMember(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.happy.friendogly.domain.repository

import androidx.paging.PagingData
import com.happy.friendogly.domain.model.Club
import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.ClubFilterCondition
import com.happy.friendogly.domain.model.Gender
import com.happy.friendogly.domain.model.SearchClubPageInfo
import com.happy.friendogly.domain.model.SizeType
import kotlinx.coroutines.flow.Flow

interface SearchClubRepository {
suspend fun getSearchingClubs(
searchClubPageInfo: SearchClubPageInfo,
filterCondition: ClubFilterCondition,
address: ClubAddress,
genderParams: List<Gender>,
sizeParams: List<SizeType>,
): Flow<PagingData<Club>>
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import androidx.paging.PagingData
import com.happy.friendogly.domain.model.Club
import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.ClubFilterCondition
import com.happy.friendogly.domain.model.Gender
import com.happy.friendogly.domain.model.SearchClubPageInfo
import com.happy.friendogly.domain.model.SizeType
import com.happy.friendogly.domain.repository.ClubRepository
import com.happy.friendogly.domain.repository.SearchClubRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetSearchingClubsUseCase
@Inject
constructor(
private val repository: ClubRepository,
private val repository: SearchClubRepository,
) {
suspend operator fun invoke(
searchClubPageInfo: SearchClubPageInfo,
filterCondition: ClubFilterCondition,
address: ClubAddress,
genderParams: List<Gender>,
sizeParams: List<SizeType>,
): DomainResult<List<Club>, DataError.Network> =
): Flow<PagingData<Club>> =
repository.getSearchingClubs(
searchClubPageInfo = searchClubPageInfo,
filterCondition = filterCondition,
address = address,
genderParams = genderParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.happy.friendogly.presentation.ui.club.common.mapper

import androidx.paging.PagingData
import androidx.paging.map
import com.happy.friendogly.domain.model.Club
import com.happy.friendogly.presentation.ui.club.common.model.ClubItemUiModel
import com.happy.friendogly.presentation.ui.club.common.model.ClubPet
Expand All @@ -8,6 +10,10 @@ fun List<Club>.toPresentation(): List<ClubItemUiModel> {
return this.map { it.toPresentation() }
}

fun PagingData<Club>.toPresentation(): PagingData<ClubItemUiModel> {
return this.map { it.toPresentation() }
}

fun Club.toPresentation(): ClubItemUiModel {
return ClubItemUiModel(
clubId = id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sealed interface ClubListEvent {

data object OpenAddPet : ClubListEvent

data object ResetPaging : ClubListEvent

sealed interface Navigation : ClubListEvent {
data object NavigateToAddClub : Navigation

Expand Down
Loading

0 comments on commit 8d98354

Please sign in to comment.