Skip to content

Commit

Permalink
Merge pull request #85 from ttoklip/feat/#15_첫화면로그인_구현
Browse files Browse the repository at this point in the history
[feat] 로그인 api 연결
  • Loading branch information
hangunhee39 authored Jul 18, 2024
2 parents 15394f0 + 6f952fc commit f75ca93
Show file tree
Hide file tree
Showing 25 changed files with 564 additions and 225 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/umc/ttoklip/data/api/LoginApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.umc.ttoklip.data.api

import com.umc.ttoklip.data.model.login.LoginResponse
import com.umc.ttoklip.data.model.ResponseBody
import com.umc.ttoklip.data.model.login.LoginLocalRequest
import com.umc.ttoklip.data.model.login.LoginRequest
import retrofit2.Response
import retrofit2.http.Body
Expand All @@ -12,4 +13,8 @@ interface LoginApi {
@POST("/api/v1/oauth")
suspend fun postLogin(@Body request: LoginRequest)
: Response<ResponseBody<LoginResponse>>

@POST("/api/v1/auth/login")
suspend fun postLocalLogin(@Body request: LoginLocalRequest)
: Response<ResponseBody<LoginResponse>>
}
38 changes: 30 additions & 8 deletions app/src/main/java/com/umc/ttoklip/data/api/SignupApi.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.umc.ttoklip.data.api

import com.umc.ttoklip.data.model.ResponseBody
import com.umc.ttoklip.data.model.StandardResponse
import com.umc.ttoklip.data.model.signup.SignupResponse
import com.umc.ttoklip.data.model.signup.SignupRequest
import com.umc.ttoklip.data.model.signup.TermResponse
import com.umc.ttoklip.data.model.signup.VerifyRequest
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response
Expand All @@ -17,26 +19,46 @@ import retrofit2.http.PartMap
import retrofit2.http.Query

interface SignupApi {
@GET("/api/v1/privacy/check-nickname")

@POST("/api/v1/email/send")
suspend fun verifySend(
@Body request: VerifyRequest
):Response<ResponseBody<StandardResponse>>
@POST("/api/v1/email/verify")
suspend fun verifyCheck(
@Body request: VerifyRequest
):Response<ResponseBody<StandardResponse>>

@POST("/api/v1/auth/duplicate")
suspend fun idCheck(@Query("newId") id:String)
:Response<ResponseBody<StandardResponse>>

@GET("/api/v1/privacy/oauth/check-nickname")
suspend fun nickCheck(@Query("nickname") nickname:String)
: Response<ResponseBody<SignupResponse>>
@GET("/api/v1/privacy/local/check-nickname")
suspend fun nickCheckLocal(@Query("nickname") nickname: String)
: Response<ResponseBody<SignupResponse>>

//소셜 회원가입 정보 저장
@Multipart
@POST("/api/v1/privacy/insert")
suspend fun savePrivacy(
@Part profileImage: MultipartBody.Part?,
@Part categories:List<MultipartBody.Part>,
@PartMap params:MutableMap<String,RequestBody>
)
:Response<ResponseBody<SignupResponse>>
):Response<ResponseBody<SignupResponse>>
//로컬 로그인 정보 저장
@Multipart
@POST("/api/v1/auth/signup")
suspend fun savePrivacyLocal(
@Part profileImage: MultipartBody.Part?,
@Part categories:List<MultipartBody.Part>,
@PartMap params:MutableMap<String,RequestBody>
):Response<ResponseBody<SignupResponse>>

@GET("/api/v1/term")
suspend fun getTerm(
@Query("page")page:Int
):Response<ResponseBody<TermResponse>>

// @POST("/api/v1/privacy/insert")
// suspend fun savePrivacy(
// @Body userInfo:SignupRequest
// ):Response<ResponseBody<SignupResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.umc.ttoklip.data.model.login

