From 022f3411b6fc0e9f777477b5d4e1a3a193f220b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A7=84=EC=84=B1?= Date: Wed, 6 Dec 2023 23:24:38 +0900 Subject: [PATCH] =?UTF-8?q?#172=20feat=20:=20Signup=20=EC=82=AC=EC=A7=84?= =?UTF-8?q?=20=EC=9E=88=EC=9D=84=EB=95=8C=20=EC=97=86=EC=9D=84=EB=95=8C=20?= =?UTF-8?q?=EB=B6=84=EA=B8=B0=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nibobnebob/data/remote/IntroApi.kt | 12 ++++++ .../data/repository/IntroRepositoryImpl.kt | 42 +++++++++++++------ .../domain/repository/IntroRepository.kt | 2 +- .../ui/intro/signup/DetailSignupFragment.kt | 8 ++-- .../ui/intro/signup/DetailSignupViewModel.kt | 2 +- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt index 739d6830..9a8d7542 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt @@ -27,6 +27,18 @@ interface IntroApi { @Part profileImage: MultipartBody.Part ): Response + @Multipart + @POST("api/user") + suspend fun signupNoImage( + @Part("email") email: RequestBody, + @Part("password") password: RequestBody, + @Part("provider") provider: RequestBody, + @Part("nickName") nickName: RequestBody, + @Part("region") region: RequestBody, + @Part("birthdate") birthdate: RequestBody, + @Part("isMale") isMale: Boolean, + ): Response + @POST("api/auth/social-login") suspend fun loginNaver( @Header("Authorization") token: String diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt index 7bbc78a2..c6d06f74 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt @@ -27,21 +27,37 @@ class IntroRepositoryImpl @Inject constructor( region: RequestBody, birthdate: RequestBody, isMale: Boolean, - profileImage: MultipartBody.Part + profileImage: MultipartBody.Part? ): Flow> = flow { - val result = runRemote { - api.signup( - email, - password, - provider, - nickName, - region, - birthdate, - isMale, - profileImage - ) + profileImage?.let { image -> + val result = runRemote { + api.signup( + email, + password, + provider, + nickName, + region, + birthdate, + isMale, + image + ) + } + emit(result) + } ?: run { + val result = runRemote { + api.signupNoImage( + email, + password, + provider, + nickName, + region, + birthdate, + isMale, + ) + } + emit(result) } - emit(result) + } override fun loginNaver(token: String): Flow> = flow { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/domain/repository/IntroRepository.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/domain/repository/IntroRepository.kt index 2af8f6c6..1af3d3af 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/domain/repository/IntroRepository.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/domain/repository/IntroRepository.kt @@ -16,7 +16,7 @@ interface IntroRepository { region: RequestBody, birthdate: RequestBody, isMale: Boolean, - profileImage: MultipartBody.Part + profileImage: MultipartBody.Part? ): Flow> fun loginNaver( diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupFragment.kt index 6ee6d361..d67a1e0b 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupFragment.kt @@ -54,10 +54,12 @@ class DetailSignupFragment : } } - private fun initImageObserver(){ + private fun initImageObserver() { repeatOnStarted { - parentViewModel.image.collect{ - viewModel.setImage(it, it.toMultiPart(requireContext())) + parentViewModel.image.collect { + if (it.isNotBlank()) { + viewModel.setImage(it, it.toMultiPart(requireContext(), "profileImage")) + } } } } diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupViewModel.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupViewModel.kt index dd0ea71e..f93b2c88 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupViewModel.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/signup/DetailSignupViewModel.kt @@ -61,7 +61,7 @@ class DetailSignupViewModel @Inject constructor( val birth = MutableStateFlow("") val location = MutableStateFlow("") val profileImg = MutableStateFlow("") - private lateinit var profileFile: MultipartBody.Part + private var profileFile: MultipartBody.Part? = null val isDataReady = combine(