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

[BASE] #22 Hilt 모듈 구현 #24

Merged
merged 34 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bed285a
[chore] hilt 의존성 추가
jiwon2724 Jul 21, 2024
0c89695
[feature] PokitApplication 구현 및 등록
jiwon2724 Jul 21, 2024
1a3478a
[feature] NetworkModule 모듈 구현
jiwon2724 Jul 21, 2024
382ab51
[chore] 타임아웃 설정
jiwon2724 Jul 21, 2024
ac5257f
[chore] auth request, response 데이터 추가
jiwon2724 Jul 21, 2024
3bcbe7f
[chore] auth api 추가
jiwon2724 Jul 22, 2024
a0497b0
[chore] auth api 수정
jiwon2724 Jul 22, 2024
8b6f46b
[chore] 버전 카탈로그 라이브러리 추가
jiwon2724 Jul 26, 2024
138387d
[feature] hilt + 네트워크 모듈 구현
jiwon2724 Jul 26, 2024
7b42aa3
[chore] @AndroidEntryPoint 애노테이션 추가
jiwon2724 Jul 26, 2024
9d17701
[chore] kotest 의존성 추가
jiwon2724 Jul 26, 2024
ea0bec5
[feature] sns로그인 api연동
jiwon2724 Jul 26, 2024
a50542f
[feature] 테스트 토큰 인터셉터 구현
jiwon2724 Jul 26, 2024
9fb589a
[feature] 닉네임 입력 화면 설계
jiwon2724 Jul 26, 2024
5e22432
[chore] 뷰모델 주입
jiwon2724 Jul 26, 2024
19a5db3
[chore] 미사용 리소스 제거
jiwon2724 Jul 26, 2024
1200e22
[chore] 코딩 컨벤션 적용
jiwon2724 Jul 26, 2024
b3a75f5
[chore] 코딩 컨벤션 적용
jiwon2724 Jul 26, 2024
a5df3fc
[chore] orbit 제거
jiwon2724 Jul 28, 2024
ac83ccb
[chore] LoginScreen 로직 수정
jiwon2724 Jul 28, 2024
8280746
[feature] 애플 로그인 구현
jiwon2724 Jul 28, 2024
c9ed23f
[feature] 네트워크 통신 모듈 구현
jiwon2724 Jul 29, 2024
cc02cbd
[chore] 클래스명 수정
jiwon2724 Jul 29, 2024
d8268a5
[chore] 주석 제거
jiwon2724 Jul 29, 2024
85d2dc1
[feature] parseErrorResult 함수 구현
jiwon2724 Jul 29, 2024
d6b5f7d
[chore] 닉네임 중복 처리 api 세팅
jiwon2724 Jul 29, 2024
fdc5cfd
[chore] parseErrorResult 분리 및 적용
jiwon2724 Jul 29, 2024
08e9e01
[chore] 중복 닉네임 api 세팅
jiwon2724 Jul 29, 2024
7314212
[chore] 코딩 컨벤션 반영
jiwon2724 Jul 29, 2024
a61417a
[chore] ktlint rule 추가
jiwon2724 Jul 29, 2024
264bf21
Merge branch 'develop' into base/#22-hilt-module
jiwon2724 Jul 30, 2024
b77b18a
[chore] ktlint_standard_function-name 제거
jiwon2724 Jul 30, 2024
54e8946
[chore] 파일 이름 수정
jiwon2724 Jul 30, 2024
a15a33b
Merge remote-tracking branch 'origin/base/#22-hilt-module' into base/…
jiwon2724 Jul 30, 2024
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
7 changes: 7 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
alias(libs.plugins.com.android.application)
alias(libs.plugins.org.jetbrains.kotlin.android)
alias(libs.plugins.hilt)
id("kotlin-kapt")
}

android {
Expand Down Expand Up @@ -67,5 +69,10 @@ dependencies {
debugImplementation(libs.androidx.ui.test.manifest)

implementation(project(":core:ui"))
implementation(project(":data"))
implementation(project(":domain"))
implementation(project(":feature:login"))

implementation(libs.hilt)
kapt(libs.hilt.compiler)
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".PokitApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/pokitmons/pokit/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package pokitmons.pokit
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import dagger.hilt.android.AndroidEntryPoint
import pokitmons.pokit.core.ui.theme.PokitTheme
import pokitmons.pokit.navigation.LoginNavHost

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/pokitmons/pokit/PokitApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pokitmons.pokit

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class PokitApplication : Application()
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.org.jetbrains.kotlin.android) apply false
alias(libs.plugins.ktlint.gradle) apply false
alias(libs.plugins.org.jetbrains.kotlin.jvm) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.com.android.library) apply false
}