data class LoginLocalRequest(
val email:String,
val password:String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.umc.ttoklip.data.model.signup

data class SignupLocalRequest(
val email:String,
val password:String,
val originName:String,
val nickname:String,
val independentYear:Int,
val independentMonth:Int,
val street:String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class SignupRequest(
val profileImage:String,
val independentYear:Int,
val independentMonth:Int
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.umc.ttoklip.data.model.signup

data class VerifyRequest(
val email:String,
val verifyCode:String
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.umc.ttoklip.data.repository.login

import com.umc.ttoklip.data.model.login.LoginLocalRequest
import com.umc.ttoklip.data.model.login.LoginRequest
import com.umc.ttoklip.data.model.login.LoginResponse
import com.umc.ttoklip.module.NetworkResult

interface LoginRepository {
suspend fun postLogin(request: LoginRequest): NetworkResult<LoginResponse>
suspend fun postLoginLocal(request:LoginLocalRequest): NetworkResult<LoginResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.umc.ttoklip.data.repository.login

import com.umc.ttoklip.data.api.LoginApi
import com.umc.ttoklip.data.model.ResponseBody
import com.umc.ttoklip.data.model.login.LoginLocalRequest
import com.umc.ttoklip.data.model.login.LoginRequest
import com.umc.ttoklip.data.model.login.LoginResponse
import com.umc.ttoklip.module.NetworkResult
Expand All @@ -15,4 +16,7 @@ class LoginRepositoryImpl @Inject constructor(
override suspend fun postLogin(request: LoginRequest): NetworkResult<LoginResponse> {
return handleApi({api.postLogin(request)}){response:ResponseBody<LoginResponse>->response.result}
}
override suspend fun postLoginLocal(request: LoginLocalRequest): NetworkResult<LoginResponse> {
return handleApi({api.postLocalLogin(request)}){response:ResponseBody<LoginResponse>->response.result}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package com.umc.ttoklip.data.repository.signup

import com.umc.ttoklip.data.model.StandardResponse
import com.umc.ttoklip.data.model.signup.SignupRequest
import com.umc.ttoklip.data.model.signup.SignupResponse
import com.umc.ttoklip.data.model.signup.VerifyRequest
import com.umc.ttoklip.module.NetworkResult
import okhttp3.MultipartBody
import okhttp3.RequestBody

interface SignupRepository {
suspend fun verifySend(request:VerifyRequest):NetworkResult<StandardResponse>
suspend fun verifyCheck(request: VerifyRequest):NetworkResult<StandardResponse>
suspend fun checkId(id:String):NetworkResult<StandardResponse>
suspend fun checkNickname(nick:String): NetworkResult<SignupResponse>
suspend fun checkNicknameLocal(nick:String): NetworkResult<SignupResponse>
suspend fun savePrivacy(photo: MultipartBody.Part,
info:MutableMap<String, RequestBody>
,cate:List<MultipartBody.Part>)
: NetworkResult<SignupResponse>
suspend fun savePrivacyLocal(photo: MultipartBody.Part,
info: MutableMap<String, RequestBody>,
cate: List<MultipartBody.Part>)
: NetworkResult<SignupResponse>
// suspend fun savePrivacy(userInfo:SignupRequest)
// : NetworkResult<SignupResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.umc.ttoklip.data.repository.signup

import com.umc.ttoklip.data.api.SignupApi
import com.umc.ttoklip.data.model.ResponseBody
import com.umc.ttoklip.data.model.StandardResponse
import com.umc.ttoklip.data.model.signup.SignupRequest
import com.umc.ttoklip.data.model.signup.SignupResponse
import com.umc.ttoklip.data.model.signup.VerifyRequest
import com.umc.ttoklip.module.NetworkResult
import com.umc.ttoklip.module.handleApi
import okhttp3.MultipartBody
Expand All @@ -14,15 +16,27 @@ import javax.inject.Inject
class SignupRepositoryImpl @Inject constructor(
private val api: SignupApi
): SignupRepository {
override suspend fun verifySend(request: VerifyRequest): NetworkResult<StandardResponse> {
return handleApi({api.verifySend(request)}){response:ResponseBody<StandardResponse>->response.result}
}
override suspend fun verifyCheck(request: VerifyRequest): NetworkResult<StandardResponse> {
return handleApi({api.verifyCheck(request)}){response:ResponseBody<StandardResponse>->response.result}
}
override suspend fun checkId(id: String): NetworkResult<StandardResponse> {
return handleApi({api.idCheck(id)}){response:ResponseBody<StandardResponse>->response.result}
}

override suspend fun checkNickname(nick: String): NetworkResult<SignupResponse> {
return handleApi({api.nickCheck(nick)}) {response: ResponseBody<SignupResponse> ->response.result}
}
override suspend fun checkNicknameLocal(nick: String): NetworkResult<SignupResponse> {
return handleApi({api.nickCheckLocal(nick)}) {response: ResponseBody<SignupResponse> ->response.result}
}

override suspend fun savePrivacy(photo:MultipartBody.Part,info:MutableMap<String, RequestBody>,cate:List<MultipartBody.Part>): NetworkResult<SignupResponse> {
return handleApi({api.savePrivacy(photo,cate,info)}) {response: ResponseBody<SignupResponse> ->response.result}
}

// override suspend fun savePrivacy(userInfo:SignupRequest): NetworkResult<SignupResponse> {
// return handleApi({api.savePrivacy(userInfo)}) {response: ResponseBody<SignupResponse> ->response.result}
// }
override suspend fun savePrivacyLocal(photo:MultipartBody.Part,info:MutableMap<String, RequestBody>,cate:List<MultipartBody.Part>): NetworkResult<SignupResponse> {
return handleApi({api.savePrivacyLocal(photo,cate,info)}) {response: ResponseBody<SignupResponse> ->response.result}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@ package com.umc.ttoklip.presentation.login
import android.content.Intent
import android.util.Log
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.common.util.Utility
import com.kakao.sdk.user.UserApiClient
import com.navercorp.nid.NaverIdLoginSDK
import com.navercorp.nid.oauth.OAuthLoginCallback
import com.umc.ttoklip.R
import com.umc.ttoklip.TtoklipApplication
import com.umc.ttoklip.data.model.login.LoginLocalRequest
import com.umc.ttoklip.data.model.login.LoginRequest
import com.umc.ttoklip.databinding.ActivityLogin2Binding
import com.umc.ttoklip.databinding.ActivityLoginBinding
import com.umc.ttoklip.presentation.MainActivity
import com.umc.ttoklip.presentation.base.BaseActivity
import com.umc.ttoklip.presentation.search.dialog.BottomDialogSearchFragment
import com.umc.ttoklip.presentation.signup.SignupActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlin.math.log

@AndroidEntryPoint
class LoginActivity : BaseActivity<ActivityLogin2Binding>(R.layout.activity_login2) {
Expand All @@ -34,12 +30,18 @@ class LoginActivity : BaseActivity<ActivityLogin2Binding>(R.layout.activity_logi

override fun initView() {
loginActivity=this

binding.loginLoginBtn.setOnClickListener {
viewModel.postLocalLogin(LoginLocalRequest(binding.loginEmailEt.text.toString(),binding.loginPwEt.text.toString()),
this)
}

binding.loginNaverBtn.setOnClickListener {
naverLogin()
}
binding.loginKakaoBtn.setOnClickListener {
kakaoLogin()
}
// binding.loginKakaoBtn.setOnClickListener {
// kakaoLogin()
// }
binding.loginLocalSignup.setOnClickListener {
val intent = Intent(this, SignupActivity::class.java)
intent.putExtra("loginWay","local")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.umc.ttoklip.presentation.login

import android.content.Context
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import android.widget.Toast
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.umc.ttoklip.TtoklipApplication
import com.umc.ttoklip.data.model.login.LoginLocalRequest
import com.umc.ttoklip.data.model.login.LoginRequest
import com.umc.ttoklip.data.repository.login.LoginRepositoryImpl
import com.umc.ttoklip.module.onFail
import com.umc.ttoklip.module.onSuccess
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
Expand All @@ -21,6 +22,9 @@ class LoginViewModel @Inject constructor(
private val loginRepository: LoginRepositoryImpl
) : ViewModel() {

val id=MutableStateFlow<String>("")
val pw=MutableStateFlow<String>("")

private val _isSocialLogin=MutableStateFlow<Boolean>(false)
val isSocialLogin:StateFlow<Boolean>
get() = _isSocialLogin
Expand All @@ -35,6 +39,21 @@ class LoginViewModel @Inject constructor(
_isSocialLogin.value=isSL
}

fun postLocalLogin(request: LoginLocalRequest, context: Context){
viewModelScope.launch {
loginRepository.postLoginLocal(request)
.onSuccess {
TtoklipApplication.prefs.setString("jwt",it.jwtToken)
TtoklipApplication.prefs.setBoolean("isFirstLogin",it.ifFirstLogin)
_isFirstLogin.emit(it.ifFirstLogin)
_isLogin.emit(true)
}.onFail {
Toast.makeText(context,"로그인 실패", Toast.LENGTH_LONG).show()
Log.d("LOGIN-API", "local login 실패")
}
}
}

fun postLogin(request: LoginRequest) {
viewModelScope.launch {
loginRepository.postLogin(request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.umc.ttoklip.presentation.signup

import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import com.umc.ttoklip.R
import com.umc.ttoklip.databinding.ActivitySignupBinding
import com.umc.ttoklip.presentation.base.BaseActivity
import com.umc.ttoklip.presentation.login.LoginActivity
import com.umc.ttoklip.presentation.signup.fragments.TermViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SignupActivity:BaseActivity<ActivitySignupBinding>(R.layout.activity_signup) {

private lateinit var navHostFragment:NavHostFragment
private lateinit var vm:SignupViewModel
private lateinit var termVM:TermViewModel

override fun initView() {
signupActivity=this

vm=ViewModelProvider(this).get(SignupViewModel::class.java)
termVM=ViewModelProvider(this).get(TermViewModel::class.java)
termVM.getTerm(resources)

navHostFragment = supportFragmentManager.findFragmentById(R.id.signup_frm)as NavHostFragment
var navController=navHostFragment.findNavController()
val graphInflater=navController.navInflater
Expand Down Expand Up @@ -72,8 +79,10 @@ class SignupActivity:BaseActivity<ActivitySignupBinding>(R.layout.activity_signu

private fun determineStartDestination(loginWay:String): Int {
return if(loginWay=="local"){
vm.signupType.value="local"
R.id.signup1_fragment
}else{
vm.signupType.value="sns"
R.id.signup3_fragment
}
}
Expand Down
Loading

0 comments on commit f75ca93

Please sign in to comment.