Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI/#28] 유형검사 결과 페이지 #34

Merged
merged 23 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
</intent-filter>
</activity>

<activity
android:name="com.going.presentation.auth.LoginActivity"
android:exported="false"
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.todo.TodoActivity"
android:exported="false"
Expand All @@ -66,6 +71,11 @@
android:exported="false"
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.tendencytest.result.TendencyTestResultActivity"
android:exported="true"
android:screenOrientation="portrait"/>

</application>

</manifest>
10 changes: 9 additions & 1 deletion app/src/main/java/com/going/going/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.going.going.di

import com.going.data.datasource.LoginDataSource
import com.going.data.datasource.MockDataSource
import com.going.data.datasourceImpl.LoginDataSourceImpl
import com.going.data.datasourceImpl.MockDataSourceImpl
import dagger.Module
import dagger.Provides
Expand All @@ -17,4 +19,10 @@ object DataSourceModule {
fun provideMockDataSource(mockDataSourceImpl: MockDataSourceImpl): MockDataSource =
mockDataSourceImpl

}
@Provides
@Singleton
fun provideLoginDataSource(loginDataSourceImpl: LoginDataSourceImpl): LoginDataSource =
loginDataSourceImpl


}
8 changes: 7 additions & 1 deletion app/src/main/java/com/going/going/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.going.going.di

import com.going.data.repositoryImpl.LoginRepositoryImpl
import com.going.data.repositoryImpl.MockRepositoryImpl
import com.going.domain.repository.LoginRepository
import com.going.domain.repository.MockRepository
import dagger.Module
import dagger.Provides
Expand All @@ -17,4 +19,8 @@ object RepositoryModule {
fun provideMockRepository(mockRepositoryImpl: MockRepositoryImpl): MockRepository =
mockRepositoryImpl

}
@Provides
@Singleton
fun provideLoginRepository(loginRepositoryImpl: LoginRepositoryImpl): LoginRepository =
loginRepositoryImpl
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코틀린스러운 코드네요 ~~ LGTM

}
8 changes: 7 additions & 1 deletion app/src/main/java/com/going/going/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.going.going.di

import com.going.data.service.LoginService
import com.going.data.service.MockService
import dagger.Module
import dagger.Provides
Expand All @@ -17,4 +18,9 @@ object ServiceModule {
fun provideMockService(retrofit: Retrofit): MockService =
retrofit.create(MockService::class.java)

}
@Provides
@Singleton
fun provideLoginService(retrofit: Retrofit): LoginService =
retrofit.create(LoginService::class.java)

}
12 changes: 12 additions & 0 deletions data/src/main/java/com/going/data/datasource/LoginDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.going.data.datasource

import com.going.data.dto.BaseResponse
import com.going.data.dto.request.RequestLoginDto
import com.going.data.dto.response.LoginResponseDto

