Skip to content

Commit e37c8ce

Browse files
authored
Merge pull request #95 from everymeals/feature/review_api
Feature/review api
2 parents f9f76de + 8569431 commit e37c8ce

File tree

53 files changed

+1063
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1063
-404
lines changed

app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt

+23-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.everymeal.everymeal_android.di
33
import com.everymeal.data.service.auth.AuthApi
44
import com.everymeal.data.service.onboarding.OnboardingApi
55
import com.everymeal.data.service.restaurant.RestaurantApi
6+
import com.everymeal.data.service.review.StoreReviewApi
7+
import com.everymeal.data.service.search.SearchService
68
import com.everymeal.everymeal_android.BuildConfig
79
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
810
import dagger.Module
@@ -30,20 +32,20 @@ object NetworkModule {
3032
fun provideClient(): OkHttpClient {
3133
val interceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
3234
return OkHttpClient.Builder()
33-
.addInterceptor(interceptor)
34-
.connectTimeout(100, TimeUnit.SECONDS)
35-
.readTimeout(100, TimeUnit.SECONDS)
36-
.build()
35+
.addInterceptor(interceptor)
36+
.connectTimeout(100, TimeUnit.SECONDS)
37+
.readTimeout(100, TimeUnit.SECONDS)
38+
.build()
3739
}
3840

3941
@Provides
4042
@Singleton
4143
fun provideRetrofit(client: OkHttpClient): Retrofit {
4244
return Retrofit.Builder()
43-
.baseUrl(BASE_URL)
44-
.addConverterFactory(json.asConverterFactory(contentType))
45-
.client(client)
46-
.build()
45+
.baseUrl(BASE_URL)
46+
.addConverterFactory(json.asConverterFactory(contentType))
47+
.client(client)
48+
.build()
4749
}
4850

4951
@Provides
@@ -63,4 +65,16 @@ object NetworkModule {
6365
fun provideRestaurantApi(retrofit: Retrofit): RestaurantApi {
6466
return retrofit.create(RestaurantApi::class.java)
6567
}
66-
}
68+
69+
@Provides
70+
@Singleton
71+
fun provideReviewApi(retrofit: Retrofit): StoreReviewApi {
72+
return retrofit.create(StoreReviewApi::class.java)
73+
}
74+
75+
@Provides
76+
@Singleton
77+
fun provideSearchApi(retrofit: Retrofit): SearchService {
78+
return retrofit.create(SearchService::class.java)
79+
}
80+
}

app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt

