Skip to content

Commit

Permalink
[MERGE] #72 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#72] ์†Œ์…œ ๋กœ๊ทธ์ธ / ์„œ๋ฒ„ํ†ต์‹  ๋กœ์ง ๊ตฌํ˜„
  • Loading branch information
leeeyubin authored Jul 16, 2024
2 parents fd5dd93 + 605a5f8 commit 888b996
Show file tree
Hide file tree
Showing 33 changed files with 302 additions and 147 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/terning/point/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.terning.point.di

import com.terning.data.datasource.MockDataSource
import com.terning.data.datasource.AuthDataSource
import com.terning.data.datasource.SearchDataSource
import com.terning.data.datasourceimpl.MockDataSourceImpl
import com.terning.data.datasourceimpl.AuthDataSourceImpl
import com.terning.data.datasourceimpl.SearchDataSourceImpl
import dagger.Binds
import dagger.Module
Expand All @@ -16,7 +16,7 @@ abstract class DataSourceModule {

@Binds
@Singleton
abstract fun bindMockDataSource(mockDataSourceImpl: MockDataSourceImpl): MockDataSource
abstract fun bindAuthDataSource(authDataSourceImpl: AuthDataSourceImpl): AuthDataSource

@Binds
@Singleton
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/terning/point/di/DataStoreModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.terning.point.di

import android.content.Context
import android.content.SharedPreferences
import com.terning.data.local.TerningDataStore
import com.terning.data.local.TerningDataStoreImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DataStoreModule {

@Provides
@Singleton
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE)

@Provides
@Singleton
fun provideTerningDataStore(dataStoreImpl: TerningDataStoreImpl): TerningDataStore =
dataStoreImpl
}
12 changes: 9 additions & 3 deletions app/src/main/java/com/terning/point/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.terning.point.di

