Skip to content

Commit

Permalink
🎨 프로필 수정 페이지 리펙토링 및 프로필 이미지 나오지 않는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-j0y committed Aug 15, 2024
1 parent 9b885bb commit d9b796c
Show file tree
Hide file tree
Showing 30 changed files with 347 additions and 220 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/xml/path_provider.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-cache-path name="my_images" path="/"/>
<external-path name="my_images" path="/"/>
</paths>
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.whyranoid.data.datasource.account

import com.whyranoid.data.getResult
import com.whyranoid.data.model.account.ChangeMyInfoRequest
import com.whyranoid.data.model.account.SignUpRequest
import com.whyranoid.data.model.account.toLoginData
import com.whyranoid.data.model.account.toUserInfo
import com.whyranoid.domain.datasource.AccountDataSource
import com.whyranoid.domain.model.account.LoginData
import com.whyranoid.domain.model.account.UserInfo
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File

class AccountDataSourceImpl(private val accountService: AccountService) : AccountDataSource {
override suspend fun signUp(
Expand Down Expand Up @@ -54,12 +59,18 @@ class AccountDataSourceImpl(private val accountService: AccountService) : Accoun

override suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean> {
return kotlin.runCatching {
var imagePart: MultipartBody.Part? = null

if (profileUrl != null) {
val file = File(profileUrl)
val fileBody = RequestBody.create(MediaType.parse("image/*"), file)
imagePart = MultipartBody.Part.createFormData("profileImg", file.name, fileBody)
}

val response = accountService.changeMyInfo(
walkieId,
ChangeMyInfoRequest(
profileImg = profileUrl ?: "",
nickname = nickName
)
imagePart,
nickName
)
if (response.isSuccessful) {
return Result.success(true)
Expand All @@ -68,4 +79,10 @@ class AccountDataSourceImpl(private val accountService: AccountService) : Accoun
}
}
}

override suspend fun getUserInfo(walkieId: Long): Result<UserInfo> {
return kotlin.runCatching {
accountService.getMyInfo(walkieId).getResult { it.toUserInfo() }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.whyranoid.data.datasource.account

import com.whyranoid.data.API
import com.whyranoid.data.model.account.ChangeMyInfoRequest
import com.whyranoid.data.model.account.ChangeMyInfoResponse
import com.whyranoid.data.model.account.LoginDataResponse
import com.whyranoid.data.model.account.NickCheckResponse
import com.whyranoid.data.model.account.SignUpRequest
import com.whyranoid.data.model.account.SignUpResponse
import com.whyranoid.data.model.account.UserInfoResponse
import okhttp3.MultipartBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Query

interface AccountService {
Expand All @@ -31,7 +33,13 @@ interface AccountService {

@POST(API.WalkingControl.MY)
suspend fun changeMyInfo(
@Query("walkieId") id: Long,
@Body myInfoRequest: ChangeMyInfoRequest
@Part("walkieId") id: Long,
@Part profileImg: MultipartBody.Part?,
@Part("nickname") nickName: String,
): Response<ChangeMyInfoResponse>

@GET(API.WalkingControl.MY)
suspend fun getMyInfo(
@Query("walkieId") id: Long
): Response<UserInfoResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.whyranoid.data.model.account

import com.whyranoid.domain.model.account.UserInfo

data class UserInfoResponse (
val nickname: String,
val profileImg: String?
)

fun UserInfoResponse.toUserInfo() = UserInfo(
name = "", // TODO 수정
nickname = nickname,
profileImg = profileImg
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.util.Log
import com.whyranoid.data.AccountDataStore
import com.whyranoid.domain.datasource.AccountDataSource
import com.whyranoid.domain.model.account.Sex
import com.whyranoid.domain.model.account.UserInfo
import com.whyranoid.domain.repository.AccountRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
Expand All @@ -14,13 +15,13 @@ class AccountRepositoryImpl(
) : AccountRepository {

override val authId: Flow<String?> = accountDataStore.authId
override val uId: Flow<Long?> = accountDataStore.uId
override val walkieId: Flow<Long?> = accountDataStore.uId
override val userName: Flow<String?> = accountDataStore.userName
override val nickName: Flow<String?> = accountDataStore.nickName
override val profileUrl: Flow<String?> = accountDataStore.profileUrl

override suspend fun getUID(): Long {
return requireNotNull(uId.first())
return requireNotNull(walkieId.first())
}

override suspend fun signUp(
Expand Down Expand Up @@ -102,4 +103,8 @@ class AccountRepositoryImpl(
return Result.failure(Exception("마이페이지 정보 수정 실패"))
}
}

override suspend fun getUserInfo(walkieId: Long): Result<UserInfo> {
return accountDataSource.getUserInfo(walkieId)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.whyranoid.domain.datasource

import com.whyranoid.domain.model.account.LoginData
import com.whyranoid.domain.model.account.UserInfo

interface AccountDataSource {
suspend fun signUp(
Expand All @@ -16,4 +17,6 @@ interface AccountDataSource {
suspend fun signIn(authorId: String): Result<LoginData>

suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean>

suspend fun getUserInfo(walkieId: Long): Result<UserInfo>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.whyranoid.domain.model.account

data class UserInfo (
val name: String,
val profileImg: String?,
val nickname: String
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.whyranoid.domain.repository

import com.whyranoid.domain.model.account.Sex
import com.whyranoid.domain.model.account.UserInfo
import kotlinx.coroutines.flow.Flow

interface AccountRepository {

val authId: Flow<String?>
val uId: Flow<Long?>
val walkieId: Flow<Long?>
val userName: Flow<String?>
val nickName: Flow<String?>
val profileUrl: Flow<String?>
Expand All @@ -33,4 +34,6 @@ interface AccountRepository {
suspend fun checkNickName(nickName: String): Result<Pair<Boolean, String>>

suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean>

suspend fun getUserInfo(walkieId: Long): Result<UserInfo>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GetChallengePreviewsByTypeUseCase(
) {
suspend operator fun invoke(type: ChallengeType): List<ChallengePreview> {
return challengeRepository.getChallengePreviewsByType(
accountRepository.uId.first()?.toInt() ?: -1, type
accountRepository.walkieId.first()?.toInt() ?: -1, type
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GetFollowingsPostsUseCase(
private val postRepository: PostRepository,
) {
suspend operator fun invoke(): Result<List<Post>> {
val myUid = requireNotNull(accountRepository.uId.first())
val myUid = requireNotNull(accountRepository.walkieId.first())
return postRepository.getMyFollowingsPost(myUid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class GetMyUidUseCase(
private val accountRepository: AccountRepository,
) {
suspend operator fun invoke(): Result<Long> {
return runCatching { requireNotNull(accountRepository.uId.firstOrNull()) }
return runCatching { requireNotNull(accountRepository.walkieId.firstOrNull()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LikePostUseCase(
) {

suspend operator fun invoke(postId: Long): Result<Long> {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
return communityRepository.likePost(postId, uid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UploadPostUseCase @Inject constructor(
history: String,
imagePath: String,
): Result<String> {
return accountRepository.uId.first()?.let { uid ->
return accountRepository.walkieId.first()?.let { uid ->
postRepository.uploadPost(uid, content, colorMode, history, imagePath)
} ?: kotlin.run {
Result.failure(Exception("Account Error"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FollowUseCase(
) {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
followRepository.follow(uid, otherUId).getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RemoveFollowerUseCase(
) {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
followRepository.unfollow(otherUId, uid).getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SendCommentUseCase(
postId: Long,
content: String,
): Result<Unit> {
val commenterId = accountRepository.uId.first() ?: return Result.failure(Exception("uid is null"))
val commenterId = accountRepository.walkieId.first() ?: return Result.failure(Exception("uid is null"))
return postRepository.sendComment(
postId,
commenterId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UnFollowUseCase(
) {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
followRepository.unfollow(uid, otherUId).getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GetRunningFollowerUseCase(
var followings = listOf<User>()
var runningFollowings = listOf<User>()
kotlin.runCatching {
id = requireNotNull(accountRepository.uId.first())
id = requireNotNull(accountRepository.walkieId.first())
}
return callbackFlow {
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RunningFinishUseCase(
private val runningRepository: RunningRepository,
) {
suspend operator fun invoke(): Result<Unit> {
accountRepository.uId.first()?.let { id ->
accountRepository.walkieId.first()?.let { id ->
return runningRepository.finishRunning(id)
}
return Result.failure(Exception("ID 정보 없음"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RunningStartUseCase(
private val runningRepository: RunningRepository,
) {
suspend operator fun invoke(): Result<Long> {
accountRepository.uId.first()?.let { id ->
accountRepository.walkieId.first()?.let { id ->
return runningRepository.startRunning(id)
}
return Result.failure(Exception("ID 정보 없음"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SendLikeUseCase(
) {
suspend operator fun invoke(receiverId: Long): Result<Unit> {
return kotlin.runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
runningRepository.sendLike(uid, receiverId).onSuccess {
return Result.success(Unit)
}.onFailure {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ androidx-core = "1.13.1"
androidx-appcompat = "1.6.1"
androidx-constraintlayout = "2.1.4"
naver-maps-android-sdk = "3.16.2"
hilt = "2.44"
hilt = "2.48.1"
javax-inject = "1"

android-material = "1.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -82,7 +83,7 @@ fun MyPageScreen(
var uid by rememberSaveable { mutableStateOf<Long?>(null) }

LaunchedEffect(Unit) {
val myUid = requireNotNull(viewModel.accountRepository.uId.first())
val myUid = requireNotNull(viewModel.accountRepository.walkieId.first())
uid = myUid
viewModel.getUserDetail(myUid, null)
viewModel.getUserBadges(myUid)
Expand Down Expand Up @@ -196,9 +197,10 @@ fun UserPageContent(
AsyncImage(
model = userDetail.user.imageUrl,
contentDescription = "유저 프로필 이미지",
contentScale = ContentScale.Crop,
modifier = Modifier
.clip(shape = CircleShape)
.size(70.dp),
.size(64.dp),
)
Spacer(modifier = Modifier.width(20.dp))

Expand Down
Loading

0 comments on commit d9b796c

Please sign in to comment.