+38-15
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ import com.everymeal.data.datasource.onboarding.OnboardingDataSource
88
import com.everymeal.data.datasource.onboarding.OnboardingDataSourceImpl
99
import com.everymeal.data.datasource.restaurant.RestaurantDataSource
1010
import com.everymeal.data.datasource.restaurant.RestaurantDataSourceImpl
11+
import com.everymeal.data.datasource.review.ReviewDataSource
12+
import com.everymeal.data.datasource.review.ReviewDataSourceImpl
13+
import com.everymeal.data.repository.auth.DefaultAuthRepository
1114
import com.everymeal.data.repository.local.LocalRepositoryImpl
12-
import com.everymeal.data.repository.DefaultAuthRepository
1315
import com.everymeal.data.repository.onboarding.OnboardingRepositoryImpl
1416
import com.everymeal.data.repository.restaurant.RestaurantRepositoryImpl
15-
import com.everymeal.domain.repository.local.LocalRepository
17+
import com.everymeal.data.repository.review.DefaultReviewRepository
18+
import com.everymeal.data.repository.search.DefaultSearchRepository
1619
import com.everymeal.domain.repository.auth.AuthRepository
20+
import com.everymeal.domain.repository.local.LocalRepository
1721
import com.everymeal.domain.repository.onboarding.OnboardingRepository
1822
import com.everymeal.domain.repository.restaurant.RestaurantRepository
19-
import com.everymeal.presentation.ui.home.Restaurant
23+
import com.everymeal.domain.repository.review.ReviewRepository
24+
import com.everymeal.domain.repository.search.SearchRepository
2025
import dagger.Binds
2126
import dagger.Module
2227
import dagger.hilt.InstallIn
@@ -30,48 +35,66 @@ abstract class RepositoryModule {
3035
@Singleton
3136
@Binds
3237
abstract fun bindOnboardingRepository(
33-
onboardingRepositoryImpl: OnboardingRepositoryImpl
38+
onboardingRepositoryImpl: OnboardingRepositoryImpl,
3439
): OnboardingRepository
3540

3641
@Singleton
3742
@Binds
3843
abstract fun bindOnboardingDataSource(
39-
onboardingDataSourceImpl: OnboardingDataSourceImpl
44+
onboardingDataSourceImpl: OnboardingDataSourceImpl,
4045
): OnboardingDataSource
4146

4247
@Singleton
4348
@Binds
4449
abstract fun bindLocalRepository(
45-
localRepositoryImpl: LocalRepositoryImpl
50+
localRepositoryImpl: LocalRepositoryImpl,
4651
): LocalRepository
4752

4853
@Singleton
4954
@Binds
5055
abstract fun bindLocalDataSource(
51-
localDataSourceImpl: LocalDataSourceImpl
56+
localDataSourceImpl: LocalDataSourceImpl,
5257
): LocalDataSource
5358

5459
@Singleton
5560
@Binds
5661
abstract fun bindAuthRemoteDataSource(
57-
authRemoteDataSourceImpl: AuthRemoteRemoteDataSourceImpl
62+
authRemoteDataSourceImpl: AuthRemoteRemoteDataSourceImpl,
5863
): AuthRemoteDataSource
5964

65+
@Singleton
66+
@Binds
67+
abstract fun bindRestaurantDataSource(
68+
restaurantDataSourceImpl: RestaurantDataSourceImpl,
69+
): RestaurantDataSource
70+
71+
@Singleton
72+
@Binds
73+
abstract fun bindRestaurantRepository(
74+
restaurantRepositoryImpl: RestaurantRepositoryImpl,
75+
): RestaurantRepository
76+
6077
@Singleton
6178
@Binds
6279
abstract fun bindAuthRepository(
63-
defaultAuthRepository: DefaultAuthRepository
80+
defaultAuthRepository: DefaultAuthRepository,
6481
): AuthRepository
6582

6683
@Singleton
6784
@Binds
68-
abstract fun bindRestaurantDataSource(
69-
restaurantDataSourceImpl: RestaurantDataSourceImpl
70-
): RestaurantDataSource
85+
abstract fun bindReviewDataSource(
86+
reviewDataSourceImpl: ReviewDataSourceImpl,
87+
): ReviewDataSource
7188

7289
@Singleton
7390
@Binds
74-
abstract fun bindRestaurantRepository(
75-
restaurantRepositoryImpl: RestaurantRepositoryImpl
76-
): RestaurantRepository
91+
abstract fun bindReviewRepository(
92+
defaultReviewRepository: DefaultReviewRepository,
93+
): ReviewRepository
94+
95+
@Singleton
96+
@Binds
97+
abstract fun bindSearchRepository(
98+
defaultSearchRepository: DefaultSearchRepository,
99+
): SearchRepository
77100
}

data/src/main/java/com/everymeal/data/datasource/auth/AuthRemoteRemoteDataSourceImpl.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package com.everymeal.data.datasource.auth
22

3-
import com.everymeal.data.model.auth.EmailResponse
4-
import com.everymeal.data.model.auth.toEmail
53
import com.everymeal.data.model.auth.toEmailAuthToken
64
import com.everymeal.data.model.auth.toEmailRequest
7-
import com.everymeal.data.model.unwrapData
85
import com.everymeal.data.service.auth.AuthApi
96
import com.everymeal.domain.model.auth.Email
107
import com.everymeal.domain.model.auth.EmailAuthToken
118
import javax.inject.Inject
129

