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

test #8

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".WithPeaceApplication"
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/com/withpeace/withpeace/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.withpeace.withpeace.ui.theme.WithpeaceTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.withpeace.withpeace

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

@HiltAndroidApp
class WithPeaceApplication: Application() {
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ plugins {
alias(libs.plugins.ktlint)
alias(libs.plugins.android.library) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.kotlin.serialization) apply false
}
1 change: 1 addition & 0 deletions core/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
16 changes: 16 additions & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id("com.android.library")
id("convention.android.base")
id("convention.android.hilt")
id("convention.coroutine")
}

android {
namespace = "com.withpeace.withpeace.core.data"
}

dependencies {
implementation(project(":core:network"))
implementation(project(":core:domain"))
implementation(libs.skydoves.sandwich)
}
Empty file added core/data/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/data/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.withpeace.withpeace.core.data

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.withpeace.withpeace.core.data.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions core/data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.withpeace.withpeace.core.data.mapper

import com.withpeace.withpeace.core.domain.model.Token
import com.withpeace.withpeace.core.network.di.response.TokenResponse

fun TokenResponse.toDomain(): Token {
return Token(
accessToken = accessToken,
refreshToken = refreshToken
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.withpeace.withpeace.core.data.repository

import com.skydoves.sandwich.message
import com.skydoves.sandwich.suspendMapSuccess
import com.skydoves.sandwich.suspendOnError
import com.withpeace.withpeace.core.data.mapper.toDomain
import com.withpeace.withpeace.core.domain.model.Token
import com.withpeace.withpeace.core.domain.repository.TokenRepository
import com.withpeace.withpeace.core.network.di.service.AuthService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject


class DefaultTokenRepository @Inject constructor(
private val authService: AuthService
) : TokenRepository {

override fun googleLogin(onError: (String?) -> Unit): Flow<Token> = flow {
authService.googleLogin()
.suspendMapSuccess {
emit(data.toDomain())
}.suspendOnError {
onError(message())
}
}.flowOn(Dispatchers.IO)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.withpeace.withpeace.core.data

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
1 change: 1 addition & 0 deletions core/domain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
7 changes: 7 additions & 0 deletions core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("convention.kotlin.library")
}

dependencies {
implementation(libs.inject)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.withpeace.withpeace.core.domain.model

data class Token(
val accessToken: String,
val refreshToken: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.withpeace.withpeace.core.domain.repository

import com.withpeace.withpeace.core.domain.model.Token
import kotlinx.coroutines.flow.Flow

interface TokenRepository {

fun googleLogin(onError: (message: String?) -> Unit): Flow<Token>
}
1 change: 1 addition & 0 deletions core/network/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
19 changes: 19 additions & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id("com.android.library")
id("convention.android.base")
id("convention.android.hilt")
id("convention.coroutine")
id("kotlinx-serialization")
}

android {
namespace = "com.withpeace.withpeace.core.network"
}

dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.retrofit.kotlin.serialization)
implementation(libs.retrofit.core)
implementation(libs.okhttp.logging)
implementation(libs.skydoves.sandwich)
}
Empty file added core/network/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/network/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.withpeace.withpeace.core.network

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.withpeace.withpeace.core.network.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions core/network/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.withpeace.withpeace.core.network.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.skydoves.sandwich.adapters.ApiResponseCallAdapterFactory
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 retrofit2.Converter
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun provideConverterFactory(): Converter.Factory {
val json = Json {
ignoreUnknownKeys = true
coerceInputValues = true
encodeDefaults = true
isLenient = true
}

val jsonMediaType = "application/json".toMediaType()
return json.asConverterFactory(jsonMediaType)
}

@Provides
@Singleton
fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor {
return HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
}

// @Provides
// @Singleton
// fun provideHeaderInterceptor(chain: Interceptor.Chain) {
// val requestBuilder = chain.request().newBuilder()
// var apiKey = BuildConfig.X_RIOT_TOKEN
// requestBuilder.addHeader("X-Riot-Token", apiKey)
// chain.proceed(requestBuilder.build())
// }

@Singleton
@Provides
fun provideOkhttpClient(httpLoggingInterceptor: HttpLoggingInterceptor): OkHttpClient {
return OkHttpClient.Builder().apply {
// addInterceptor(AccessTokenInterceptor) TODO("토큰 인터셉터 할당")
addInterceptor(httpLoggingInterceptor)
}.build()
}


@Provides
@Singleton
fun provideRetrofitClient(
okHttpClient: OkHttpClient,
converterFactory: Converter.Factory
): Retrofit {
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl("https://asia.api.riotgames.com/") // TODO("BaseUrl 수정")
.addConverterFactory(converterFactory)
.addCallAdapterFactory(ApiResponseCallAdapterFactory.create())
.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.withpeace.withpeace.core.network.di.request

data class SignUpRequest(
val email: String,
val nickname: String,
val deviceToken: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.withpeace.withpeace.core.network.di.response

import kotlinx.serialization.Serializable

@Serializable
data class BaseResponse<T>(
val data: T,
val error: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.withpeace.withpeace.core.network.di.response

data class TokenResponse(
val accessToken: String,
val refreshToken: String,
)
Loading
Loading