Expand Down
27 changes: 27 additions & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.hilt)
id("kotlin-kapt")
}

android {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

namespace = "pokitmons.pokit.data"
compileSdk = 34

Expand Down Expand Up @@ -38,6 +45,26 @@ dependencies {
implementation(libs.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
testImplementation(project(":feature:login"))
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

// kotest
testImplementation(libs.kotest.runner.junit5)
testImplementation(libs.kotlin.reflect)

// hilt
implementation(libs.hilt)
kapt(libs.hilt.compiler)

// serialization
implementation(libs.kotlinx.serialization.json)

// retrofit
implementation(libs.retrofit)
implementation(libs.retrofit.converter.serialization)
implementation(libs.okhttp)
implementation(libs.logging.interceptor)

implementation(project(":domain"))
}
13 changes: 13 additions & 0 deletions data/src/main/java/pokitmons/pokit/data/api/AuthApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pokitmons.pokit.data.api

import pokitmons.pokit.data.model.auth.request.SNSLoginRequest
import pokitmons.pokit.data.model.auth.response.SNSLoginResponse
import retrofit2.http.Body
import retrofit2.http.POST

interface AuthApi {
@POST("auth/signin")
suspend fun snsLogin(
@Body snsLoginRequest: SNSLoginRequest,
): SNSLoginResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pokitmons.pokit.data.datasource.remote.auth

import pokitmons.pokit.data.model.auth.request.SNSLoginRequest
import pokitmons.pokit.data.model.auth.response.SNSLoginResponse

interface AuthDataSource {
// suspend fun signUp(signUpRequest: SignUpRequest): PokitResponse<SignUpResponse>
suspend fun snsLogin(snsLoginRequest: SNSLoginRequest): SNSLoginResponse
// suspend fun checkDuplicateNickname(nickname: String): PokitResponse<DuplicateNicknameResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pokitmons.pokit.data.datasource.remote.auth

import pokitmons.pokit.data.api.AuthApi
import pokitmons.pokit.data.model.auth.request.SNSLoginRequest
import pokitmons.pokit.data.model.auth.response.SNSLoginResponse
import javax.inject.Inject

class RemoteAuthDataSourceImpl @Inject constructor(private val authApi: AuthApi) : AuthDataSource {
override suspend fun snsLogin(snsLoginRequest: SNSLoginRequest): SNSLoginResponse {
return authApi.snsLogin(snsLoginRequest)
}
}
23 changes: 23 additions & 0 deletions data/src/main/java/pokitmons/pokit/data/di/auth/AuthModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pokitmons.pokit.data.di.auth

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import pokitmons.pokit.data.datasource.remote.auth.AuthDataSource
import pokitmons.pokit.data.datasource.remote.auth.RemoteAuthDataSourceImpl
import pokitmons.pokit.data.repository.auth.AuthRepositoryImpl
import pokitmons.pokit.domain.repository.auth.AuthRepository
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class AuthModule {
@Binds
@Singleton
abstract fun bindAuthRepository(authRepositoryImpl: AuthRepositoryImpl): AuthRepository

@Binds
@Singleton
abstract fun bindAuthDataSource(authDataSourceImpl: RemoteAuthDataSourceImpl): AuthDataSource
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pokitmons.pokit.data.di.network

import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import java.io.IOException

// 토큰 api 수정될 때 까지 사용
class BearerTokenInterceptor : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest: Request = chain.request()
val requestWithToken: Request = originalRequest.newBuilder()
.header(
"Authorization",
"Bearer eyJhbGciOiJIUzM4NCJ9.eyJzdWIiOiIxIiwiaWF0IjoxNzIxNjU4MjUxLCJleHAiOj" +
"MwMDE3MjE2NTgyNTF9.gw6LZimKLuZJ2y0UV5cgvk3F7o92pkRIDgx-qlD_S7qEI01QAFt9dZDyHADabftI"
)
.build()

return chain.proceed(requestWithToken)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package pokitmons.pokit.data.di.network

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import pokitmons.pokit.data.api.AuthApi
import retrofit2.Retrofit
import java.util.concurrent.TimeUnit
import javax.inject.Singleton

private const val BASE_URL = "https://pokit.site"
private const val API = "api"
private const val VERSION = "v1"

private const val READ_TIME_OUT = 20000L
private const val WRITE_TIME_OUT = 20000L

@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Singleton
@Provides
fun provideOkHttpClient(): OkHttpClient {
return OkHttpClient.Builder()
.addInterceptor(BearerTokenInterceptor())
.addInterceptor(
HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
)
.readTimeout(READ_TIME_OUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIME_OUT, TimeUnit.SECONDS)
.build()
}

@Singleton
@Provides
fun provideJson(): Json {
return Json {
ignoreUnknownKeys = true
coerceInputValues = true
prettyPrint = true
}
}

@Singleton
@Provides
fun provideRetrofit(
okHttpClient: OkHttpClient,
json: Json,
): Retrofit {
val converterFactory = json.asConverterFactory("application/json; charset=UTF8".toMediaType())
return Retrofit.Builder()
.baseUrl("$BASE_URL/$API/$VERSION/")
.addConverterFactory(converterFactory)
.client(okHttpClient)
.build()
}

@Provides
fun provideAuthService(retrofit: Retrofit): AuthApi {
return retrofit.create(AuthApi::class.java)
}
}
13 changes: 13 additions & 0 deletions data/src/main/java/pokitmons/pokit/data/mapper/auth/AuthMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pokitmons.pokit.data.mapper.auth

import pokitmons.pokit.data.model.auth.response.SNSLoginResponse
import pokitmons.pokit.domain.model.auth.SNSLogin

object AuthMapper {
fun mapperToSNSLogin(snsLoginResponse: SNSLoginResponse): SNSLogin {
return SNSLogin(
accessToken = snsLoginResponse.accessToken,
refreshToken = snsLoginResponse.refreshToken
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pokitmons.pokit.data.model.auth.request

import kotlinx.serialization.Serializable

@Serializable
data class SNSLoginRequest(
val authPlatform: String,
val idToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package pokitmons.pokit.data.model.auth.request

data class SignUpRequest(
val nickname: String,
val interests: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pokitmons.pokit.data.model.auth.response

import kotlinx.serialization.Serializable

@Serializable
data class DuplicateNicknameResponse(
val isDuplicate: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pokitmons.pokit.data.model.auth.response

import kotlinx.serialization.Serializable

@Serializable
data class SNSLoginResponse(
val accessToken: String,
val refreshToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pokitmons.pokit.data.model.auth.response

data class SignUpResponse(
val userId: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pokitmons.pokit.data.model.common

import kotlinx.serialization.Serializable

@Serializable
data class PokitResponse<T>(
val data: T,
val message: String,
val code: String,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

sealed class Response<out T> {
    data class Success<T>(val data : T) : Response<T>()
    data class Failure(val code: Int) : Response<Nothing>()
}

회의때 잠깐 구현했던 코드 혹시 몰라서 첨부합니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

짱짱~~!

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pokitmons.pokit.data.repository.auth

import pokitmons.pokit.data.datasource.remote.auth.AuthDataSource
import pokitmons.pokit.data.mapper.auth.AuthMapper
import pokitmons.pokit.data.model.auth.request.SNSLoginRequest
import pokitmons.pokit.domain.model.auth.SNSLogin
import pokitmons.pokit.domain.repository.auth.AuthRepository
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val remoteAuthDataSource: AuthDataSource,
) : AuthRepository {
override suspend fun snsLogin(
authPlatform: String,
idToken: String,
): Result<SNSLogin> = runCatching {
val snsLoginRequest = SNSLoginRequest(authPlatform = authPlatform, idToken = idToken)
val snsLoginResponse = remoteAuthDataSource.snsLogin(snsLoginRequest)
AuthMapper.mapperToSNSLogin(snsLoginResponse)
}.onFailure { throwable ->
try {
} catch (e: Exception) {
}
}
}
16 changes: 0 additions & 16 deletions data/src/test/java/pokitmons/pokit/data/ExampleUnitTest.kt

This file was deleted.

4 changes: 4 additions & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
implementation(libs.javax.inject)
}
3 changes: 0 additions & 3 deletions domain/src/main/java/pokitmons/pokit/domain/MyClass.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package pokitmons.pokit.domain.model.auth

data class SNSLogin(
val accessToken: String,
val refreshToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pokitmons.pokit.domain.repository.auth

import pokitmons.pokit.domain.model.auth.SNSLogin

interface AuthRepository {
suspend fun snsLogin(
authPlatform: String,
idToken: String,
): Result<SNSLogin>
}
Loading
Loading