Skip to content

Commit

Permalink
Merge pull request #95 from everymeals/feature/review_api
Browse files Browse the repository at this point in the history
Feature/review api
  • Loading branch information
kez-lab authored Feb 4, 2024
2 parents f9f76de + 8569431 commit e37c8ce
Show file tree
Hide file tree
Showing 53 changed files with 1,063 additions and 404 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.everymeal.everymeal_android.di
import com.everymeal.data.service.auth.AuthApi
import com.everymeal.data.service.onboarding.OnboardingApi
import com.everymeal.data.service.restaurant.RestaurantApi
import com.everymeal.data.service.review.StoreReviewApi
import com.everymeal.data.service.search.SearchService
import com.everymeal.everymeal_android.BuildConfig
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
Expand Down Expand Up @@ -30,20 +32,20 @@ object NetworkModule {
fun provideClient(): OkHttpClient {
val interceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
return OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(100, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.build()
.addInterceptor(interceptor)
.connectTimeout(100, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.build()
}

@Provides
@Singleton
fun provideRetrofit(client: OkHttpClient): Retrofit {
return Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(json.asConverterFactory(contentType))
.client(client)
.build()
.baseUrl(BASE_URL)
.addConverterFactory(json.asConverterFactory(contentType))
.client(client)
.build()
}

@Provides
Expand All @@ -63,4 +65,16 @@ object NetworkModule {
fun provideRestaurantApi(retrofit: Retrofit): RestaurantApi {
return retrofit.create(RestaurantApi::class.java)
}
}

@Provides
@Singleton
fun provideReviewApi(retrofit: Retrofit): StoreReviewApi {
return retrofit.create(StoreReviewApi::class.java)
}

@Provides
@Singleton
fun provideSearchApi(retrofit: Retrofit): SearchService {
return retrofit.create(SearchService::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ import com.everymeal.data.datasource.onboarding.OnboardingDataSource
import com.everymeal.data.datasource.onboarding.OnboardingDataSourceImpl
import com.everymeal.data.datasource.restaurant.RestaurantDataSource
import com.everymeal.data.datasource.restaurant.RestaurantDataSourceImpl
import com.everymeal.data.datasource.review.ReviewDataSource
import com.everymeal.data.datasource.review.ReviewDataSourceImpl
import com.everymeal.data.repository.auth.DefaultAuthRepository
import com.everymeal.data.repository.local.LocalRepositoryImpl
import com.everymeal.data.repository.DefaultAuthRepository
import com.everymeal.data.repository.onboarding.OnboardingRepositoryImpl
import com.everymeal.data.repository.restaurant.RestaurantRepositoryImpl
import com.everymeal.domain.repository.local.LocalRepository
import com.everymeal.data.repository.review.DefaultReviewRepository
import com.everymeal.data.repository.search.DefaultSearchRepository
import com.everymeal.domain.repository.auth.AuthRepository
import com.everymeal.domain.repository.local.LocalRepository
import com.everymeal.domain.repository.onboarding.OnboardingRepository
import com.everymeal.domain.repository.restaurant.RestaurantRepository
import com.everymeal.presentation.ui.home.Restaurant
import com.everymeal.domain.repository.review.ReviewRepository
import com.everymeal.domain.repository.search.SearchRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -30,48 +35,66 @@ abstract class RepositoryModule {
@Singleton
@Binds
abstract fun bindOnboardingRepository(
onboardingRepositoryImpl: OnboardingRepositoryImpl
onboardingRepositoryImpl: OnboardingRepositoryImpl,
): OnboardingRepository

@Singleton
@Binds
abstract fun bindOnboardingDataSource(
onboardingDataSourceImpl: OnboardingDataSourceImpl
onboardingDataSourceImpl: OnboardingDataSourceImpl,
): OnboardingDataSource

@Singleton
@Binds
abstract fun bindLocalRepository(
localRepositoryImpl: LocalRepositoryImpl
localRepositoryImpl: LocalRepositoryImpl,
): LocalRepository

@Singleton
@Binds
abstract fun bindLocalDataSource(
localDataSourceImpl: LocalDataSourceImpl
localDataSourceImpl: LocalDataSourceImpl,
): LocalDataSource

@Singleton
@Binds
abstract fun bindAuthRemoteDataSource(
authRemoteDataSourceImpl: AuthRemoteRemoteDataSourceImpl
authRemoteDataSourceImpl: AuthRemoteRemoteDataSourceImpl,
): AuthRemoteDataSource

@Singleton
@Binds
abstract fun bindRestaurantDataSource(
restaurantDataSourceImpl: RestaurantDataSourceImpl,
): RestaurantDataSource

@Singleton
@Binds
abstract fun bindRestaurantRepository(
restaurantRepositoryImpl: RestaurantRepositoryImpl,
): RestaurantRepository

@Singleton
@Binds
abstract fun bindAuthRepository(
defaultAuthRepository: DefaultAuthRepository
defaultAuthRepository: DefaultAuthRepository,
): AuthRepository

@Singleton
@Binds
abstract fun bindRestaurantDataSource(
restaurantDataSourceImpl: RestaurantDataSourceImpl
): RestaurantDataSource
abstract fun bindReviewDataSource(
reviewDataSourceImpl: ReviewDataSourceImpl,
): ReviewDataSource

@Singleton
@Binds
abstract fun bindRestaurantRepository(
restaurantRepositoryImpl: RestaurantRepositoryImpl
): RestaurantRepository
abstract fun bindReviewRepository(
defaultReviewRepository: DefaultReviewRepository,
): ReviewRepository

@Singleton
@Binds
abstract fun bindSearchRepository(
defaultSearchRepository: DefaultSearchRepository,
): SearchRepository
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.everymeal.data.datasource.auth

import com.everymeal.data.model.auth.EmailResponse
import com.everymeal.data.model.auth.toEmail
import com.everymeal.data.model.auth.toEmailAuthToken
import com.everymeal.data.model.auth.toEmailRequest
import com.everymeal.data.model.unwrapData
import com.everymeal.data.service.auth.AuthApi
import com.everymeal.domain.model.auth.Email
import com.everymeal.domain.model.auth.EmailAuthToken
import javax.inject.Inject

class AuthRemoteRemoteDataSourceImpl @Inject constructor(
private val authApi: AuthApi
private val authApi: AuthApi,
) : AuthRemoteDataSource {

override suspend fun postEmail(email: Email): Result<EmailAuthToken> = runCatching {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.everymeal.data.datasource.review

import com.everymeal.data.model.review.ReviewListResponse
import com.everymeal.data.model.review.StoreReviewRequest

interface ReviewDataSource {
suspend fun getReviewList(
cursorIdx: Int,
mealIdx: Int,
pageSize: Int,
): Result<ReviewListResponse>

suspend fun postReview(storeReviewRequest: StoreReviewRequest): Result<Boolean>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.everymeal.data.datasource.review

import com.everymeal.data.model.review.ReviewListResponse
import com.everymeal.data.model.review.StoreReviewRequest
import com.everymeal.data.model.unwrapRunCatching
import com.everymeal.data.service.review.StoreReviewApi
import javax.inject.Inject

class ReviewDataSourceImpl @Inject constructor(
private val storeReviewApi: StoreReviewApi,
) : ReviewDataSource {

override suspend fun getReviewList(
cursorIdx: Int,
mealIdx: Int,
pageSize: Int,
): Result<ReviewListResponse> =
unwrapRunCatching {
storeReviewApi.getStoreReviewsWithId(
cursorIdx,
mealIdx,
pageSize,
)
}

override suspend fun postReview(
storeReviewRequest: StoreReviewRequest,
): Result<Boolean> = unwrapRunCatching { storeReviewApi.postStoreReview(storeReviewRequest) }
}
6 changes: 5 additions & 1 deletion data/src/main/java/com/everymeal/data/model/BaseResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ data class BaseResponse<T>(

fun <T> Result<BaseResponse<T>>.unwrapData(): Result<T> {
return this.map { it.data }
}
}

suspend fun <T> unwrapRunCatching(block: suspend () -> BaseResponse<T>): Result<T> {
return runCatching { block() }.unwrapData()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class GetUnivRestaurantResponse(
val sort: Sort,
val numberOfElements: Int,
val first: Boolean,
val empty: Boolean
val empty: Boolean,
)

@Serializable
Expand All @@ -31,7 +31,7 @@ data class RestaurantResponse(
val reviewCount: Int,
val recommendedCount: Int,
val images: List<String>?,
val isLiked: Boolean
val isLiked: Boolean,
)

@Serializable
Expand All @@ -41,17 +41,17 @@ data class Pageable(
val pageNumber: Int,
val pageSize: Int,
val paged: Boolean,
val unpaged: Boolean
val unpaged: Boolean,
)

@Serializable
data class Sort(
val empty: Boolean,
val sorted: Boolean,
val unsorted: Boolean
val unsorted: Boolean,
)

fun RestaurantResponse.toEntity(): RestaurantDataEntity {
fun RestaurantResponse.toRestaurant(): RestaurantDataEntity {
return RestaurantDataEntity(
idx = this.idx,
name = this.name,
Expand All @@ -63,12 +63,13 @@ fun RestaurantResponse.toEntity(): RestaurantDataEntity {
reviewCount = this.reviewCount,
recommendedCount = this.recommendedCount,
images = this.images,
isLiked = this.isLiked
isLiked = this.isLiked,
)
}

fun GetUnivRestaurantResponse.toEntity(): GetUnivRestaurantEntity {

fun GetUnivRestaurantResponse.toGetUnivRestaurantEntity(): GetUnivRestaurantEntity {
return GetUnivRestaurantEntity(
data = this.content.map { it.toEntity() }
data = this.content.map { it.toRestaurant() }
)
}
}
Loading

0 comments on commit e37c8ce

Please sign in to comment.