Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 마이페이지 나의 밈 API 연결 #263

Merged
merged 9 commits into from
Oct 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ internal class UserRepositoryImpl @Inject constructor(
}.flow
}

override fun getUserRegisteredMemes(): Flow<PagingData<Meme>> {
return createPager { page ->
userRemoteDataSource.getUserRegisteredMemes(
page = page,
size = ITEMS_PER_PAGE,
).memeList.map { it.toMeme() }
}.flow
}

override suspend fun getUserRecentMemes(): List<Meme> {
return userRemoteDataSource.getUserRecentMemes().map { it.toMeme() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import team.ppac.domain.usecase.GetTopKeywordsUseCase
import team.ppac.domain.usecase.GetTopKeywordsUseCaseImpl
import team.ppac.domain.usecase.GetUserRecentMemesUseCase
import team.ppac.domain.usecase.GetUserRecentMemesUseCaseImpl
import team.ppac.domain.usecase.GetUserRegisteredMemesUseCase
import team.ppac.domain.usecase.GetUserRegisteredMemesUseCaseImpl
import team.ppac.domain.usecase.GetUserSavedMemesUseCase
import team.ppac.domain.usecase.GetUserSavedMemesUseCaseImpl
import team.ppac.domain.usecase.GetUserUseCase
Expand Down Expand Up @@ -73,6 +75,10 @@ internal abstract class UseCaseModule {
@ViewModelScoped
abstract fun bindGetUserSavedMemesUseCase(impl: GetUserSavedMemesUseCaseImpl): GetUserSavedMemesUseCase

@Binds
@ViewModelScoped
abstract fun bindGetUserRegisteredMemesUseCase(impl: GetUserRegisteredMemesUseCaseImpl): GetUserRegisteredMemesUseCase

@Binds
@ViewModelScoped
abstract fun bindGetUserRecentMemesUseCase(impl: GetUserRecentMemesUseCaseImpl): GetUserRecentMemesUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ interface UserRepository {
suspend fun createUser(): Boolean
suspend fun getUser(): User
fun getUserSavedMemes(getCurrentPage: (Int) -> Unit): Flow<PagingData<Meme>>
fun getUserRegisteredMemes(): Flow<PagingData<Meme>>
suspend fun getUserRecentMemes(): List<Meme>
suspend fun setLevel(level: Int)
suspend fun getLevel() : Int
suspend fun getLevel(): Int
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package team.ppac.domain.usecase

import androidx.paging.PagingData
import kotlinx.coroutines.flow.Flow
import team.ppac.domain.model.Meme
import team.ppac.domain.repository.UserRepository
import javax.inject.Inject

interface GetUserRegisteredMemesUseCase {
operator fun invoke(): Flow<PagingData<Meme>>
}

internal class GetUserRegisteredMemesUseCaseImpl @Inject constructor(
private val userRepository: UserRepository,
) : GetUserRegisteredMemesUseCase {
override fun invoke(): Flow<PagingData<Meme>> {
return userRepository.getUserRegisteredMemes()
}
}
4 changes: 2 additions & 2 deletions core/remote/src/main/kotlin/team/ppac/remote/api/MemeApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query
import team.ppac.remote.model.response.meme.MemeResponse
import team.ppac.remote.model.response.user.MemesResponse
import team.ppac.remote.model.response.meme.UploadMemeResponse
import team.ppac.remote.model.response.user.SavedMemesResponse

internal interface MemeApi {
@GET("api/meme/{memeId}")
Expand All @@ -34,7 +34,7 @@ internal interface MemeApi {
@Path("name") keyword: String,
@Query("page") page: Int,
@Query("size") pageSize: Int,
): SavedMemesResponse
): MemesResponse

@POST("/api/meme/{memeId}/reaction")
suspend fun reactMeme(@Path("memeId") memeId: String): Boolean
Expand Down
10 changes: 8 additions & 2 deletions core/remote/src/main/kotlin/team/ppac/remote/api/UserApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import retrofit2.http.POST
import retrofit2.http.Query
import team.ppac.remote.model.request.user.PostUserRequest
import team.ppac.remote.model.response.meme.MemeResponse
import team.ppac.remote.model.response.user.SavedMemesResponse
import team.ppac.remote.model.response.user.MemesResponse
import team.ppac.remote.model.response.user.UserResponse

internal interface UserApi {
Expand All @@ -22,7 +22,13 @@ internal interface UserApi {
suspend fun getUserSavedMemes(
@Query("page") page: Int,
@Query("size") size: Int,
): SavedMemesResponse
): MemesResponse

@GET("api/user/registered-memes")
suspend fun getUserRegisteredMemes(
@Query("page") page: Int,
@Query("size") size: Int,
): MemesResponse

@GET("api/user/recent-memes")
suspend fun getUserRecentMemes(): List<MemeResponse>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package team.ppac.remote.datasource

import team.ppac.remote.model.response.meme.MemeResponse
import team.ppac.remote.model.response.user.SavedMemesResponse
import team.ppac.remote.model.response.user.MemesResponse

interface MemeDataSource {
suspend fun getMemeById(memeId: String): MemeResponse
Expand All @@ -12,7 +12,7 @@ interface MemeDataSource {
keyword: String,
page: Int,
size: Int,
): SavedMemesResponse
): MemesResponse
suspend fun reactMeme(memeId: String): Boolean
suspend fun watchMeme(
memeId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package team.ppac.remote.datasource

import team.ppac.remote.model.response.meme.MemeResponse
import team.ppac.remote.model.response.user.SavedMemesResponse
import team.ppac.remote.model.response.user.MemesResponse
import team.ppac.remote.model.response.user.UserResponse

interface UserRemoteDataSource {
suspend fun postUser(deviceId: String): UserResponse
suspend fun getUser(): UserResponse
suspend fun getUserSavedMemes(page: Int, size: Int): SavedMemesResponse
suspend fun getUserSavedMemes(page: Int, size: Int): MemesResponse
suspend fun getUserRegisteredMemes(page: Int, size: Int): MemesResponse
suspend fun getUserRecentMemes(): List<MemeResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import okhttp3.RequestBody.Companion.toRequestBody
import team.ppac.remote.api.MemeApi
import team.ppac.remote.datasource.MemeDataSource
import team.ppac.remote.model.response.meme.MemeResponse
import team.ppac.remote.model.response.user.SavedMemesResponse
import team.ppac.remote.model.response.user.MemesResponse
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import javax.inject.Inject


internal class MemeDataSourceImpl @Inject constructor(
private val memeApi: MemeApi,
@ApplicationContext private val context: Context,
Expand All @@ -40,7 +39,7 @@ internal class MemeDataSourceImpl @Inject constructor(
return memeApi.deleteSavedMeme(memeId)
}

override suspend fun getSearchMemes(keyword: String, page: Int, size: Int): SavedMemesResponse {
override suspend fun getSearchMemes(keyword: String, page: Int, size: Int): MemesResponse {
return memeApi.getSearchMemes(keyword, page, size)
}

Expand Down Expand Up @@ -110,4 +109,4 @@ internal class MemeDataSourceImpl @Inject constructor(
} else null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import team.ppac.remote.api.UserApi
import team.ppac.remote.datasource.UserRemoteDataSource
import team.ppac.remote.model.request.user.PostUserRequest
import team.ppac.remote.model.response.meme.MemeResponse
import team.ppac.remote.model.response.user.SavedMemesResponse
import team.ppac.remote.model.response.user.MemesResponse
import team.ppac.remote.model.response.user.UserResponse
import javax.inject.Inject

Expand All @@ -19,10 +19,14 @@ internal class UserDataSourceImpl @Inject constructor(
return userApi.getUser()
}

override suspend fun getUserSavedMemes(page: Int, size: Int): SavedMemesResponse {
override suspend fun getUserSavedMemes(page: Int, size: Int): MemesResponse {
return userApi.getUserSavedMemes(page = page, size = size)
}

override suspend fun getUserRegisteredMemes(page: Int, size: Int): MemesResponse {
return userApi.getUserRegisteredMemes(page = page, size = size)
}

override suspend fun getUserRecentMemes(): List<MemeResponse> {
return userApi.getUserRecentMemes()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import team.ppac.remote.model.response.meme.MemeResponse
import team.ppac.remote.model.response.pagination.PaginationResponse

@JsonClass(generateAdapter = true)
data class SavedMemesResponse(
data class MemesResponse(
@field:Json(name = "pagination")
val pagination: PaginationResponse,
@field:Json(name = "memeList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ internal fun MyPageScreen(
onRefresh = {
onIntent(MyPageIntent.RefreshData)
savedMemes.refresh()
registeredMemes.refresh()
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import team.ppac.common.android.base.BaseViewModel
import team.ppac.domain.usecase.GetLevelUseCase
import team.ppac.domain.usecase.GetUserRecentMemesUseCase
import team.ppac.domain.usecase.GetUserRegisteredMemesUseCase
import team.ppac.domain.usecase.GetUserSavedMemesUseCase
import team.ppac.domain.usecase.GetUserUseCase
import team.ppac.domain.usecase.RefreshEventUseCase
Expand All @@ -27,6 +28,7 @@ class MyPageViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val getUserUseCase: GetUserUseCase,
getUserSavedMemesUseCase: GetUserSavedMemesUseCase,
getUserRegisteredMemesUseCase: GetUserRegisteredMemesUseCase,
private val getUserRecentMemesUseCase: GetUserRecentMemesUseCase,
private val setLevelUseCase: SetLevelUseCase,
private val getLevelUseCase: GetLevelUseCase,
Expand All @@ -40,10 +42,12 @@ class MyPageViewModel @Inject constructor(
val savedMemes =
getUserSavedMemesUseCase(getCurrentPage = { currentPage.tryEmit(it) })
.cachedIn(viewModelScope)
val registeredMemes = getUserRegisteredMemesUseCase().cachedIn(viewModelScope)

reduce {
copy(
savedMemes = savedMemes
savedMemes = savedMemes,
registeredMemes = registeredMemes,
)
}
}
Expand Down