Skip to content

Commit

Permalink
[Feat] network 기초 세팅, RetrofitModule, ServiceModule 구현 (#25)
Browse files Browse the repository at this point in the history
* [build] kotlin-Serialization id 수정

* [init] network 모듈

* [build] hilt : migrate from kapt to ksp

* [build] kotlin config

* [build] testing 모듈에 JVM 플러그인 적용

* [build] ksp, hilt verson up

* [build] Build-logic refactoring

* [init] dataStore Module

* [feat] UserCodeDataStore

* [feat] DataStoreModule

* [refactor] Preference 만드는 로직 분리

* [build] ktlint 적용

* [build] set ktlint, BASE_URL

* [fix] deprecated된 manifast package 삭제  (nameSpace로 대체됨)

* [build] Test 의존성 추가

* [build] META-INF/LICENSE* 파일 무시

* [add] allow usesCleartextTraffic, INTERNET Permission

* [build] core:network BuildConfig, test, kotlinx-serialization  세팅

* [feat] RetrofitModule

* [feat] ServiceModule, MatchingService

* [feat] MatchingResponse

* [feat] BaseResponse

* [chore] postMatch -> matchProfile네이밍 변경

* [test] matchProfile

* [chore] 불필요한 파일 삭제

* [sample] 서버 통신 Test~ (PR 머지 전에 삭제할 것임)

* [CI] github secret key -> local property에 주입

* [chore] ktlint

* [refactor] 줄 바꿈, ignoreUnKnownKeys 옵션 삭제

* [chore] naming 변경

* [refactor] release 버전도 FUNCH_DEBUG_BASE_URL 추가

* [refactor] Response 분리
  • Loading branch information
murjune authored Jan 31, 2024
1 parent dfbbfd1 commit 62bb831
Show file tree
Hide file tree
Showing 21 changed files with 423 additions and 20 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/PR_Builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:
# echo $GOOGLE_SERVICES >> ./app/google-services.json
# cat ./app/google-services.json
#
# - name: Create Local Properties
# run: touch local.properties
#
# - name: Access Local Properties
# env:
# HOST_URI: ${{ secrets.HOST_URI }}
- name: Create Local Properties
run: touch local.properties

- name: Access Local Properties
env:
FUNCH_DEBUG_BASE_URL: ${{ secrets.FUNCH_DEBUG_BASE_URL }}
# HOST_RELEASE_URI: ${{ secrets.HOST_RELEASE_URI }}
# KAKAO_NATIVE_APP_KEY: ${{ secrets.KAKAO_NATIVE_APP_KEY }}
# KAKAO_REDIRECT_SCHEME: ${{ secrets.KAKAO_REDIRECT_SCHEME }}
Expand All @@ -50,8 +50,8 @@ jobs:
# KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
# KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
# STORE_FILE: ${{ secrets.STORE_FILE }}
# run: |
# echo HOST_URI=\"$HOST_URI\" >> local.properties
run: |
echo FUNCH_DEBUG_BASE_URL=\"FUNCH_DEBUG_BASE_URL\" >> local.properties
# echo HOST_RELEASE_URI=\"$HOST_RELEASE_URI\" >> local.properties
# echo KAKAO_NATIVE_APP_KEY=\"$KAKAO_NATIVE_APP_KEY\" >> local.properties
# echo KAKAO_REDIRECT_SCHEME=\"$KAKAO_REDIRECT_SCHEME\" >> local.properties
Expand Down
6 changes: 5 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ plugins {
android {
namespace = "com.moya.funch"

packaging {
resources.excludes.add("META-INF/LICENSE*")
}

defaultConfig {
applicationId = "com.moya.funch"
versionCode = libs.versions.versionCode.get().toInt()
Expand All @@ -30,7 +34,7 @@ android {
dependencies {
// core
implementation(projects.core.designsystem)

implementation(projects.core.network) // @murjune TODO : 삭제
// feature
implementation(projects.feature.profile)
// implementation(projects.feature.match)
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.moya.funch">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".FunchApplication"
Expand All @@ -15,6 +15,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PunchAOS"
android:usesCleartextTraffic="true"
tools:targetApi="34">
<activity
android:name=".MainActivity"
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/moya/funch/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,41 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.lifecycleScope
import com.moya.funch.network.dto.request.MatchingRequest
import com.moya.funch.network.service.MatchingService
import com.moya.funch.theme.FunchTheme
import com.moya.funch.theme.LocalBackgroundTheme
import com.moya.funch.ui.FunchApp
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@Inject
lateinit var matchingService: MatchingService

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// @murjune TODO : 삭제
lifecycleScope.launch {
runCatching { // 내꺼 코드 : 7O2K, 상대 코드 : 4V1B
matchingService.matchProfile(
MatchingRequest(
userId = "65b6c543ebe5db753688b9dd",
targetCode = "7O2K",
),
)
}.onSuccess {
Timber.e("성공 : $it")
}.onFailure {
Timber.e(it.stackTraceToString())
}
}

setContent {
FunchTheme {
val backgroundColor = LocalBackgroundTheme.current.color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ class AndroidLibraryPlugin : Plugin<Project> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = libs.findVersion("targetSdk").get().requiredVersion.toInt()
}

dependencies {
add("testImplementation", kotlin("test"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package com.moya.funch.plugins

import com.android.build.gradle.BaseExtension
import com.moya.funch.plugins.utils.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.withType

class JUnit5Plugin : Plugin<Project> {
override fun apply(target: Project): Unit =
with(target) {

extensions.getByType<BaseExtension>().apply {
testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

dependencies {
add("testImplementation", kotlin("test"))
add("testImplementation", libs.findBundle("junit5").get())
add("testImplementation", libs.findLibrary("truth").get())
}
Expand Down
32 changes: 32 additions & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
import org.jetbrains.kotlin.konan.properties.Properties

plugins {
alias(libs.plugins.ktlint)
alias(libs.plugins.funch.android.library)
alias(libs.plugins.funch.kotlinx.serialization)
alias(libs.plugins.funch.junit5)
}

val properties =
Properties().apply {
load(rootProject.file("local.properties").inputStream())
}
android {
namespace = "com.moja.funch.network"

buildTypes {
getByName("release") {
buildConfigField(
"String",
"FUNCH_DEBUG_BASE_URL",
properties.getProperty("FUNCH_DEBUG_BASE_URL"),
)
}
getByName("debug") {
buildConfigField(
"String",
"FUNCH_DEBUG_BASE_URL",
properties.getProperty("FUNCH_DEBUG_BASE_URL"),
)
}
}
}

dependencies {
implementation(projects.core.datastore)
implementation(projects.core.testing)

implementation(libs.bundles.retrofit)
implementation(platform(libs.okhttp.bom))
implementation(libs.okhttp.logging.interceptor)
// test
testImplementation(libs.mockk)
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.mockk.webserver)
}
4 changes: 0 additions & 4 deletions core/network/src/main/java/com/moya/funch/network/MyClass.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.moya.funch.network.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.moja.funch.network.BuildConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Converter
import retrofit2.Retrofit
import java.util.concurrent.TimeUnit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object RetrofitModule {
@Provides
@Singleton
fun provideJson(): Json =
Json {
coerceInputValues = true
}

@Singleton
@Provides
fun provideJsonConverterFactory(json: Json): Converter.Factory {
return json.asConverterFactory("application/json".toMediaType())
}

@Singleton
@Provides
fun provideLoggingInterceptor(): Interceptor =
HttpLoggingInterceptor().setLevel(
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.NONE
},
)

@Singleton
@Provides
fun provideOkHttpClient(logInterceptor: Interceptor): OkHttpClient =
OkHttpClient
.Builder()
.addInterceptor(logInterceptor)
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS).build()

@Singleton
@Provides
fun provideRetrofit(
client: OkHttpClient,
converterFactory: Converter.Factory,
): Retrofit =
Retrofit.Builder()
.baseUrl(BuildConfig.FUNCH_DEBUG_BASE_URL)
.client(client)
.addConverterFactory(converterFactory)
.build()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.moya.funch.network.di

import com.moya.funch.network.service.MatchingService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.create
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ServiceModule {
@Provides
@Singleton
fun providesMatchingService(retrofit: Retrofit): MatchingService = retrofit.create()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.moya.funch.network.dto.request

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

@Serializable
data class MatchingRequest(
@SerialName("requestMemberId") val userId: String,
@SerialName("targetMemberCode") val targetCode: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.moya.funch.network.dto.response

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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moya.funch.network.dto.response.match

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

@Serializable
data class ChemistryResponse(
@SerialName("title")
val title: String = "",
@SerialName("description")
val description: String = "",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.moya.funch.network.dto.response.match

import com.moya.funch.network.dto.response.profile.ProfileResponse
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class MatchingResponse(
@SerialName("profile")
val profile: ProfileResponse = ProfileResponse(),
@SerialName("similarity")
val similarity: Int = 0,
@SerialName("chemistryInfos")
val chemistryInfos: List<ChemistryResponse> = listOf(),
@SerialName("recommendInfos")
val recommends: List<RecommendResponse> = listOf(),
@SerialName("subwayInfos")
val subways: List<SubwayResponse> = listOf(),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.moya.funch.network.dto.response.match

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

@Serializable
data class RecommendResponse(
@SerialName("title")
val title: String = "",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moya.funch.network.dto.response.match

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

@Serializable
data class SubwayResponse(
@SerialName("lines")
val lines: List<String> = listOf(),
@SerialName("name")
val name: String = "",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.moya.funch.network.dto.response.profile

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

@Serializable
data class ProfileResponse(
@SerialName("name")
val name: String = "",
@SerialName("jobGroup")
val jobGroup: String = "",
@SerialName("clubs")
val clubs: List<String> = listOf(),
@SerialName("mbti")
val mbti: String = "",
@SerialName("constellation")
val constellation: String = "",
@SerialName("subwayNames")
val subwayNames: List<String> = listOf(),
)
Loading

0 comments on commit 62bb831

Please sign in to comment.