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][#97] MyPage Album 이미지 삭제 API 연결 #100

Merged
merged 6 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -0,0 +1,7 @@
package com.nexters.ilab.android.core.data.datasource

import com.nexters.ilab.android.core.data.response.UserInfoResponse

interface DeleteMyAlbumDataSource {
suspend fun deleteMyAlbum(uuid: Long, thumbnailId: Int): UserInfoResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nexters.ilab.android.core.data.datasource

import com.nexters.ilab.android.core.data.response.UserInfoResponse
import com.nexters.ilab.android.core.data.service.ILabService
import javax.inject.Inject

class DeleteMyAlbumDataSourceImpl @Inject constructor(
private val service: ILabService,
) : DeleteMyAlbumDataSource {
override suspend fun deleteMyAlbum(uuid: Long, thumbnailId: Int): UserInfoResponse {
return service.deleteMyAlbumImage(uuid, thumbnailId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.nexters.ilab.android.core.data.datasource.FileDataSource
import com.nexters.ilab.android.core.data.datasource.FileDataSourceImpl
import com.nexters.ilab.android.core.data.datasource.AuthDataSource
import com.nexters.ilab.android.core.data.datasource.AuthDataSourceImpl
import com.nexters.ilab.android.core.data.datasource.DeleteMyAlbumDataSource
import com.nexters.ilab.android.core.data.datasource.DeleteMyAlbumDataSourceImpl
import com.nexters.ilab.android.core.data.datasource.ProfileDataSource
import com.nexters.ilab.android.core.data.datasource.ProfileDataSourceImpl
import com.nexters.ilab.android.core.data.datasource.StyleDataSource
Expand Down Expand Up @@ -45,4 +47,8 @@ abstract class DataSourceModule {
@Singleton
@Binds
abstract fun bindProfileDataSource(profileDataSourceImpl: ProfileDataSourceImpl): ProfileDataSource

@Binds
@Singleton
abstract fun bindDeleteMyAlbumDataSource(deleteMyAlbumDataSourceImpl: DeleteMyAlbumDataSourceImpl): DeleteMyAlbumDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.nexters.ilab.android.core.data.di

import com.nexters.ilab.android.core.data.repository.FileRepositoryImpl
import com.nexters.ilab.android.core.data.repository.AuthRepositoryImpl
import com.nexters.ilab.android.core.data.repository.DeleteMyAlbumRepositoryImpl
import com.nexters.ilab.android.core.data.repository.PrivacyPolicyRepositoryImpl
import com.nexters.ilab.android.core.data.repository.ProfileRepositoryImpl
import com.nexters.ilab.android.core.data.repository.StyleRepositoryImpl
import com.nexters.ilab.android.core.data.repository.TokenRepositoryImpl
import com.nexters.ilab.android.core.domain.repository.FileRepository
import com.nexters.ilab.android.core.domain.repository.AuthRepository
import com.nexters.ilab.android.core.domain.repository.DeleteMyAlbumRepository
import com.nexters.ilab.android.core.domain.repository.PrivacyPolicyRepository
import com.nexters.ilab.android.core.domain.repository.ProfileRepository
import com.nexters.ilab.android.core.domain.repository.StyleRepository
Expand Down Expand Up @@ -45,4 +47,8 @@ abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindProfileRepository(profileRepositoryImpl: ProfileRepositoryImpl): ProfileRepository

@Binds
@Singleton
abstract fun bindDeleteMyAlbumRepository(deleteMyAlbumRepositoryImpl: DeleteMyAlbumRepositoryImpl): DeleteMyAlbumRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nexters.ilab.android.core.data.repository

import com.nexters.ilab.android.core.data.datasource.DeleteMyAlbumDataSource
import com.nexters.ilab.android.core.data.mapper.toEntity
import com.nexters.ilab.android.core.data.util.runSuspendCatching
import com.nexters.ilab.android.core.datastore.TokenDataSource
import com.nexters.ilab.android.core.domain.repository.DeleteMyAlbumRepository
import javax.inject.Inject

class DeleteMyAlbumRepositoryImpl @Inject constructor(
private val tokenDataSource: TokenDataSource,
private val myAlbumDataSource: DeleteMyAlbumDataSource,
) : DeleteMyAlbumRepository {
override suspend fun deleteMyAlbum(thumbnailId: Int) = runSuspendCatching {
val uuid = tokenDataSource.getUUID()
myAlbumDataSource.deleteMyAlbum(uuid, thumbnailId).toEntity()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.nexters.ilab.android.core.data.service
import com.nexters.ilab.android.core.data.response.CreatedProfileResponse
import com.nexters.ilab.android.core.data.response.ProfileResponse
import com.nexters.ilab.android.core.data.response.StyleResponse
import com.nexters.ilab.android.core.data.response.UserInfoResponse
import okhttp3.MultipartBody
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path

interface ILabService {
@GET("style")
Expand All @@ -23,4 +25,10 @@ interface ILabService {
@Part("styleId") styleId: Int,
@Part("uuid") uuid: Long,
): List<CreatedProfileResponse>

@POST("thumbnails/delete/{uuid}/{thumbnailId}")
suspend fun deleteMyAlbumImage(
@Path("uuid") uuid: Long,
@Path("uuid") thumbnailId: Int,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 Path 잘 못 들어간거같음

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉 그렇네 왜 이래

): UserInfoResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nexters.ilab.android.core.domain.repository

import com.nexters.ilab.android.core.domain.entity.UserInfoEntity

interface DeleteMyAlbumRepository {
suspend fun deleteMyAlbum(thumbnailId: Int): Result<UserInfoEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ internal fun HomeRoute(
LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
when (sideEffect) {
is HomeSideEffect.OnCreateImageButtonClickFromStyle -> {
is HomeSideEffect.OnCreateImageBtnClickFromStyle -> {
onNavigateToUploadPhoto(sideEffect.selectedStyle)
}

is HomeSideEffect.OnCreateImageButtonClickFromProfile -> {
is HomeSideEffect.OnCreateImageBtnClickFromProfile -> {
onNavigateToUploadPhoto(sideEffect.selectedProfile)
}
}
Expand All @@ -99,8 +99,8 @@ internal fun HomeRoute(
uiState = uiState,
padding = padding,
onSettingClick = onSettingClick,
onCreateImageButtonClickFromStyle = viewModel::onCreateImageButtonClickFromStyle,
onCreateImageButtonClickFromProfile = viewModel::onCreateImageButtonClickFromProfile,
onCreateImageBtnClickFromStyle = viewModel::onCreateImageBtnClickFromStyle,
onCreateImageBtnClickFromProfile = viewModel::onCreateImageBtnClickFromProfile,
openProfileImageDialog = viewModel::openProfileImageDialog,
dismissProfileImageDialog = viewModel::dismissProfileImageDialog,
getStyleProfileList = viewModel::getStyleProfileList,
Expand All @@ -115,8 +115,8 @@ internal fun HomeScreen(
uiState: HomeState,
padding: PaddingValues,
onSettingClick: () -> Unit,
onCreateImageButtonClickFromStyle: () -> Unit,
onCreateImageButtonClickFromProfile: () -> Unit,
onCreateImageBtnClickFromStyle: () -> Unit,
onCreateImageBtnClickFromProfile: () -> Unit,
openProfileImageDialog: (Int) -> Unit,
dismissProfileImageDialog: () -> Unit,
getStyleProfileList: () -> Unit,
Expand Down Expand Up @@ -153,17 +153,17 @@ internal fun HomeScreen(
ProfileImageDialog(
profileImage = uiState.selectedProfileImage,
onCloseClick = dismissProfileImageDialog,
onCreateImageButtonClickFromProfile = {
onCreateImageBtnClickFromProfile = {
dismissProfileImageDialog()
onCreateImageButtonClickFromProfile()
onCreateImageBtnClickFromProfile()
},
)
}
HomeTopAppBar(onSettingClick)
HomeContent(
styleImageList = uiState.styleImageList,
profileImageList = uiState.profileImageList,
onCreateImageButtonClickFromStyle = onCreateImageButtonClickFromStyle,
onCreateImageBtnClickFromStyle = onCreateImageBtnClickFromStyle,
openProfileImageDialog = openProfileImageDialog,
setSelectedStyleImage = setSelectedStyleImage,
)
Expand All @@ -189,7 +189,7 @@ internal fun HomeTopAppBar(onSettingClick: () -> Unit) {
internal fun HomeContent(
styleImageList: List<StyleEntity>,
profileImageList: List<ProfileEntity>,
onCreateImageButtonClickFromStyle: () -> Unit,
onCreateImageBtnClickFromStyle: () -> Unit,
openProfileImageDialog: (Int) -> Unit,
setSelectedStyleImage: (Int) -> Unit,
) {
Expand All @@ -205,7 +205,7 @@ internal fun HomeContent(
item(span = StaggeredGridItemSpan.FullLine) {
HomeKeywordView(
styleImageList = styleImageList,
onCreateImageButtonClickFromStyle = onCreateImageButtonClickFromStyle,
onCreateImageBtnClickFromStyle = onCreateImageBtnClickFromStyle,
setSelectedStyleImage = setSelectedStyleImage,
)
}
Expand Down Expand Up @@ -236,7 +236,7 @@ internal fun HomeContent(
@Composable
internal fun HomeKeywordView(
styleImageList: List<StyleEntity>,
onCreateImageButtonClickFromStyle: () -> Unit,
onCreateImageBtnClickFromStyle: () -> Unit,
setSelectedStyleImage: (Int) -> Unit,
) {
val pageCount = styleImageList.size
Expand Down Expand Up @@ -296,7 +296,7 @@ internal fun HomeKeywordView(
)
Spacer(modifier = Modifier.height(32.dp))
ILabButton(
onClick = onCreateImageButtonClickFromStyle,
onClick = onCreateImageBtnClickFromStyle,
modifier = Modifier
.fillMaxWidth()
.padding(start = 20.dp, end = 20.dp)
Expand Down Expand Up @@ -364,7 +364,7 @@ internal fun ProfileImageItem(
internal fun ProfileImageDialog(
profileImage: ProfileEntity,
onCloseClick: () -> Unit,
onCreateImageButtonClickFromProfile: () -> Unit,
onCreateImageBtnClickFromProfile: () -> Unit,
) {
BasicAlertDialog(
onDismissRequest = onCloseClick,
Expand Down Expand Up @@ -409,7 +409,7 @@ internal fun ProfileImageDialog(
)
Spacer(modifier = Modifier.height(24.dp))
ILabButton(
onClick = onCreateImageButtonClickFromProfile,
onClick = onCreateImageBtnClickFromProfile,
modifier = Modifier
.fillMaxWidth()
.padding(start = 20.dp, end = 20.dp, bottom = 16.dp)
Expand All @@ -435,8 +435,8 @@ internal fun HomeScreenPreview() {
uiState = HomeState(),
padding = PaddingValues(0.dp),
onSettingClick = {},
onCreateImageButtonClickFromStyle = {},
onCreateImageButtonClickFromProfile = {},
onCreateImageBtnClickFromStyle = {},
onCreateImageBtnClickFromProfile = {},
openProfileImageDialog = {},
dismissProfileImageDialog = {},
getStyleProfileList = {},
Expand All @@ -452,6 +452,6 @@ fun ProfileImageDialogPreview() {
ProfileImageDialog(
profileImage = ProfileEntity("", "", ""),
onCloseClick = {},
onCreateImageButtonClickFromProfile = {},
onCreateImageBtnClickFromProfile = {},
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nexters.ilab.android.feature.home.viewmodel

sealed interface HomeSideEffect {
data class OnCreateImageButtonClickFromStyle(val selectedStyle: String) : HomeSideEffect
data class OnCreateImageButtonClickFromProfile(val selectedProfile: String) : HomeSideEffect
data class OnCreateImageBtnClickFromStyle(val selectedStyle: String) : HomeSideEffect
data class OnCreateImageBtnClickFromProfile(val selectedProfile: String) : HomeSideEffect
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class HomeViewModel @Inject constructor(
}
}

fun onCreateImageButtonClickFromStyle() = intent {
fun onCreateImageBtnClickFromStyle() = intent {
postSideEffect(
HomeSideEffect.OnCreateImageButtonClickFromStyle(
HomeSideEffect.OnCreateImageBtnClickFromStyle(
if (state.selectedStyle.name.isEmpty()) {
state.styleImageList[0].name
} else {
Expand All @@ -85,9 +85,9 @@ class HomeViewModel @Inject constructor(
)
}

fun onCreateImageButtonClickFromProfile() = intent {
fun onCreateImageBtnClickFromProfile() = intent {
postSideEffect(
HomeSideEffect.OnCreateImageButtonClickFromProfile(state.selectedProfileImage.name),
HomeSideEffect.OnCreateImageBtnClickFromProfile(state.selectedProfileImage.name),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ internal fun LoginRoute(

LoginScreen(
uiState = uiState,
onLoginClick = viewModel::onLoginButtonClick,
onLoginClick = viewModel::onLoginBtnClick,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LoginViewModel @Inject constructor(

override val container = container<LoginState, LoginSideEffect>(LoginState())

fun onLoginButtonClick() = intent {
fun onLoginBtnClick() = intent {
postSideEffect(LoginSideEffect.KakaoLogin)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ internal fun MyPageRoute(
onSettingClick = onSettingClick,
getUserInfo = viewModel::getUserInfo,
onShareBtnClick = viewModel::shareMyAlbum,
onDeleteBtnClick = {},
onDeleteBtnClick = viewModel::deleteMyAlbum,
onAlbumClick = viewModel::onAlbumClick,
dismissServerErrorDialog = viewModel::dismissServerErrorDialog,
dismissNetworkErrorDialog = viewModel::dismissNetworkErrorDialog,
Expand All @@ -143,7 +143,7 @@ internal fun MyPageScreen(
onSettingClick: () -> Unit,
getUserInfo: () -> Unit,
onShareBtnClick: () -> Unit,
onDeleteBtnClick: () -> Unit,
onDeleteBtnClick: (Int) -> Unit,
onAlbumClick: (Int) -> Unit,
dismissServerErrorDialog: () -> Unit,
dismissNetworkErrorDialog: () -> Unit,
Expand Down Expand Up @@ -203,7 +203,7 @@ internal fun MyPageContent(
userInfo: UserInfoEntity,
myAlbumImageList: ImmutableList<UserThumbnailEntity>,
onShareBtnClick: () -> Unit,
onDeleteBtnClick: () -> Unit,
onDeleteBtnClick: (Int) -> Unit,
onAlbumClick: (Int) -> Unit,
) {
val span: (LazyGridItemSpanScope) -> GridItemSpan = { GridItemSpan(2) }
Expand Down Expand Up @@ -240,7 +240,7 @@ internal fun MyPageContent(
MyAlbumImage(
myAlbum = myAlbumImageList[iter],
onShareBtnClick = onShareBtnClick,
onDeleteBtnClick = onDeleteBtnClick,
onDeleteBtnClick = { onDeleteBtnClick(iter) },
onAlbumClick = onAlbumClick,
index = iter,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
import com.nexters.ilab.android.core.common.ErrorHandlerActions
import com.nexters.ilab.android.core.common.handleException
import com.nexters.ilab.android.core.domain.repository.AuthRepository
import com.nexters.ilab.android.core.domain.repository.DeleteMyAlbumRepository
import com.nexters.ilab.android.core.domain.repository.FileRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toImmutableList
Expand All @@ -20,6 +21,7 @@ import javax.inject.Inject
class MyPageViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val fileRepository: FileRepository,
private val deleteMyAlbumRepository: DeleteMyAlbumRepository,
) : ViewModel(), ContainerHost<MyPageState, MyPageSideEffect>, ErrorHandlerActions {
override val container = container<MyPageState, MyPageSideEffect>(MyPageState())

Expand Down Expand Up @@ -51,6 +53,29 @@ class MyPageViewModel @Inject constructor(
}
}

fun deleteMyAlbum(index: Int) = intent {
viewModelScope.launch {
reduce {
state.copy(isLoading = true)
}
deleteMyAlbumRepository.deleteMyAlbum(index)
.onSuccess { userInfo ->
reduce {
state.copy(
myAlbumFullImageList = userInfo.thumbnails.toImmutableList(),
)
}
}.onFailure { exception ->
handleException(exception, this@MyPageViewModel)
}
reduce {
state.copy(
isLoading = false,
)
}
}
}

private fun setSelectedMyAlbum(index: Int) = intent {
reduce {
state.copy(selectedMyAlbum = index)
Expand Down
Loading