Skip to content

Commit

Permalink
[MERGE] #42 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#42] 디테일뷰 / 상품 세부조회 API 구현
  • Loading branch information
Marchbreeze authored Jul 13, 2024
2 parents 5558520 + 46fe9df commit ebad032
Show file tree
Hide file tree
Showing 33 changed files with 411 additions and 170 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.orange.ddanzi.di
package co.orange.ddanzi.di.interceptor

import android.content.Context
import android.content.Intent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package co.orange.ddanzi.di.interceptor

import co.orange.data.local.UserSharedPref
import okhttp3.Interceptor
import okhttp3.Response
import javax.inject.Inject

class DeviceTokenInterceptor
@Inject
constructor(
private val sharedPref: UserSharedPref,
) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()
val newRequest =
originalRequest.newBuilder()
.header(AUTHORIZATION, "$BEARER ${sharedPref.accessToken}")
.build()
return chain.proceed(newRequest)
}

companion object {
private const val BEARER = "Bearer"
private const val AUTHORIZATION = "Authorization"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package co.orange.ddanzi.di
package co.orange.ddanzi.di.module

import co.orange.data.dataSource.AuthDataSource
import co.orange.data.dataSource.DetailDataSource
import co.orange.data.dataSource.HomeDataSource
import co.orange.data.dataSourceImpl.AuthDataSourceImpl
import co.orange.data.dataSourceImpl.DetailDataSourceImpl
import co.orange.data.dataSourceImpl.HomeDataSourceImpl
import dagger.Module
import dagger.Provides
Expand All @@ -20,4 +22,8 @@ object DataSourceModule {
@Provides
@Singleton
fun provideHomeDataSource(homeDataSourceImpl: HomeDataSourceImpl): HomeDataSource = homeDataSourceImpl

@Provides
@Singleton
fun provideDetailDataSource(detailDataSourceImpl: DetailDataSourceImpl): DetailDataSource = detailDataSourceImpl
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package co.orange.ddanzi.di
package co.orange.ddanzi.di.module

import co.orange.data.repositoryImpl.AuthRepositoryImpl
import co.orange.data.repositoryImpl.DetailRepositoryImpl
import co.orange.data.repositoryImpl.HomeRepositoryImpl
import co.orange.domain.repository.AuthRepository
import co.orange.domain.repository.DetailRepository
import co.orange.domain.repository.HomeRepository
import dagger.Module
import dagger.Provides
Expand All @@ -20,4 +22,8 @@ object RepositoryModule {
@Provides
@Singleton
fun provideHomeRepository(homeRepositoryImpl: HomeRepositoryImpl): HomeRepository = homeRepositoryImpl

@Provides
@Singleton
fun provideDetailRepository(detailRepositoryImpl: DetailRepositoryImpl): DetailRepository = detailRepositoryImpl
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package co.orange.ddanzi.di
package co.orange.ddanzi.di.module

import co.orange.core.extension.isJsonArray
import co.orange.core.extension.isJsonObject
import co.orange.ddanzi.BuildConfig.BASE_URL
import co.orange.ddanzi.di.interceptor.AuthInterceptor
import co.orange.ddanzi.di.interceptor.DeviceTokenInterceptor
import co.orange.ddanzi.di.qualifier.RetrofitQualifier
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -64,6 +67,11 @@ object RetrofitModule {
@RetrofitQualifier.JWT
fun provideAuthInterceptor(authInterceptor: AuthInterceptor): Interceptor = authInterceptor

@Provides
@Singleton
@RetrofitQualifier.DEVICE
fun provideDeviceTokenInterceptor(deviceTokenInterceptor: DeviceTokenInterceptor): Interceptor = deviceTokenInterceptor

@Provides
@Singleton
@RetrofitQualifier.JWT
Expand All @@ -84,6 +92,18 @@ object RetrofitModule {
.addInterceptor(loggingInterceptor)
.build()

@Provides
@Singleton
@RetrofitQualifier.DEVICE
fun provideDeviceOkHttpClient(
loggingInterceptor: Interceptor,
@RetrofitQualifier.DEVICE deviceTokenInterceptor: Interceptor,
): OkHttpClient =
OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.addInterceptor(deviceTokenInterceptor)
.build()

@Provides
@Singleton
@RetrofitQualifier.JWT
Expand All @@ -109,4 +129,17 @@ object RetrofitModule {
.client(client)
.addConverterFactory(factory)
.build()

@Provides
@Singleton
@RetrofitQualifier.DEVICE
fun provideDeviceRetrofit(
@RetrofitQualifier.DEVICE client: OkHttpClient,
factory: Converter.Factory,
): Retrofit =
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(factory)
.build()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package co.orange.ddanzi.di
package co.orange.ddanzi.di.module

import co.orange.data.service.AuthService
import co.orange.data.service.DetailService
import co.orange.data.service.HomeService
import co.orange.ddanzi.di.qualifier.RetrofitQualifier
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -18,10 +20,15 @@ object ServiceModule {
@RetrofitQualifier.NOTOKEN retrofit: Retrofit,
): AuthService = retrofit.create(AuthService::class.java)

// TODO 추후 수정
@Provides
@Singleton
fun provideHomeService(
@RetrofitQualifier.NOTOKEN retrofit: Retrofit,
): HomeService = retrofit.create(HomeService::class.java)

@Provides
@Singleton
fun provideDetailService(
@RetrofitQualifier.DEVICE retrofit: Retrofit,
): DetailService = retrofit.create(DetailService::class.java)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.orange.ddanzi.di
package co.orange.ddanzi.di.module

import android.content.Context
import android.content.SharedPreferences
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.orange.ddanzi.di
package co.orange.ddanzi.di.qualifier

import javax.inject.Qualifier

Expand All @@ -10,4 +10,8 @@ object RetrofitQualifier {
@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class NOTOKEN

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class DEVICE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.orange.data.dataSource

import co.orange.data.dto.BaseResponse
import co.orange.data.dto.response.ProductDetailDto

interface DetailDataSource {
suspend fun getHomeData(id: String): BaseResponse<ProductDetailDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.orange.data.dataSourceImpl

import co.orange.data.dataSource.DetailDataSource
import co.orange.data.dto.BaseResponse
import co.orange.data.dto.response.ProductDetailDto
import co.orange.data.service.DetailService
import javax.inject.Inject

data class DetailDataSourceImpl
@Inject
constructor(
private val detailService: DetailService,
) : DetailDataSource {
override suspend fun getHomeData(id: String): BaseResponse<ProductDetailDto> = detailService.getProductDetail(id)
}
40 changes: 40 additions & 0 deletions data/src/main/java/co/orange/data/dto/response/ProductDetailDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package co.orange.data.dto.response

import co.orange.domain.entity.response.ProductDetailModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ProductDetailDto(
@SerialName("name")
val name: String,
@SerialName("category")
val category: String,
@SerialName("isOptionExist")
val isOptionExist: Boolean,
@SerialName("isImminent")
val isImminent: Boolean,
@SerialName("discountRate")
val discountRate: Int,
@SerialName("stockCount")
val stockCount: Int,
@SerialName("infoUrl")
val infoUrl: String,
@SerialName("interestCount")
val interestCount: Int,
@SerialName("optionList")
val optionList: List<ProductOptionDto>,
) {
fun toModel() =
ProductDetailModel(
name,
category,
isOptionExist,
isImminent,
discountRate,
stockCount,
infoUrl,
interestCount,
optionList.map { it.toModel() },
)
}
29 changes: 29 additions & 0 deletions data/src/main/java/co/orange/data/dto/response/ProductOptionDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package co.orange.data.dto.response

import co.orange.domain.entity.response.ProductOptionModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ProductOptionDto(
@SerialName("optionId")
val optionId: Long,
@SerialName("type")
val type: String,
@SerialName("optionDetailList")
val optionDetailList: List<OptionDetailDto>,
) {
@Serializable
data class OptionDetailDto(
@SerialName("optionDetailId")
val optionDetailId: Long,
@SerialName("content")
val content: String,
@SerialName("isAvailable")
val isAvailable: Boolean,
) {
fun toModel() = ProductOptionModel.OptionDetailModel(optionDetailId, content, isAvailable)
}

fun toModel() = ProductOptionModel(optionId, type, optionDetailList.map { it.toModel() })
}
1 change: 1 addition & 0 deletions data/src/main/java/co/orange/data/local/UserSharedPref.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package co.orange.data.local
interface UserSharedPref {
var accessToken: String
var refreshToken: String
var deviceToken: String
var userId: Long

fun clearInfo()
Expand Down
5 changes: 5 additions & 0 deletions data/src/main/java/co/orange/data/local/UserSharedPrefImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class UserSharedPrefImpl
get() = dataStore.getString(REFRESH_TOKEN, "").orEmpty()
set(value) = dataStore.edit { putString(REFRESH_TOKEN, value) }

override var deviceToken: String
get() = dataStore.getString(DEVICE_TOKEN, "").orEmpty()
set(value) = dataStore.edit { putString(DEVICE_TOKEN, value) }

override var userId: Long
get() = dataStore.getLong(USER_ID, 0L)
set(value) = dataStore.edit { putLong(USER_ID, value) }
Expand All @@ -28,6 +32,7 @@ class UserSharedPrefImpl
companion object {
private const val ACCESS_TOKEN = "ACCESS_TOKEN"
private const val REFRESH_TOKEN = "REFRESH_TOKEN"
private const val DEVICE_TOKEN = "DEVICE_TOKEN"
private const val USER_ID = "USER_ID"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package co.orange.data.repositoryImpl

import co.orange.data.dataSource.DetailDataSource
import co.orange.domain.entity.response.ProductDetailModel
import co.orange.domain.repository.DetailRepository
import javax.inject.Inject

class DetailRepositoryImpl
@Inject
constructor(
private val detailDataSource: DetailDataSource,
) : DetailRepository {
override suspend fun getProductDetail(id: String): Result<ProductDetailModel> =
runCatching {
detailDataSource.getHomeData(id).data.toModel()
}
}
13 changes: 13 additions & 0 deletions data/src/main/java/co/orange/data/service/DetailService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package co.orange.data.service

import co.orange.data.dto.BaseResponse
import co.orange.data.dto.response.ProductDetailDto
import retrofit2.http.GET
import retrofit2.http.Path

interface DetailService {
@GET("/api/v1/home/product/{id}")
suspend fun getProductDetail(
@Path("id") id: String,
): BaseResponse<ProductDetailDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class ProductDetailModel(
val stockCount: Int,
val infoUrl: String,
val interestCount: Int,
val optionList: List<OptionModel>
)
val optionList: List<ProductOptionModel>,
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package co.orange.domain.entity.response

data class OptionModel(
data class ProductOptionModel(
val optionId: Long,
val type: String,
val optionDetailList: List<OptionDetailModel>,
) {
data class OptionDetailModel(
val optionDetailId: Long,
val content: String,
val isAvailable: Boolean,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package co.orange.domain.repository

import co.orange.domain.entity.response.ProductDetailModel

interface DetailRepository {
suspend fun getProductDetail(id: String): Result<ProductDetailModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BuyConfirmActivity : BaseActivity<ActivityBuyConfirmBinding>(R.layout.acti
}

private fun getIntentInfo() {
viewModel.productId = intent.getLongExtra(EXTRA_PRODUCT_ID, -1)
viewModel.productId = intent.getStringExtra(EXTRA_PRODUCT_ID).orEmpty()
}

private fun setIntentUi(item: BuyInfoModel) {
Expand All @@ -79,7 +79,7 @@ class BuyConfirmActivity : BaseActivity<ActivityBuyConfirmBinding>(R.layout.acti
@JvmStatic
fun createIntent(
context: Context,
productId: Long,
productId: String,
): Intent =
Intent(context, BuyConfirmActivity::class.java).apply {
putExtra(EXTRA_PRODUCT_ID, productId)
Expand Down
Loading

0 comments on commit ebad032

Please sign in to comment.