-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor/#162] ReviewService 부분 Hilt+Flow 리팩토링 #170
Changes from 32 commits
76e14b5
103545e
5ab0b7e
63e575b
402bec0
9c3d091
0703c0c
ef6f4d9
5ef72e6
7d537d2
3a9cd5b
11d664a
b7df60d
0a947f6
85d88fa
4334962
be28ff6
f175a88
8ba8265
321c970
fabfce4
92737fe
774b229
7f4023b
c13107e
7c82bfa
b389ca2
56fa3b4
e331c9b
aae97b6
e589b47
00f31a4
57ef195
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.eatssu.android.data.repository | ||
|
||
import com.eatssu.android.base.BaseResponse | ||
import com.eatssu.android.data.dto.response.MenuOfMealResponse | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface MealRepository { | ||
// suspend fun getTodayMeal( | ||
// date: String, | ||
// restaurant: String, | ||
// time: String, | ||
// ): Flow<BaseResponse<ArrayList<GetMealResponse>>> | ||
|
||
suspend fun getMenuInfoByMealId( | ||
mealId: Long, | ||
): Flow<BaseResponse<MenuOfMealResponse>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.eatssu.android.data.repository | ||
|
||
import com.eatssu.android.base.BaseResponse | ||
import com.eatssu.android.data.dto.response.MenuOfMealResponse | ||
import com.eatssu.android.data.service.MealService | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import javax.inject.Inject | ||
|
||
class MealRepositoryImpl @Inject constructor(private val mealService: MealService) : | ||
MealRepository { | ||
|
||
// override suspend fun getTodayMeal( | ||
// date: String, | ||
// restaurant: String, | ||
// time: String | ||
// ): Flow<BaseResponse<ArrayList<GetMealResponse>>> = | ||
// flow { emit(mealService.getTodayMeal(date, restaurant, time)) } | ||
|
||
override suspend fun getMenuInfoByMealId(mealId: Long): Flow<BaseResponse<MenuOfMealResponse>> = | ||
flow { | ||
emit(mealService.getMenuInfoByMealId(mealId)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,47 @@ | ||
package com.eatssu.android.data.repository | ||
|
||
import com.eatssu.android.data.service.ReviewService | ||
import com.eatssu.android.base.BaseResponse | ||
import com.eatssu.android.data.dto.request.ModifyReviewRequest | ||
import com.eatssu.android.data.dto.request.WriteReviewRequest | ||
import com.eatssu.android.data.dto.response.GetMealReviewInfoResponse | ||
import com.eatssu.android.data.dto.response.GetMenuReviewInfoResponse | ||
import com.eatssu.android.data.dto.response.GetReviewListResponse | ||
import com.eatssu.android.data.dto.response.ImageResponse | ||
import kotlinx.coroutines.flow.Flow | ||
import okhttp3.MultipartBody | ||
|
||
class ReviewRepository(private val reviewService: ReviewService) { | ||
interface ReviewRepository { | ||
|
||
// override suspend fun reissueToken( | ||
// refreshToken: String | ||
// ): Flow<ReissueResponse> = flow { | ||
// emit(authService.reissueToken(refreshToken)) | ||
// } | ||
suspend fun writeReview( | ||
menuId: Long, | ||
body: WriteReviewRequest, | ||
): Flow<BaseResponse<Void>> | ||
|
||
// suspend fun getMenuReviewInfo(menuId: Long) | ||
// : Flow<BaseResponse<GetMenuReviewInfoResponse>> = | ||
// flow { | ||
// emit(reviewService.getMenuReviewInfo(menuId)) | ||
// } | ||
suspend fun deleteReview( | ||
reviewId: Long, | ||
): Flow<BaseResponse<Void>> | ||
|
||
suspend fun modifyReview( | ||
reviewId: Long, | ||
body: ModifyReviewRequest, | ||
): Flow<BaseResponse<Void>> | ||
|
||
suspend fun getReviewList( | ||
menuType: String, | ||
mealId: Long?, | ||
menuId: Long?, | ||
): Flow<BaseResponse<GetReviewListResponse>> | ||
|
||
suspend fun getMenuReviewInfo( | ||
menuId: Long, | ||
): Flow<BaseResponse<GetMenuReviewInfoResponse>> | ||
|
||
|
||
suspend fun getMealReviewInfo( | ||
mealId: Long, | ||
): Flow<BaseResponse<GetMealReviewInfoResponse>> | ||
|
||
suspend fun getImageString( | ||
image: MultipartBody.Part, | ||
): Flow<BaseResponse<ImageResponse>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.eatssu.android.data.repository | ||
|
||
import com.eatssu.android.base.BaseResponse | ||
import com.eatssu.android.data.dto.request.ModifyReviewRequest | ||
import com.eatssu.android.data.dto.request.WriteReviewRequest | ||
import com.eatssu.android.data.dto.response.GetMealReviewInfoResponse | ||
import com.eatssu.android.data.dto.response.GetMenuReviewInfoResponse | ||
import com.eatssu.android.data.dto.response.GetReviewListResponse | ||
import com.eatssu.android.data.dto.response.ImageResponse | ||
import com.eatssu.android.data.service.ReviewService | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import okhttp3.MultipartBody | ||
import javax.inject.Inject | ||
|
||
class ReviewRepositoryImpl @Inject constructor(private val reviewService: ReviewService) : | ||
ReviewRepository { | ||
|
||
override suspend fun writeReview( | ||
menuId: Long, | ||
body: WriteReviewRequest, | ||
): Flow<BaseResponse<Void>> = | ||
flow { | ||
emit(reviewService.writeReview(menuId, body)) | ||
} | ||
|
||
Comment on lines
+19
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
각 메서드는 적용할 수 있는 코드 수정 예시: - override suspend fun writeReview(
+ override fun writeReview( 다른 메서드들도 동일하게 수정할 수 있습니다. Also applies to: 27-31, 32-39, 40-47, 48-52, 53-57, 58-64 |
||
override suspend fun deleteReview(reviewId: Long): Flow<BaseResponse<Void>> = | ||
flow { | ||
emit(reviewService.deleteReview(reviewId)) | ||
} | ||
|
||
override suspend fun modifyReview( | ||
reviewId: Long, | ||
body: ModifyReviewRequest, | ||
): Flow<BaseResponse<Void>> = | ||
flow { | ||
emit(reviewService.modifyReview(reviewId, body)) | ||
} | ||
|
||
override suspend fun getReviewList( | ||
menuType: String, | ||
mealId: Long?, | ||
menuId: Long?, | ||
): Flow<BaseResponse<GetReviewListResponse>> = flow { | ||
emit(reviewService.getReviewList(menuType, mealId, menuId)) | ||
} | ||
|
||
override suspend fun getMenuReviewInfo(menuId: Long): Flow<BaseResponse<GetMenuReviewInfoResponse>> = | ||
flow { | ||
emit(reviewService.getMenuReviewInfo(menuId)) | ||
} | ||
|
||
override suspend fun getMealReviewInfo(mealId: Long): Flow<BaseResponse<GetMealReviewInfoResponse>> = | ||
flow { | ||
emit(reviewService.getMealReviewInfo(mealId)) | ||
} | ||
|
||
override suspend fun getImageString( | ||
image: MultipartBody.Part, | ||
): Flow<BaseResponse<ImageResponse>> = | ||
flow { | ||
emit(reviewService.uploadImage(image)) | ||
} | ||
|
||
Comment on lines
+19
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 에러 처리 로직 추가를 권장드립니다. 현재 구현에서는 서비스 호출 시 발생할 수 있는 예외 상황에 대한 처리가 없습니다. 예시 코드: override fun writeReview(
menuId: Long,
body: WriteReviewRequest,
): Flow<BaseResponse<Void>> = flow {
- emit(reviewService.writeReview(menuId, body))
+ try {
+ emit(reviewService.writeReview(menuId, body))
+ } catch (e: Exception) {
+ emit(BaseResponse.error(e.message ?: "알 수 없는 오류가 발생했습니다"))
+ }
}
|
||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
'suspend' 키워드의 불필요한 사용 검토
'Flow'를 반환하는 함수에서는 일반적으로 'suspend' 키워드가 필요하지 않습니다. 'Flow'는 자체적으로 비동기 스트림을 나타내며, 수집할 때 코루틴 내에서 처리되므로 인터페이스 메서드에서 'suspend'를 제거하여 코드의 간결성과 명확성을 높일 수 있습니다.
적용할 변경 사항:
📝 Committable suggestion