Skip to content

Commit

Permalink
[Refactor/#162] ReviewService 부분 Hilt+Flow 리팩토링 (#170)
Browse files Browse the repository at this point in the history
* add: usecase

* feat: service&repository

* refactor: 리뷰 삭제 리팩토링

* refactor: 리뷰 수정 리팩토링

* refactor: 토스트 string

* refactor: service&repository

* add: 리뷰 리스트&인포 usecase

* refactor: suspend

* add: 수정/삭제 string

* add: 리뷰 요약/리스트 usecase

* refactor: CA 리팩

* fix: 수정하기 됨

* refactor: 이미지 쪽 리팩

* refactor: 리뷰 작성 리팩

* refactor: 이미지 변환 content type 헤더

* delete: 이미지 서비스 합치기

* chore: 이미지 서비스 정리

* feat: 로그인 화면 finish() 추가

* refactor: timber

* test: 이전 버전

* refactor: timber

* refactor: imageusecase not working

* chore: solved conflict

* fix: not load meal's review

* chore: pretter code

* add: missed rebase

* add: debug mode

* chore: 리뷰 반영

* chore

* package: change usecase folders

* refactor: 다중 메뉴 선택 뷰 - 뷰모델 리팩토링

flow, repository, usecase

* chore: @coderabbitai review

* chore: @coderabbitai review2
  • Loading branch information
HI-JIN2 authored Nov 18, 2024
1 parent cf897f7 commit bd357be
Show file tree
Hide file tree
Showing 74 changed files with 1,055 additions and 989 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
applicationId = "com.eatssu.android"
minSdk = 23
targetSdk = 34
versionCode = 21
versionCode = 22
versionName = "2.1.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/eatssu/android/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class App: Application() {
appContext = this
KakaoSdk.init(this,BuildConfig.KAKAO_NATIVE_APP_KEY)

Timber.plant(Timber.DebugTree())
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ data class MenusInformation(

)

fun MenuOfMealResponse.asMenuOfMeal(): List<MenuMini> {
val menuList = mutableListOf<MenuMini>()

this.menusInformation.forEach {

val menu = MenuMini(it.menuId, it.name)
menuList.add(menu)
}

return menuList
fun MenuOfMealResponse.toMenuMiniList(): List<MenuMini> {
return menusInformation.map { it.toMenuMini() }
}

fun MenusInformation.toMenuMini(): MenuMini {
return MenuMini(
id = this.menuId,
name = this.name
)
}

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))
}

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))
}

}
18 changes: 0 additions & 18 deletions app/src/main/java/com/eatssu/android/data/service/ImageService.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ interface MealService {
): Call<BaseResponse<ArrayList<GetMealResponse>>>

@GET("meals/{mealId}/menus-info") //메뉴 정보 리스트 조회
fun getMenuInfoByMealId(
suspend fun getMenuInfoByMealId(
@Path("mealId") mealId: Long,
): Call<BaseResponse<MenuOfMealResponse>>
): BaseResponse<MenuOfMealResponse>

}
55 changes: 33 additions & 22 deletions app/src/main/java/com/eatssu/android/data/service/ReviewService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,63 @@ 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 retrofit2.Call
import retrofit2.http.*
import com.eatssu.android.data.dto.response.ImageResponse
import okhttp3.MultipartBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query


interface ReviewService {
@POST("/reviews/write/{menuId}") //리뷰 작성
fun writeReview(
suspend fun writeReview(
@Path("menuId") menuId: Long,
@Body request: WriteReviewRequest,
): Call<BaseResponse<Void>>
): BaseResponse<Void>

@DELETE("/reviews/{reviewId}") //리뷰 삭제
fun deleteReview(
suspend fun deleteReview(
@Path("reviewId") reviewId: Long,
): Call<BaseResponse<Void>>
): BaseResponse<Void>

@PATCH("/reviews/{reviewId}") //리뷰 수정(글 수정)
fun modifyReview(
suspend fun modifyReview(
@Path("reviewId") reviewId: Long,
@Body request: ModifyReviewRequest,
): Call<BaseResponse<Void>>
): BaseResponse<Void>

//Todo paging 라이브러리 써보기
@GET("/reviews") //리뷰 리스트 조회
fun getReviewList(
suspend fun getReviewList(
@Query("menuType") menuType: String,
@Query("mealId") mealId: Long?,
@Query("menuId") menuId: Long?,
// @Query("lastReviewId") lastReviewId: Long?,
// @Query("page") page: Int? =
// @Query("size") size: Int? = 20
// @Query("sort") sort: List<String>? = arrayListOf("date","DESC")
): Call<BaseResponse<GetReviewListResponse>>

// @GET("/reviews/menus/{menuId}") //고정 메뉴 리뷰 정보 조회(메뉴명, 평점 등등)
// fun getMenuReviewInfo(
// @Path("menuId") menuId: Long,
// ): BaseResponse<GetMenuReviewInfoResponse>
@Query("page") page: Int? = 0,
@Query("size") size: Int? = 20,
@Query("sort") sort: List<String>? = arrayListOf("date", "DESC"),
): BaseResponse<GetReviewListResponse>

@GET("/reviews/menus/{menuId}") //고정 메뉴 리뷰 정보 조회(메뉴명, 평점 등등)
fun getMenuReviewInfo(
suspend fun getMenuReviewInfo(
@Path("menuId") menuId: Long,
): Call<BaseResponse<GetMenuReviewInfoResponse>>
): BaseResponse<GetMenuReviewInfoResponse>

@GET("/reviews/meals/{mealId}") //식단(변동 메뉴) 리뷰 정보 조회(메뉴명, 평점 등등)
fun getMealReviewInfo(
suspend fun getMealReviewInfo(
@Path("mealId") mealId: Long,
): Call<BaseResponse<GetMealReviewInfoResponse>>
): BaseResponse<GetMealReviewInfoResponse>

@Multipart
@POST("/reviews/upload/image") //리뷰 이미지 업로드
suspend fun uploadImage(
@Part image: MultipartBody.Part,
): BaseResponse<ImageResponse>

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.eatssu.android.data.usecase
package com.eatssu.android.data.usecase.alarm

import android.app.AlarmManager
import android.app.PendingIntent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.eatssu.android.data.usecase
package com.eatssu.android.data.usecase.alarm

import com.eatssu.android.data.repository.PreferencesRepository
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.eatssu.android.data.usecase
package com.eatssu.android.data.usecase.alarm

import com.eatssu.android.data.repository.PreferencesRepository
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.eatssu.android.data.usecase
package com.eatssu.android.data.usecase.auth

import android.content.Context
import com.eatssu.android.util.MySharedPreferences
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.eatssu.android.data.usecase
package com.eatssu.android.data.usecase.auth

import com.eatssu.android.base.BaseResponse
import com.eatssu.android.data.dto.response.MyReviewResponse
Expand Down
Loading

0 comments on commit bd357be

Please sign in to comment.