Skip to content

Commit

Permalink
[FEAT/#66] 프로필 수정 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
seongh06 committed Oct 16, 2024
1 parent 9d52e38 commit 206080e
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import okhttp3.RequestBody
import umc.everyones.lck.data.dto.BaseResponse
import umc.everyones.lck.data.dto.request.mypage.CancelHostViewingPartyMypageRequestDto
import umc.everyones.lck.data.dto.request.mypage.CancelParticipateViewingPartyMypageRequestDto
import umc.everyones.lck.data.dto.request.mypage.UpdateProfilesRequestDto
import umc.everyones.lck.data.dto.request.mypage.UpdateTeamRequestDto
import umc.everyones.lck.data.dto.response.NonBaseResponse
import umc.everyones.lck.data.dto.response.mypage.CommentsMypageResponseDto
Expand Down Expand Up @@ -33,7 +34,7 @@ interface MypageDataSource {

suspend fun withdraw(): NonBaseResponse

suspend fun updateProfiles(profileImage: MultipartBody.Part?, updateProfileRequest: RequestBody): BaseResponse<UpdateProfilesResponseDto>
suspend fun updateProfiles(profileImage: MultipartBody.Part, request: UpdateProfilesRequestDto): BaseResponse<UpdateProfilesResponseDto>

suspend fun updateTeam(requestDto: UpdateTeamRequestDto ): BaseResponse<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import umc.everyones.lck.data.datasource.MypageDataSource
import umc.everyones.lck.data.dto.BaseResponse
import umc.everyones.lck.data.dto.request.mypage.CancelHostViewingPartyMypageRequestDto
import umc.everyones.lck.data.dto.request.mypage.CancelParticipateViewingPartyMypageRequestDto
import umc.everyones.lck.data.dto.request.mypage.UpdateProfilesRequestDto
import umc.everyones.lck.data.dto.request.mypage.UpdateTeamRequestDto
import umc.everyones.lck.data.dto.response.NonBaseResponse
import umc.everyones.lck.data.dto.response.mypage.CommentsMypageResponseDto
Expand Down Expand Up @@ -47,8 +48,8 @@ class MypageDataSourceImpl @Inject constructor(
override suspend fun withdraw(): NonBaseResponse =
mypageService.withdraw()

override suspend fun updateProfiles(profileImage: MultipartBody.Part?, updateProfileRequest: RequestBody): BaseResponse<UpdateProfilesResponseDto> =
mypageService.updateProfiles(profileImage, updateProfileRequest)
override suspend fun updateProfiles(profileImage: MultipartBody.Part, updateProfileRequest: UpdateProfilesRequestDto): BaseResponse<UpdateProfilesResponseDto> =
mypageService.updateProfiles(profileImage, updateProfileRequest.updateProfileRequest)

override suspend fun updateTeam(requestDto: UpdateTeamRequestDto): BaseResponse<Boolean> =
mypageService.updateTeam(requestDto)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package umc.everyones.lck.data.dto.request.mypage

import okhttp3.MultipartBody
import okhttp3.RequestBody
import umc.everyones.lck.data.UpdateProfileRequest

data class UpdateProfilesRequestDto(
val profileImage: MultipartBody.Part,
val updateProfileRequest: UpdateProfileRequestElementDto
val updateProfileRequest: RequestBody
) {
data class UpdateProfileRequestElementDto(
val nickname: String,
val isDefaultImage: Boolean
val nickname: String?,
val defaultImage: Boolean
)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package umc.everyones.lck.data.dto.response.mypage

import umc.everyones.lck.domain.model.response.mypage.UpdateProfilesModel
import umc.everyones.lck.domain.model.response.mypage.UpdateProfilesResponseModel

data class UpdateProfilesResponseDto(
val updatedProfileImageUrl: String,
val updatedProfileImageUrl: String,
val updatedNickname: String
){
fun toUpdateProfilesModel() =
UpdateProfilesModel(updatedProfileImageUrl, updatedNickname)
fun toUpdateProfilesResponseModel() =
UpdateProfilesResponseModel(updatedProfileImageUrl, updatedNickname)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package umc.everyones.lck.data.repositoryImpl.mypage
import okhttp3.MultipartBody
import okhttp3.RequestBody
import umc.everyones.lck.data.datasource.MypageDataSource
import umc.everyones.lck.data.dto.request.mypage.CancelParticipateViewingPartyMypageRequestDto
import umc.everyones.lck.data.dto.request.mypage.UpdateProfilesRequestDto
import umc.everyones.lck.data.dto.response.NonBaseResponse
import umc.everyones.lck.domain.model.request.mypage.CancelHostViewingPartyMypageModel
import umc.everyones.lck.domain.model.request.mypage.CancelParticipateViewingPartyMypageModel
import umc.everyones.lck.domain.model.request.mypage.UpdateProfilesRequestModel
import umc.everyones.lck.domain.model.request.mypage.UpdateTeamModel
import umc.everyones.lck.domain.model.response.mypage.CommentsMypageModel
import umc.everyones.lck.domain.model.response.mypage.HostViewingPartyMypageModel
import umc.everyones.lck.domain.model.response.mypage.InquiryProfilesModel
import umc.everyones.lck.domain.model.response.mypage.ParticipateViewingPartyMypageModel
import umc.everyones.lck.domain.model.response.mypage.PostsMypageModel
import umc.everyones.lck.domain.model.response.mypage.UpdateProfilesModel
import umc.everyones.lck.domain.model.response.mypage.UpdateProfilesResponseModel
import umc.everyones.lck.domain.repository.MypageRepository
import javax.inject.Inject

Expand Down Expand Up @@ -47,8 +46,8 @@ class MypageRepositoryImpl @Inject constructor(
override suspend fun withdraw(): Result<NonBaseResponse> =
runCatching { mypageDataSource.withdraw() }

override suspend fun updateProfiles(profileImage: MultipartBody.Part?, updateProfileRequest: RequestBody): Result<UpdateProfilesModel> =
runCatching { mypageDataSource.updateProfiles(profileImage, updateProfileRequest).data.toUpdateProfilesModel() }
override suspend fun updateProfiles(profileImage: MultipartBody.Part, requestModel: UpdateProfilesRequestModel): Result<UpdateProfilesResponseModel> =
runCatching { mypageDataSource.updateProfiles(profileImage, requestModel.toUpdateProfilesRequestDto()).data.toUpdateProfilesResponseModel()}

override suspend fun updateTeam(request: UpdateTeamModel): Result<Boolean> =
runCatching { mypageDataSource.updateTeam(request.toUpdateTeamRequestDto()).data }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import umc.everyones.lck.data.UpdateProfileRequest
import umc.everyones.lck.data.dto.BaseResponse
import umc.everyones.lck.data.dto.request.mypage.CancelHostViewingPartyMypageRequestDto
import umc.everyones.lck.data.dto.request.mypage.CancelParticipateViewingPartyMypageRequestDto
import umc.everyones.lck.data.dto.request.mypage.UpdateProfilesRequestDto
import umc.everyones.lck.data.dto.request.mypage.UpdateTeamRequestDto
import umc.everyones.lck.data.dto.response.NonBaseResponse
import umc.everyones.lck.data.dto.response.mypage.CommentsMypageResponseDto
Expand Down Expand Up @@ -73,8 +74,8 @@ interface MypageService {
@Multipart
@PATCH("my-pages/profiles")
suspend fun updateProfiles(
@Part profileImage: MultipartBody.Part?,
@Part("updateProfileRequest") updateProfileRequest: RequestBody
@Part profileImage: MultipartBody.Part,
@Part("updateProfileRequest") request: RequestBody
): BaseResponse<UpdateProfilesResponseDto>

@PATCH("my-pages/my-team")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package umc.everyones.lck.domain.model.request.mypage

import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.toRequestBody
import umc.everyones.lck.data.dto.request.mypage.UpdateProfilesRequestDto

data class UpdateProfilesRequestModel(
val profileImage: MultipartBody.Part,
val updateProfileRequest: UpdateProfileRequestElementModel
) {
data class UpdateProfileRequestElementModel(
val nickname: String?,
val defaultImage: Boolean
) {
fun toUpdateProfileRequestElementDto() =
Gson().toJson(this).toRequestBody("application/json".toMediaTypeOrNull())
}
fun toUpdateProfilesRequestDto() =
UpdateProfilesRequestDto(profileImage, updateProfileRequest.toUpdateProfileRequestElementDto())
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package umc.everyones.lck.domain.model.response.mypage

data class UpdateProfilesModel(
val updatedProfileImageUrl: String,
data class UpdateProfilesResponseModel(
val updatedProfileImageUrl: String,
val updatedNickname: String
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package umc.everyones.lck.domain.repository

import okhttp3.MultipartBody
import okhttp3.RequestBody
import umc.everyones.lck.data.UpdateProfileRequest
import umc.everyones.lck.data.dto.request.mypage.UpdateTeamRequestDto
import umc.everyones.lck.data.dto.response.NonBaseResponse
import umc.everyones.lck.domain.model.request.mypage.CancelHostViewingPartyMypageModel
import umc.everyones.lck.domain.model.request.mypage.CancelParticipateViewingPartyMypageModel
import umc.everyones.lck.domain.model.request.mypage.UpdateProfilesRequestModel
import umc.everyones.lck.domain.model.request.mypage.UpdateTeamModel
import umc.everyones.lck.domain.model.response.mypage.CommentsMypageModel
import umc.everyones.lck.domain.model.response.mypage.HostViewingPartyMypageModel
import umc.everyones.lck.domain.model.response.mypage.InquiryProfilesModel
import umc.everyones.lck.domain.model.response.mypage.ParticipateViewingPartyMypageModel
import umc.everyones.lck.domain.model.response.mypage.PostsMypageModel
import umc.everyones.lck.domain.model.response.mypage.UpdateProfilesModel
import umc.everyones.lck.domain.model.response.mypage.UpdateProfilesResponseModel

interface MypageRepository {
suspend fun inquiryProfiles(): Result<InquiryProfilesModel>
Expand All @@ -34,7 +30,7 @@ interface MypageRepository {

suspend fun withdraw(): Result<NonBaseResponse>

suspend fun updateProfiles(profileImage: MultipartBody.Part?, updateProfileRequest: RequestBody): Result<UpdateProfilesModel>
suspend fun updateProfiles(profileImage: MultipartBody.Part, requestModel: UpdateProfilesRequestModel): Result<UpdateProfilesResponseModel>

suspend fun updateTeam(request: UpdateTeamModel): Result<Boolean>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package umc.everyones.lck.presentation.mypage
import android.app.Activity
import android.content.ContentValues.TAG
import android.content.Intent
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.Toast
Expand All @@ -15,6 +17,7 @@ import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.bumptech.glide.Glide
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.FragmentMypageProfileEditBinding
import umc.everyones.lck.presentation.MainActivity
Expand Down Expand Up @@ -54,9 +57,9 @@ class MyPageProfileEditFragment : BaseFragment<FragmentMypageProfileEditBinding>

myPageViewModel.updateProfileResult.observe(viewLifecycleOwner) { result ->
if (result != null) {
Log.d(TAG,"프로필 수정 성공")
Timber.d("프로필 수정 성공")
} else {
Log.e(TAG, "프로필 수정 실패")
Timber.e("프로필 수정 실패")
}
}
myPageViewModel.profileData.observe(viewLifecycleOwner) { profile ->
Expand Down Expand Up @@ -122,33 +125,31 @@ class MyPageProfileEditFragment : BaseFragment<FragmentMypageProfileEditBinding>

// 현재 프로필 이미지 URI 가져오기
val currentProfileImageUri = myPageViewModel.profileUri.value
val currentNickname = myPageViewModel.nickName.value

// 업데이트할 닉네임과 이미지 결정
// 업데이트할 닉네임 결정 (닉네임이 비어있으면 null로 설정)
val finalNickname = if (nicknameInput.isNotEmpty()) {
nicknameInput // 닉네임이 비어있지 않으면 입력값 사용
} else {
currentNickname // 닉네임이 비어있으면 현재 닉네임 사용
null // 닉네임이 비어있으면 null로 설정
}

val finalProfileImageUri = if (nicknameInput.isNotEmpty()) {
// 닉네임이 변경된 경우, 현재 프로필 이미지를 사용
currentProfileImageUri
// 프로필 이미지 결정
val finalProfileImageUri = if (binding.ivMypageProfileEditProfile.drawable != null) {
// 프로필 이미지가 변경된 경우
val bitmap = (binding.ivMypageProfileEditProfile.drawable as BitmapDrawable).bitmap // Bitmap으로 변환
val path = MediaStore.Images.Media.insertImage(requireContext().contentResolver, bitmap, "ProfileImage", null) // URI로 변환
Uri.parse(path) // URI로 변환하여 반환
} else {
// 닉네임이 변경되지 않은 경우, 프로필 이미지가 변경된 경우에만 새 이미지 사용
currentProfileImageUri // 현재 프로필 이미지를 유지
// 프로필 이미지가 변경되지 않은 경우 현재 프로필 이미지를 유지
currentProfileImageUri
}


// 업데이트할 데이터가 유효할 경우 ViewModel 호출
// 업데이트할 데이터가 유효할 경우 ViewModel 호출
myPageViewModel.updateProfile(finalNickname, finalProfileImageUri)

// 프로필 업데이트 결과를 관찰하여 성공 여부에 따라 화면 전환
myPageViewModel.updateProfileResult.observe(viewLifecycleOwner) { result ->
navigator.navigate(R.id.action_myPageProfileEditFragment_to_myPageProfileFragment)
}
// 프로필 업데이트 후 화면 전환
navigator.navigate(R.id.action_myPageProfileEditFragment_to_myPageProfileFragment)
}

}

private fun setInitialState() {
Expand Down
Loading

0 comments on commit 206080e

Please sign in to comment.