1310
class AuthRemoteRemoteDataSourceImpl @Inject constructor(
14-
private val authApi: AuthApi
11+
private val authApi: AuthApi,
1512
) : AuthRemoteDataSource {
1613

1714
override suspend fun postEmail(email: Email): Result<EmailAuthToken> = runCatching {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.everymeal.data.datasource.review
2+
3+
import com.everymeal.data.model.review.ReviewListResponse
4+
import com.everymeal.data.model.review.StoreReviewRequest
5+
6+
interface ReviewDataSource {
7+
suspend fun getReviewList(
8+
cursorIdx: Int,
9+
mealIdx: Int,
10+
pageSize: Int,
11+
): Result<ReviewListResponse>
12+
13+
suspend fun postReview(storeReviewRequest: StoreReviewRequest): Result<Boolean>
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.everymeal.data.datasource.review
2+
3+
import com.everymeal.data.model.review.ReviewListResponse
4+
import com.everymeal.data.model.review.StoreReviewRequest
5+
import com.everymeal.data.model.unwrapRunCatching
6+
import com.everymeal.data.service.review.StoreReviewApi
7+
import javax.inject.Inject
8+
9+
class ReviewDataSourceImpl @Inject constructor(
10+
private val storeReviewApi: StoreReviewApi,
11+
) : ReviewDataSource {
12+
13+
override suspend fun getReviewList(
14+
cursorIdx: Int,
15+
mealIdx: Int,
16+
pageSize: Int,
17+
): Result<ReviewListResponse> =
18+
unwrapRunCatching {
19+
storeReviewApi.getStoreReviewsWithId(
20+
cursorIdx,
21+
mealIdx,
22+
pageSize,
23+
)
24+
}
25+
26+
override suspend fun postReview(
27+
storeReviewRequest: StoreReviewRequest,
28+
): Result<Boolean> = unwrapRunCatching { storeReviewApi.postStoreReview(storeReviewRequest) }
29+
}

data/src/main/java/com/everymeal/data/model/BaseResponse.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ data class BaseResponse<T>(
1111

1212
fun <T> Result<BaseResponse<T>>.unwrapData(): Result<T> {
1313
return this.map { it.data }
14-
}
14+
}
15+
16+
suspend fun <T> unwrapRunCatching(block: suspend () -> BaseResponse<T>): Result<T> {
17+
return runCatching { block() }.unwrapData()
18+
}

data/src/main/java/com/everymeal/data/model/restaruant/GetUnivRestaurantResponse.kt

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data class GetUnivRestaurantResponse(
1616
val sort: Sort,
1717
val numberOfElements: Int,
1818
val first: Boolean,
19-
val empty: Boolean
19+
val empty: Boolean,
2020
)
2121

2222
@Serializable
@@ -31,7 +31,7 @@ data class RestaurantResponse(
3131
val reviewCount: Int,
3232
val recommendedCount: Int,
3333
val images: List<String>?,
34-
val isLiked: Boolean
34+
val isLiked: Boolean,
3535
)
3636

3737
@Serializable
@@ -41,17 +41,17 @@ data class Pageable(
4141
val pageNumber: Int,
4242
val pageSize: Int,
4343
val paged: Boolean,
44-
val unpaged: Boolean
44+
val unpaged: Boolean,
4545
)
4646

4747
@Serializable
4848
data class Sort(
4949
val empty: Boolean,
5050
val sorted: Boolean,
51-
val unsorted: Boolean
51+
val unsorted: Boolean,
5252
)
5353

54-
fun RestaurantResponse.toEntity(): RestaurantDataEntity {
54+
fun RestaurantResponse.toRestaurant(): RestaurantDataEntity {
5555
return RestaurantDataEntity(
5656
idx = this.idx,
5757
name = this.name,
@@ -63,12 +63,13 @@ fun RestaurantResponse.toEntity(): RestaurantDataEntity {
6363
reviewCount = this.reviewCount,
6464
recommendedCount = this.recommendedCount,
6565
images = this.images,
66-
isLiked = this.isLiked
66+
isLiked = this.isLiked,
6767
)
6868
}
6969

70-
fun GetUnivRestaurantResponse.toEntity(): GetUnivRestaurantEntity {
70+
71+
fun GetUnivRestaurantResponse.toGetUnivRestaurantEntity(): GetUnivRestaurantEntity {
7172
return GetUnivRestaurantEntity(
72-
data = this.content.map { it.toEntity() }
73+
data = this.content.map { it.toRestaurant() }
7374
)
74-
}
75+
}

0 commit comments

Comments
 (0)