import com.terning.data.repositoryimpl.MockRepositoryImpl
import com.terning.data.repositoryimpl.AuthRepositoryImpl
import com.terning.data.repositoryimpl.SearchViewsRepositoryImpl
import com.terning.domain.repository.MockRepository
import com.terning.data.repositoryimpl.TokenRepositoryImpl
import com.terning.domain.repository.AuthRepository
import com.terning.domain.repository.SearchRepository
import com.terning.domain.repository.TokenRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -16,7 +18,11 @@ abstract class RepositoryModule {

@Binds
@Singleton
abstract fun bindMockRepository(mockRepositoryImpl: MockRepositoryImpl): MockRepository
abstract fun bindAuthRepository(authRepositoryImpl: AuthRepositoryImpl): AuthRepository

@Binds
@Singleton
abstract fun bindTokenRepository(tokenRepositoryImpl: TokenRepositoryImpl): TokenRepository

@Binds
@Singleton
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/terning/point/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.terning.point.di

import com.terning.core.extension.isJsonArray
import com.terning.core.extension.isJsonObject
import com.terning.point.BuildConfig
import com.terning.point.di.qualifier.OPEN
import com.terning.point.BuildConfig.BASE_URL
import com.terning.point.di.qualifier.JWT
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -65,12 +65,12 @@ object RetrofitModule {

@Provides
@Singleton
@OPEN
fun provideOpenRetrofit(
@JWT
fun provideJWTRetrofit(
client: OkHttpClient,
factory: Converter.Factory
): Retrofit = Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.baseUrl(BASE_URL)
.addConverterFactory(factory)
.client(client)
.build()
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/terning/point/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.terning.point.di

import com.terning.data.service.MockService
import com.terning.data.service.AuthService
import com.terning.data.service.SearchService
import com.terning.point.di.qualifier.OPEN
import com.terning.point.di.qualifier.JWT
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -16,11 +16,11 @@ object ServiceModule {

@Provides
@Singleton
fun provideMockService(@OPEN retrofit: Retrofit): MockService =
retrofit.create(MockService::class.java)
fun provideAuthService(@JWT retrofit: Retrofit): AuthService =
retrofit.create(AuthService::class.java)

@Provides
@Singleton
fun provideSearchService(@OPEN retrofit: Retrofit): SearchService =
fun provideSearchService(@JWT retrofit: Retrofit): SearchService =
retrofit.create(SearchService::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import javax.inject.Qualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class OPEN
annotation class JWT
12 changes: 12 additions & 0 deletions data/src/main/java/com/terning/data/datasource/AuthDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.terning.data.datasource

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.SignInRequestDto
import com.terning.data.dto.response.SignInResponseDto

interface AuthDataSource {
suspend fun postSignIn(
authorization: String,
platform: SignInRequestDto
): BaseResponse<SignInResponseDto>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.terning.data.datasourceimpl

import com.terning.data.datasource.AuthDataSource
import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.SignInRequestDto
import com.terning.data.dto.response.SignInResponseDto
import com.terning.data.service.AuthService
import javax.inject.Inject

class AuthDataSourceImpl @Inject constructor(
private val authService: AuthService
) : AuthDataSource {
override suspend fun postSignIn(
authorization: String,
platform: SignInRequestDto
): BaseResponse<SignInResponseDto> = authService.postSignIn(authorization, platform)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import kotlinx.serialization.Serializable
data class NonDataBaseResponse(
@SerialName("status")
val status: Int,
@SerialName("code")
val code: String,
@SerialName("message")
val message: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.terning.data.dto.request

import com.terning.domain.entity.request.SignInRequestModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SignInRequestDto(
@SerialName("authType")
val authType: String
)

fun SignInRequestModel.toSignInRequestDto(): SignInRequestDto =
SignInRequestDto(authType = authType)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.SignInResponseModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SignInResponseDto(
@SerialName("accessToken")
val accessToken: String,
@SerialName("refreshToken")
val refreshToken: String,
@SerialName("userId")
val userId: Long,
@SerialName("authType")
val authType: String,
) {
fun toSignInModel() = SignInResponseModel(
accessToken = accessToken,
refreshToken = refreshToken,
userId = userId,
authType = authType
)
}
8 changes: 8 additions & 0 deletions data/src/main/java/com/terning/data/local/TerningDataStore.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.terning.data.local

interface TerningDataStore {
var accessToken: String
var refreshToken: String
var userId: Long
fun clearInfo()
}
31 changes: 31 additions & 0 deletions data/src/main/java/com/terning/data/local/TerningDataStoreImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.terning.data.local

import android.content.SharedPreferences
import androidx.core.content.edit
import javax.inject.Inject

class TerningDataStoreImpl @Inject constructor(
private val dataStore: SharedPreferences,
) : TerningDataStore {
override var accessToken: String
get() = dataStore.getString(ACCESS_TOKEN, "") ?: ""
set(value) = dataStore.edit { putString(ACCESS_TOKEN, value) }

override var refreshToken: String
get() = dataStore.getString(REFRESH_TOKEN, "") ?: ""
set(value) = dataStore.edit { putString(REFRESH_TOKEN, value) }

override var userId: Long
get() = dataStore.getLong(USER_ID, 0L)
set(value) = dataStore.edit { putLong(USER_ID, value) }

override fun clearInfo() {
dataStore.edit().clear().commit()
}

companion object {
private const val ACCESS_TOKEN = "ACCESS_TOKEN"
private const val REFRESH_TOKEN = "REFRESH_TOKEN"
private const val USER_ID = "USER_ID"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.terning.data.repositoryimpl

import com.terning.data.datasource.AuthDataSource
import com.terning.data.dto.request.toSignInRequestDto
import com.terning.domain.entity.request.SignInRequestModel
import com.terning.domain.entity.response.SignInResponseModel
import com.terning.domain.repository.AuthRepository
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource
) : AuthRepository {
override suspend fun postSignIn(
authorization: String,
request: SignInRequestModel
): Result<SignInResponseModel> = kotlin.runCatching {
authDataSource.postSignIn(
authorization,
request.toSignInRequestDto()
).result.toSignInModel()
}
}

This file was deleted.

Loading

0 comments on commit 888b996

Please sign in to comment.