Skip to content

Commit

Permalink
[FIX] #26 회원가입 로직
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYJH committed Feb 21, 2022
1 parent 1ad4800 commit 2a91b82
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 17 deletions.
1 change: 1 addition & 0 deletions EarthGardener/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import team.gdsc.earthgardener.data.datasource.profile.ProfileDataSource
import team.gdsc.earthgardener.data.datasource.profile.ProfileRemoteDataSource
import team.gdsc.earthgardener.data.datasource.signin.SignInDataSource
import team.gdsc.earthgardener.data.datasource.signin.SignInRemoteDataSource
import team.gdsc.earthgardener.data.datasource.signup.SignUpDataSource
import team.gdsc.earthgardener.data.datasource.signup.SignUpRemoteDataSource

val dataSourceModule = module {
single<CheckEmailDataSource> { CheckEmailRemoteDataSource(get()) }
Expand All @@ -24,4 +26,5 @@ val dataSourceModule = module {
single<PostDataSource>{ PostRemoteDataSource(get()) }
single<SignInDataSource>{ SignInRemoteDataSource(get()) }
single<ProfileDataSource>{ ProfileRemoteDataSource(get())}
single<SignUpDataSource>{ SignUpRemoteDataSource(get())}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import team.gdsc.earthgardener.data.repository.tree.TreeNameRepositoryImpl
import team.gdsc.earthgardener.data.repository.PostRepositoryImpl
import team.gdsc.earthgardener.data.repository.profile.ProfileRepositoryImpl
import team.gdsc.earthgardener.data.repository.signin.SignInRepositoryImpl
import team.gdsc.earthgardener.data.repository.signup.SignUpRepositoryImpl
import team.gdsc.earthgardener.domain.email.CheckEmailRepository
import team.gdsc.earthgardener.domain.nickname.CheckNicknameRepository
import team.gdsc.earthgardener.domain.repository.tree.TreeInfoRepository
import team.gdsc.earthgardener.domain.repository.tree.TreeNameRepository
import team.gdsc.earthgardener.domain.post.PostRepository
import team.gdsc.earthgardener.domain.profile.ProfileRepository
import team.gdsc.earthgardener.domain.signin.SignInRepository
import team.gdsc.earthgardener.domain.signup.SignUpRepository

val repositoryModule = module {
single<CheckEmailRepository> { CheckEmailRepositoryImpl(get()) }
Expand All @@ -24,4 +26,5 @@ val repositoryModule = module {
single<PostRepository>{ PostRepositoryImpl(get()) }
single<SignInRepository>{ SignInRepositoryImpl(get()) }
single<ProfileRepository>{ ProfileRepositoryImpl(get())}
single<SignUpRepository>{ SignUpRepositoryImpl(get())}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import team.gdsc.earthgardener.presentation.post.viewmodel.PostFormViewModel
import team.gdsc.earthgardener.presentation.user.login.viewModel.SignInViewModel
import team.gdsc.earthgardener.presentation.user.signup.nickname.viewModel.CheckNicknameViewModel
import team.gdsc.earthgardener.presentation.user.signup.emailpw.viewModel.CheckEmailViewModel
import team.gdsc.earthgardener.presentation.user.signup.viewModel.SignUpViewModel

val viewModelModule = module {
viewModel { CheckEmailViewModel(get()) }
viewModel { CheckNicknameViewModel(get()) }
//viewModel { CheckEmailViewModel(get()) }
//viewModel { CheckNicknameViewModel(get()) }
viewModel { MainViewModel(get(), get(), get(), get()) }
viewModel { PostFormViewModel(get()) }
viewModel { SignInViewModel(get())}
viewModel { SignUpViewModel(get(), get(), get())}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.gdsc.earthgardener.presentation.user.signup.emailpw

import android.annotation.SuppressLint
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
Expand All @@ -9,18 +10,21 @@ import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import team.gdsc.earthgardener.R
import team.gdsc.earthgardener.databinding.FragmentEmailPwBinding
import team.gdsc.earthgardener.presentation.base.BaseFragment
import team.gdsc.earthgardener.presentation.user.signup.nickname.NickNameFragment
import team.gdsc.earthgardener.presentation.user.signup.SignUpActivity
import team.gdsc.earthgardener.presentation.user.signup.emailpw.viewModel.CheckEmailViewModel
import team.gdsc.earthgardener.presentation.user.signup.viewModel.SignUpViewModel
import java.util.regex.Pattern

class EmailPwFragment : BaseFragment<FragmentEmailPwBinding>(R.layout.fragment_email_pw) {

private val checkEmailViewModel: CheckEmailViewModel by viewModel()
private val checkEmailViewModel: SignUpViewModel by sharedViewModel()

private var emailCode: String?= null
private var checkEmailCode = false

Expand All @@ -29,7 +33,7 @@ class EmailPwFragment : BaseFragment<FragmentEmailPwBinding>(R.layout.fragment_e
checkEmailPattern()
checkEmailWatcher()
getCodeEvent()
observeCheckEmailCode()
//observeCheckEmailCode()
checkCode()
etPasswordWatcher()
btnNextEvent()
Expand Down Expand Up @@ -79,10 +83,12 @@ class EmailPwFragment : BaseFragment<FragmentEmailPwBinding>(R.layout.fragment_e
}

private fun observeCheckEmailCode(){
checkEmailViewModel.currentEmail.observe(this, Observer{
Log.d("code", it.toString())
emailCode = it.toString()
})
/*
checkEmailViewModel.currentEmail.observe(viewLifecycleOwner){
//emailCode = it.toString()
}
*/
}

private fun checkCode(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import team.gdsc.earthgardener.domain.email.CheckEmailRepository

class CheckEmailViewModel(private val checkEmailRepository: CheckEmailRepository)
: ViewModel() {

/*
private val _currentEmail = MutableLiveData<String>()
val currentEmail : LiveData<String>
get() = _currentEmail
Expand All @@ -33,4 +33,6 @@ class CheckEmailViewModel(private val checkEmailRepository: CheckEmailRepository
it.printStackTrace()
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okio.BufferedSink
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import retrofit2.Call
import retrofit2.Callback
Expand All @@ -31,11 +32,14 @@ import team.gdsc.earthgardener.presentation.user.signup.retrofit.SignUpRequest
import team.gdsc.earthgardener.presentation.user.signup.retrofit.SignUpResponse
import team.gdsc.earthgardener.presentation.user.signup.retrofit.SignUpRetrofitClient
import team.gdsc.earthgardener.presentation.user.signup.retrofit.SignUpRetrofitInterface
import team.gdsc.earthgardener.presentation.user.signup.viewModel.SignUpViewModel
import java.lang.Exception

class NickNameFragment : BaseFragment<FragmentNickNameBinding>(R.layout.fragment_nick_name) {

private val checkNicknameViewModel: CheckNicknameViewModel by viewModel()
private val signUpViewModel : SignUpViewModel by sharedViewModel()

//private val checkNicknameViewModel: CheckNicknameViewModel by viewModel()
private val OPEN_GALLERY = 1

private var email: String? =null
Expand All @@ -50,6 +54,7 @@ class NickNameFragment : BaseFragment<FragmentNickNameBinding>(R.layout.fragment
btnFinishActive()
observeCheckNickname()
btnFinishEvent()
observeSignUp()

email = arguments!!.getString("email", "error")
pw = arguments!!.getString("pw", "error")
Expand Down Expand Up @@ -126,13 +131,13 @@ class NickNameFragment : BaseFragment<FragmentNickNameBinding>(R.layout.fragment
signUpActivity.binding.btnNext.setOnClickListener {
//signUpActivity.finish()
// 먼저 닉네임 중복 여부 판단
checkNicknameViewModel.nickname = binding.etSignUpNickname.text.toString()
checkNicknameViewModel.getNickname()
signUpViewModel.nickname = binding.etSignUpNickname.text.toString()
signUpViewModel.getNickname()
}
}

private fun observeCheckNickname(){
checkNicknameViewModel.currentStatus.observe(this, Observer{
signUpViewModel.currentStatus.observe(this, Observer{
if(it.toString() == "200"){
// 회원가입 post하기
var requestEmail = RequestBody.create("text/plain".toMediaTypeOrNull(), email.toString())
Expand All @@ -143,14 +148,27 @@ class NickNameFragment : BaseFragment<FragmentNickNameBinding>(R.layout.fragment
signUpMap["pw"] = requestPW
signUpMap["nickname"] = requestNickname

postSignUpData(signUpMap, img!!)
signUpViewModel.map = signUpMap
signUpViewModel.image = img!!
signUpViewModel.postSignUp()
//postSignUpData(signUpMap, img!!)
}else if(it.toString() == "409"){
Toast.makeText(context, "이미 존재하는 닉네임입니다", Toast.LENGTH_SHORT).show()
binding.etSignUpNickname.text.clear()
}
})
}

private fun observeSignUp(){
signUpViewModel.isSignUp.observe(viewLifecycleOwner){
if(it){
Log.d("result", "success")
val signUpActivity = activity as SignUpActivity
signUpActivity.finish()
}
}
}

private fun postSignUpData(data: HashMap<String, RequestBody>, image: MultipartBody.Part){
val signUpInterface = SignUpRetrofitClient.sRetrofit.create(SignUpRetrofitInterface::class.java)
Log.d("signup", "hi")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,103 @@
package team.gdsc.earthgardener.presentation.user.signup.viewModel

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import okhttp3.MultipartBody
import okhttp3.RequestBody
import team.gdsc.earthgardener.domain.email.CheckEmailRepository
import team.gdsc.earthgardener.domain.nickname.CheckNicknameRepository
import team.gdsc.earthgardener.domain.signup.SignUpRepository

class SignUpViewModel(private val signUpRepository: SignUpRepository)
class SignUpViewModel(
private val checkEmailRepository: CheckEmailRepository,
private val checkNicknameRepository: CheckNicknameRepository,
private val signUpRepository: SignUpRepository
)
:ViewModel(){

//private var _data: HashMap<String, RequestBody> =
//var data: HashMap<String, RequestBody> = _data
// email

private var _email : String = ""
var email: String = _email
set(value){
_email = value
field = value
}

// nickname

private var _status = MutableLiveData<String>()
var currentStatus : LiveData<String> = _status

private var _nickname: String = ""
var nickname: String = _nickname
set(value){
_nickname = value
field = value
}


// signup

private val _isSignUp = MutableLiveData<Boolean>()
val isSignUp : LiveData<Boolean> = _isSignUp

private lateinit var _map : HashMap<String, RequestBody>
var map : HashMap<String, RequestBody> = _map
set(value){
_map = value
field = value
}



private lateinit var _image : MultipartBody.Part
var image : MultipartBody.Part = _image
set(value){
_image = value
field = value
}



fun getEmail() = viewModelScope.launch{
runCatching{checkEmailRepository.getCheckEmailResult(_email)}
.onSuccess {
Log.d("getemail", "success")
//_currentEmail.value = it.code
}
.onFailure {
it.printStackTrace()
}
}

fun getNickname() = viewModelScope.launch{
kotlin.runCatching { checkNicknameRepository.getCheckNicknameResult(_nickname) }
.onSuccess {
Log.d("stauts", it.status.toString())
_status.value = it.status.toString()
}
.onFailure {
it.printStackTrace()
}
}

fun postSignUp() = viewModelScope.launch {
runCatching{ signUpRepository.postSignUpRepositoryResult(_map, _image)}
.onSuccess {
Log.d("signup" , "success")
_isSignUp.postValue(true)
}
.onFailure {
_isSignUp.postValue(false)
it.printStackTrace()
}
}



}

0 comments on commit 2a91b82

Please sign in to comment.