Skip to content

Commit

Permalink
Merge pull request #42 from SSU-Plector/feat/#37-signup-dev-submit
Browse files Browse the repository at this point in the history
[Feat/#37 signup dev submit] 개발자 등록 페이지 추가
  • Loading branch information
kangyuri1114 authored Jun 9, 2024
2 parents 2539c07 + 09b747e commit 1deb0f6
Show file tree
Hide file tree
Showing 31 changed files with 1,131 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import android.content.Intent
import com.zucchini.auth.LoginActivity
import com.zucchini.common.NavigationProvider
import com.zucchini.projects.MainActivity
import com.zucchini.submit.SubmitDevActivity
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

Expand All @@ -26,4 +28,12 @@ class DefaultNavigationProvider @Inject constructor(
override fun toLogin(): Intent {
return Intent(context, LoginActivity::class.java)
}

override fun toSubmitDev(): Intent {
return Intent(context, SubmitDevActivity::class.java)
}

override fun toMain(): Intent {
return Intent(context, MainActivity::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface NavigationProvider {
fun toMyPage(): Intent

fun toLogin(): Intent
fun toSubmitDev(): Intent
fun toMain(): Intent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="340dp"
android:height="80dp"
android:viewportWidth="340"
android:viewportHeight="56">
<path
android:strokeWidth="1"
android:pathData="M10,0.5L330,0.5A9.5,9.5 0,0 1,339.5 10L339.5,46A9.5,9.5 0,0 1,330 55.5L10,55.5A9.5,9.5 0,0 1,0.5 46L0.5,10A9.5,9.5 0,0 1,10 0.5z"
android:fillColor="#423B39"
android:strokeColor="#423B39"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ interface NetworkPreference {
var accessToken: String
var refreshToken: String
var developerId: Int
var kakaoEmail: String
var kakaoNickname: String
var kakaoProfileImage: String
var autoLoginConfigured: Boolean
fun clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ class NetworkPreferenceImpl @Inject constructor(
}
}

override var kakaoEmail: String
get() = preferences.getString("kakao_email", "").orEmpty()
set(value) {
preferences.edit(commit = true) {
putString("kakao_email", value)
}
}

override var kakaoNickname: String
get() = preferences.getString("kakao_nickname", "").orEmpty()
set(value) {
preferences.edit(commit = true) {
putString("kakao_nickname", value)
}
}
override var kakaoProfileImage: String
get() = preferences.getString("kakao_profile_image", "").orEmpty()
set(value) {
preferences.edit(commit = true) {
putString("kakao_profile_image", value)
}
}

override fun clear() {
preferences.edit(commit = true) {
clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.sample.network.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CreateDevelopersRequest(
@SerialName("shortIntro")
val shortIntro: String,
@SerialName("university")
val university: String,
@SerialName("major")
val major: String,
@SerialName("studentNumber")
val studentNumber: String,
@SerialName("kakaoId")
val kakaoId: String,
@SerialName("githubLink")
val githubLink: String,
@SerialName("part1")
val part1: String,
@SerialName("part2")
val part2: String,
@SerialName("languageList")
val languageList: List<String>,
@SerialName("devToolList")
val devToolList: List<String>,
@SerialName("techStackList")
val techStackList: List<String>,

)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package com.sample.network.service
import com.sample.network.model.BaseResponse
import com.sample.network.reponse.DevelopersDetailResponse
import com.sample.network.reponse.DevelopersListResponse
import com.sample.network.request.CreateDevelopersRequest
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.PATCH
import retrofit2.http.Path
import retrofit2.http.Query

Expand All @@ -20,4 +24,11 @@ interface DevelopersService {
suspend fun getDevelopersDetailData(
@Path("developerId") developerId: Int,
): BaseResponse<DevelopersDetailResponse>

@PATCH("/api/developers")
suspend fun createDeveloperInfo(
@Header("Authorization") accessToken: String,
@Query("email") email: String? = null,
@Body request: CreateDevelopersRequest,
): BaseResponse<Int>
}
22 changes: 21 additions & 1 deletion data/src/main/java/com/zucchini/data/DevelopersRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package com.zucchini.data
import com.sample.network.service.DevelopersService
import com.zucchini.domain.model.DevelopersDetailModel
import com.zucchini.domain.model.DevelopersListModel
import com.zucchini.domain.model.SubmitDevInfo
import com.zucchini.domain.repository.DevelopersRepository
import com.zucchini.mapper.toCreateDevelopersRequest
import com.zucchini.mapper.toDevelopersDetailModel
import com.zucchini.mapper.toDevelopersListModel
import javax.inject.Inject

class DevelopersRepositoryImpl @Inject constructor(
private val developersService: DevelopersService,
) : DevelopersRepository {
override suspend fun getDevelopersListData(page: Int, part: String?): Result<DevelopersListModel> {
override suspend fun getDevelopersListData(
page: Int,
part: String?,
): Result<DevelopersListModel> {
return runCatching {
developersService.getDevelopersListData(
sortType = null,
Expand All @@ -28,4 +33,19 @@ class DevelopersRepositoryImpl @Inject constructor(
developersService.getDevelopersDetailData(developerId).data.toDevelopersDetailModel()
}
}

override suspend fun createDeveloperInfo(
accessToken: String,
email: String?,
submitDevInfo: SubmitDevInfo,
): Result<Int> {
return runCatching {
val bearerToken = "Bearer $accessToken"
developersService.createDeveloperInfo(
bearerToken,
email,
submitDevInfo.toCreateDevelopersRequest(),
).data
}
}
}
20 changes: 20 additions & 0 deletions data/src/main/java/com/zucchini/mapper/SubmitDevInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.zucchini.mapper

import com.sample.network.request.CreateDevelopersRequest
import com.zucchini.domain.model.SubmitDevInfo

internal fun SubmitDevInfo.toCreateDevelopersRequest(): CreateDevelopersRequest {
return CreateDevelopersRequest(
shortIntro = devIntro,
university = devUniversity,
major = devMajor,
studentNumber = devStudentNumber,
kakaoId = kakaoId,
githubLink = devGithub,
part1 = devPart1,
part2 = devPart2,
languageList = devLanguageList,
devToolList = devCooperationList,
techStackList = devTechStackList,
)
}
15 changes: 15 additions & 0 deletions domain/src/main/java/com/zucchini/domain/model/SubmitDevInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.zucchini.domain.model

data class SubmitDevInfo(
val devGithub: String,
val devUniversity: String,
val devMajor: String,
val devIntro: String,
val kakaoId: String,
val devStudentNumber: String,
val devPart1: String,
val devPart2: String,
val devTechStackList: List<String>,
val devLanguageList: List<String>,
val devCooperationList: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.zucchini.domain.repository

import com.zucchini.domain.model.DevelopersDetailModel
import com.zucchini.domain.model.DevelopersListModel
import com.zucchini.domain.model.SubmitDevInfo

interface DevelopersRepository {
suspend fun getDevelopersListData(page: Int, part: String?): Result<DevelopersListModel>
suspend fun getDevelopersDetailData(developerId: Int): Result<DevelopersDetailModel>

suspend fun createDeveloperInfo(accessToken: String, email: String? = null, submitDevInfo: SubmitDevInfo): Result<Int>
}
13 changes: 9 additions & 4 deletions feature/projects/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity
android:name="com.zucchini.submit.SubmitDevActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity
android:name="com.zucchini.auth.LoginActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:exported="false" />
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity
android:name="com.zucchini.projects.projects.ProjectDetailActivity"
android:exported="false"
Expand All @@ -16,8 +21,8 @@
android:name="com.zucchini.projects.MainActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="adjustNothing" />
<activity
android:name="com.zucchini.projects.developer.DevDetailActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.zucchini.feature.projects.R
import com.zucchini.feature.projects.databinding.ActivityLoginBinding
import com.zucchini.projects.MainActivity
import com.zucchini.projects.adapter.IntroducePagerAdapter
import com.zucchini.submit.SubmitDevActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -52,8 +53,7 @@ class LoginActivity @Inject constructor(
success -> if (viewModel.isLogin.value) {
navigateToMain()
} else {
// TODO 회원가입
navigateToMain()
navigateToSubmitDev()
}

else -> Timber.e("Kakao Login Failed")
Expand All @@ -68,6 +68,12 @@ class LoginActivity @Inject constructor(
finish()
}

private fun navigateToSubmitDev() {
intent = Intent(this, SubmitDevActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(intent)
}

private fun setLoginViewPager() {
val loginViewImageList = listOf(
R.drawable.project_introduction_1,
Expand Down
23 changes: 18 additions & 5 deletions feature/projects/src/main/java/com/zucchini/auth/LoginViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zucchini.auth

import android.content.Context
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.kakao.sdk.common.model.ClientError
Expand All @@ -28,6 +27,9 @@ class LoginViewModel @Inject constructor(
private val _isLogin = MutableStateFlow(false)
val isLogin = _isLogin.asStateFlow()

init {
//getKakaoUserInfo()
}

fun loginWithKakaoApp(context: Context) {
if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) {
Expand All @@ -46,10 +48,7 @@ class LoginViewModel @Inject constructor(
developerId = it.developerId
autoLoginConfigured = true
}
Log.d(
"networkPreference",
"accessToken: ${networkPreference.accessToken} refreshToken: ${networkPreference.refreshToken} developerId: ${networkPreference.developerId} autoLoginConfigured: ${networkPreference.autoLoginConfigured}",
)
getKakaoUserInfo()
_isLogin.value = it.isLogin
_kakaoLoginSuccess.value = true
Timber.d("Login Success ${it.accessToken}")
Expand Down Expand Up @@ -77,6 +76,7 @@ class LoginViewModel @Inject constructor(
developerId = it.developerId
autoLoginConfigured = true
}
getKakaoUserInfo()
_isLogin.value = it.isLogin
_kakaoLoginSuccess.value = true
Timber.d("Login Success")
Expand All @@ -91,4 +91,17 @@ class LoginViewModel @Inject constructor(
}
}
}

private fun getKakaoUserInfo() {
UserApiClient.instance.me { user, error ->
if (error != null) {
Timber.e(this.toString())
} else if (user != null) {
networkPreference.kakaoEmail = user.kakaoAccount?.email ?: ""
networkPreference.kakaoProfileImage =
user.kakaoAccount?.profile?.thumbnailImageUrl ?: ""
networkPreference.kakaoNickname = user.kakaoAccount?.profile?.nickname ?: "쥬키니"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ package com.zucchini.projects

import androidx.lifecycle.ViewModel
import com.kakao.sdk.user.UserApiClient
import com.sample.network.datastore.NetworkPreference
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor() : ViewModel() {

private val _userNickname = MutableStateFlow("")
val userNickname = _userNickname.asStateFlow()

private val _userEmail = MutableStateFlow("")
val userEmail = _userEmail.asStateFlow()

private val _userProfile = MutableStateFlow("")
val userProfile = _userProfile.asStateFlow()
class MainViewModel @Inject constructor(
private val networkPreference: NetworkPreference,
) : ViewModel() {

init {
getKakaoUserInfo()
Expand All @@ -26,13 +19,13 @@ class MainViewModel @Inject constructor() : ViewModel() {
private fun getKakaoUserInfo() {
UserApiClient.instance.me { user, error ->
if (error != null) {
_userNickname.value = ""
_userEmail.value = ""
_userProfile.value = ""
Timber.e("failed to get user info: $error")
} else if (user != null) {
_userNickname.value = user.kakaoAccount?.profile?.nickname ?: "no nickname"
_userEmail.value = user.kakaoAccount?.email ?: "no email"
_userProfile.value = user.kakaoAccount?.profile?.thumbnailImageUrl ?: ""
networkPreference.kakaoNickname =
user.kakaoAccount?.profile?.nickname ?: "no nickname"
networkPreference.kakaoEmail = user.kakaoAccount?.email ?: "no email"
networkPreference.kakaoProfileImage =
user.kakaoAccount?.profile?.thumbnailImageUrl ?: ""
}
}
}
Expand Down
Loading

0 comments on commit 1deb0f6

Please sign in to comment.