interface LoginDataSource {
suspend fun postLogin(
Authorization: String,
platform: RequestLoginDto,
): BaseResponse<LoginResponseDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.going.data.datasourceImpl

import com.going.data.datasource.LoginDataSource
import com.going.data.dto.BaseResponse
import com.going.data.dto.request.RequestLoginDto
import com.going.data.dto.response.LoginResponseDto
import com.going.data.service.LoginService
import javax.inject.Inject

class LoginDataSourceImpl @Inject constructor(
private val loginService: LoginService,
) : LoginDataSource {
override suspend fun postLogin(
Authorization: String,
platform: RequestLoginDto,
): BaseResponse<LoginResponseDto> =
loginService.postSignin(Authorization, platform)
}
14 changes: 14 additions & 0 deletions data/src/main/java/com/going/data/dto/BaseResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.going.data.dto

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

@Serializable
data class BaseResponse<T>(
@SerialName("status")
val status: Int,
@SerialName("message")
val message: String,
@SerialName("data")
val data: T,
)
10 changes: 10 additions & 0 deletions data/src/main/java/com/going/data/dto/request/RequestLoginDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.going.data.dto.request

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

@Serializable
data class RequestLoginDto(
@SerialName("platform")
val platform: String
)
37 changes: 37 additions & 0 deletions data/src/main/java/com/going/data/dto/response/LoginResponseDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.going.data.dto.response

import com.going.domain.entity.response.AuthTokenModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class LoginResponseDto(
@SerialName("accessToken")
val accessToken: String,
@SerialName("refreshToken")
val refreshToken: String,
) {
fun toAuthTokenModel() =
AuthTokenModel(accessToken = accessToken, refreshToken = refreshToken)
}

// @Serializable
// data class LoginResponseDto(
// @SerialName("status")
// val status: Int,
// @SerialName("message")
// val message: String,
// @SerialName("data")
// val data: Data,
// ) {
// @Serializable
// data class Data(
// @SerialName("accessToken")
// val accessToken: String,
// @SerialName("refreshToken")
// val refreshToken: String,
// )
//
// fun toAuthTokenModel() =
// AuthTokenModel(accessToken = data.accessToken, refreshToken = data.refreshToken)
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.going.data.repositoryImpl

import com.going.data.datasource.LoginDataSource
import com.going.data.dto.request.RequestLoginDto
import com.going.domain.entity.response.AuthTokenModel
import com.going.domain.repository.LoginRepository
import javax.inject.Inject

class LoginRepositoryImpl @Inject constructor(
private val loginDataSource: LoginDataSource,
) : LoginRepository {
override suspend fun postSignin(
Authorization: String,
platform: String,
): Result<AuthTokenModel> =
runCatching {
loginDataSource.postLogin(
Authorization,
RequestLoginDto(platform),
).data.toAuthTokenModel()
}
}
16 changes: 16 additions & 0 deletions data/src/main/java/com/going/data/service/LoginService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.going.data.service

import com.going.data.dto.BaseResponse
import com.going.data.dto.request.RequestLoginDto
import com.going.data.dto.response.LoginResponseDto
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST

interface LoginService {
@POST("api/users/signin")
suspend fun postSignin(
@Header("Authorization") Authorization: String,
@Body body: RequestLoginDto,
): BaseResponse<LoginResponseDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.going.domain.entity

data class TendencyResultMock(
val tendencyTitle: String,
val tendencySubTitle: String,
val tags: List<String>,
val tendencyBoxInfo: List<BoxInfo>,
) {
data class BoxInfo(
val title: String,
val first: String,
val second: String,
val third: String,
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.going.domain.entity.response

data class AuthTokenModel(
val isResigned: Boolean,
val accessToken: String,
val refreshToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.going.domain.repository

import com.going.domain.entity.response.AuthTokenModel

interface LoginRepository {
suspend fun postSignin(
Authorization: String,
platform: String,
): Result<AuthTokenModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import com.going.presentation.databinding.ActivityLoginBinding
import com.going.ui.base.BaseActivity
import com.going.ui.extension.UiState
import com.going.ui.extension.setOnSingleClickListener
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@AndroidEntryPoint
class LoginActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_login) {
private val viewModel by viewModels<LoginViewModel>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.response.AuthTokenModel
import com.going.domain.repository.LoginRepository
import com.going.ui.extension.UiState
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.user.UserApiClient
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

class LoginViewModel : ViewModel() {
@HiltViewModel
class LoginViewModel @Inject constructor(
private val loginRepository: LoginRepository,
) : ViewModel() {
private val _postChangeTokenState = MutableStateFlow<UiState<AuthTokenModel>>(UiState.Empty)
val postChangeTokenState: StateFlow<UiState<AuthTokenModel?>> = _postChangeTokenState

Expand Down Expand Up @@ -64,19 +71,22 @@ class LoginViewModel : ViewModel() {

viewModelScope.launch {
// 통신 로직

// 성공시 서버에서 준 정보를 넣는 예시 코드
_postChangeTokenState.value = UiState.Success(
AuthTokenModel(
isResigned = true,
accessToken = "testAccessToekn",
refreshToken = "testRefreshToekn",
),
)
loginRepository.postSignin(accessToken, social).onSuccess {
// 성공시 서버에서 준 정보를 넣는 예시 코드
Timber.e("성공고오고오고공")
_postChangeTokenState.value = UiState.Success(
AuthTokenModel(
accessToken = "testAccessToekn",
refreshToken = "testRefreshToekn",
),
)
}.onFailure { err ->
Timber.e("실패패패패패패")
}
}
}

companion object {
const val KAKAO = "KAKAO"
const val KAKAO = "kakao"
}
}
Loading