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

Share Count api 연결 #260

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -66,6 +66,10 @@ internal class MemeRepositoryImpl @Inject constructor(
return memeDataSource.watchMeme(memeId, watchType.name.lowercase())
}

override suspend fun shareMeme(memeId: String): Boolean {
return memeDataSource.shareMeme(memeId)
}

private val _savedMemeEventFlow = MutableSharedFlow<SavedMemeEvent>()

override val savedMemeEventFlow: Flow<SavedMemeEvent>
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ import team.ppac.domain.usecase.SaveMemeUseCase
import team.ppac.domain.usecase.SaveMemeUseCaseImpl
import team.ppac.domain.usecase.SetLevelUseCase
import team.ppac.domain.usecase.SetLevelUseCaseImpl
import team.ppac.domain.usecase.ShareMemeUseCase
import team.ppac.domain.usecase.ShareMemeUseCaseImpl
import team.ppac.domain.usecase.UploadMemeUseCase
import team.ppac.domain.usecase.UploadMemeUseCaseImpl
import team.ppac.domain.usecase.WatchMemeUseCase
@@ -119,6 +121,10 @@ internal abstract class UseCaseModule {
@ViewModelScoped
abstract fun bindEmitRefreshEventUseCase(impl: EmitRefreshEventUseCaseImpl): EmitRefreshEventUseCase

@Binds
@ViewModelScoped
abstract fun bindShareMemeUseCase(impl: ShareMemeUseCaseImpl): ShareMemeUseCase

@Binds
@ViewModelScoped
abstract fun bindUploadMemeUseCase(impl: UploadMemeUseCaseImpl): UploadMemeUseCase
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@ interface MemeRepository {
memeId: String,
watchType: MemeWatchType,
): Boolean

suspend fun shareMeme(
memeId: String
): Boolean
suspend fun emitRefreshEvent()
val savedMemeEventFlow: Flow<SavedMemeEvent>
suspend fun uploadMeme(
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package team.ppac.domain.usecase

import team.ppac.domain.repository.MemeRepository
import javax.inject.Inject

interface ShareMemeUseCase {
suspend operator fun invoke(memeId: String): Boolean
}

internal class ShareMemeUseCaseImpl @Inject constructor(
private val memeRepository: MemeRepository,
) : ShareMemeUseCase {
override suspend fun invoke(memeId: String): Boolean =
memeRepository.shareMeme(memeId)

}
5 changes: 5 additions & 0 deletions core/remote/src/main/kotlin/team/ppac/remote/api/MemeApi.kt
Original file line number Diff line number Diff line change
@@ -45,6 +45,11 @@ internal interface MemeApi {
@Path("type") type: String,
): Boolean

@POST("/api/meme/{memeId}/share")
suspend fun shareMeme(
@Path("memeId") memeId: String,
): Boolean

@Multipart
@POST("/api/meme")
suspend fun postMeme(
Original file line number Diff line number Diff line change
@@ -13,12 +13,12 @@ interface MemeDataSource {
page: Int,
size: Int,
): SavedMemesResponse

suspend fun reactMeme(memeId: String): Boolean
suspend fun watchMeme(
memeId: String,
type: String,
): Boolean
suspend fun shareMeme(memeId: String): Boolean

suspend fun uploadMeme(
keywordIds: List<String>,
Original file line number Diff line number Diff line change
@@ -52,6 +52,10 @@ internal class MemeDataSourceImpl @Inject constructor(
return memeApi.watchMeme(memeId, type)
}

override suspend fun shareMeme(memeId: String): Boolean {
return memeApi.shareMeme(memeId)
}

override suspend fun uploadMeme(
keywordIds: List<String>,
memeImageUri: String,
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import team.ppac.domain.usecase.EmitRefreshEventUseCase
import team.ppac.domain.usecase.GetMemeUseCase
import team.ppac.domain.usecase.ReactMemeUseCase
import team.ppac.domain.usecase.SaveMemeUseCase
import team.ppac.domain.usecase.ShareMemeUseCase
import team.ppac.errorhandling.FarmemeNetworkException
import javax.inject.Inject

@@ -27,6 +28,7 @@ class DetailViewModel @Inject constructor(
private val deleteSavedMemeUseCase: DeleteSavedMemeUseCase,
private val reactMemeUseCase: ReactMemeUseCase,
private val emitRefreshEventUseCase: EmitRefreshEventUseCase,
private val shareMemeUseCase: ShareMemeUseCase,
) : BaseViewModel<DetailUiState, DetailSideEffect, DetailIntent>(savedStateHandle) {

init {
@@ -64,6 +66,7 @@ class DetailViewModel @Inject constructor(
}

is DetailIntent.ClickBottomButton.Share -> {
incrementShareCount()
postSideEffect(DetailSideEffect.ShareLink(intent.memeId))
}

@@ -168,6 +171,11 @@ class DetailViewModel @Inject constructor(
}
}

private suspend fun incrementShareCount() {
shareMemeUseCase(currentState.memeId)
emitRefreshEventUseCase()
}

companion object {
const val TAG = "DetailViewModel"
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import team.ppac.domain.usecase.GetThisWeekRecommendMemesUseCase
import team.ppac.domain.usecase.GetUserUseCase
import team.ppac.domain.usecase.ReactMemeUseCase
import team.ppac.domain.usecase.SaveMemeUseCase
import team.ppac.domain.usecase.ShareMemeUseCase
import team.ppac.domain.usecase.WatchMemeUseCase
import team.ppac.errorhandling.FarmemeNetworkException
import team.ppac.recommendation.mvi.RecommendationIntent
@@ -33,6 +34,7 @@ class RecommendationViewModel @Inject constructor(
private val saveMemeUseCase: SaveMemeUseCase,
private val deleteSavedMemeUseCase: DeleteSavedMemeUseCase,
private val watchMemeUseCase: WatchMemeUseCase,
private val shareMemeUseCase: ShareMemeUseCase,
) : BaseViewModel<RecommendationState, RecommendationSideEffect, RecommendationIntent>(
savedStateHandle
) {
@@ -85,6 +87,7 @@ class RecommendationViewModel @Inject constructor(
}

is RecommendationIntent.ClickButton.Share -> {
shareMemeUseCase(intent.meme.id)
postSideEffect(RecommendationSideEffect.ShareLink(intent.meme.id))
}