Skip to content
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

[Fix] Change DTO #246

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ data class GetMealResponse(

@SerializedName("mealId") var mealId: Long? = null,
@SerializedName("price") var price: Int? = null,
@SerializedName("mainRating") var mainRating: Double? = null,
@SerializedName("menusInformationList") var menusInformationList: ArrayList<MenusInformationList> = arrayListOf(),
@SerializedName("rating") var rating: Double? = null,
@SerializedName("briefMenus") var briefMenus: ArrayList<MenusInformationList> = arrayListOf(),
Comment on lines +10 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

속성명 변경에 따른 일관성 문제가 발견되었습니다.

검색 결과를 통해 다음과 같은 불일치 사항이 확인되었습니다:

  • MealResponse.kt에서 mainRatingrating으로 변경되었으나, 다른 Response 클래스들(MenuReviewInfoResponse, MealReviewInfoResponse, ReviewListResponse 등)에서는 여전히 mainRating을 사용 중입니다.
  • MenuResponse.kt에서는 @SerializedName("rating")을 사용하면서도 변수명은 mainRating을 유지하고 있어 일관성이 없습니다.
  • briefMenus 속성은 MenuOfMealResponseMealResponse에서 서로 다른 타입(MenusInformationMenusInformationList)을 사용하고 있습니다.

이러한 불일치는 API 응답 처리 시 혼란을 야기할 수 있으며, 향후 유지보수에 어려움을 줄 수 있습니다.

🔗 Analysis chain

백엔드 API 스펙과 일치하는지 확인이 필요합니다.

속성 이름이 변경되었습니다:

  • mainRatingrating
  • menusInformationListbriefMenus

이러한 변경사항이 최신 백엔드 API 문서와 일치하는지 확인해주세요.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: API 응답 구조와 일치하는지 확인하기 위해 관련 파일들을 검색합니다.

# API 관련 파일들에서 이전 속성명이 남아있는지 확인
echo "이전 속성명 검색 결과:"
rg "mainRating|menusInformationList" --type kotlin

# 새로운 속성명의 일관된 사용 확인
echo -e "\n새로운 속성명 검색 결과:"
rg "rating|briefMenus" --type kotlin

Length of output: 5624

)

data class MenusInformationList(
Expand All @@ -23,10 +23,10 @@ fun ArrayList<GetMealResponse>.mapTodayMenuResponseToMenu(): List<Menu> {

this.forEach { mealResponse ->
val menuNames =
mealResponse.menusInformationList.joinToString(separator = "+") { it.name ?: "" }
mealResponse.briefMenus.joinToString(separator = "+") { it.name ?: "" }
val mealId = mealResponse.mealId ?: -1
val price = mealResponse.price ?: 0
val mainRating = mealResponse.mainRating ?: 0.0
val mainRating = mealResponse.rating ?: 0.0

val menu = Menu(mealId, menuNames, price, mainRating)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.eatssu.android.domain.model.MenuMini
import com.google.gson.annotations.SerializedName

data class MenuOfMealResponse(
@SerializedName("menusInformation") var menusInformation: ArrayList<MenusInformation> = arrayListOf(),
@SerializedName("briefMenus") var briefMenus: ArrayList<MenusInformation> = arrayListOf(),
)

data class MenusInformation(
Expand All @@ -15,7 +15,7 @@ data class MenusInformation(
)

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

fun MenusInformation.toMenuMini(): MenuMini {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.eatssu.android.data.dto.response

import android.util.Log
import com.eatssu.android.domain.model.Menu
import com.google.gson.annotations.SerializedName
import timber.log.Timber


data class GetFixedMenuResponse(
Expand All @@ -14,7 +14,7 @@ data class GetFixedMenuResponse(
data class CategoryMenuListCollection(

@SerializedName("category") var category: String? = null,
@SerializedName("menuInformationList") var menuInformationList: ArrayList<MenuInformationList> = arrayListOf(),
@SerializedName("menus") var menus: ArrayList<MenuInformationList> = arrayListOf(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

DTO 필드명이 백엔드 변경사항과 일치하도록 수정되었습니다.

  • menuInformationListmenus
  • mainRating SerializedName이 rating으로 변경

하지만 mainRating 변수명은 여전히 이전 명명규칙을 따르고 있습니다.

다음과 같이 변수명도 일관성 있게 변경하는 것을 추천드립니다:

-    @SerializedName("rating") var mainRating: Double? = null,
+    @SerializedName("rating") var rating: Double? = null,

Also applies to: 26-26


)

Expand All @@ -23,38 +23,27 @@ data class MenuInformationList(
@SerializedName("menuId") var menuId: Long? = null,
@SerializedName("name") var name: String? = null,
@SerializedName("price") var price: Int? = null,
@SerializedName("mainRating") var mainRating: Double? = null,
@SerializedName("rating") var rating: Double? = null,

)

//fun GetFixedMenuResponse.mapFixedMenuResponseToMenu(): List<Menu> {
// return this.map { fixMenuInfo ->
// Menu(
// id = fixMenuInfo.menuId ?: 0,
// name = fixMenuInfo.name ?: "",
// price = fixMenuInfo.price ?: 0,
// rate = fixMenuInfo.mainRating ?: 0.0
// )
// }
//}


fun GetFixedMenuResponse.mapFixedMenuResponseToMenu(): List<Menu> {
val menus = mutableListOf<Menu>()

categoryMenuListCollection.forEach { categoryMenuList ->
val categoryName = categoryMenuList.category ?: ""
categoryMenuList.menuInformationList.forEach { menuInfo ->
categoryMenuList.menus.forEach { menuInfo ->
val menu = Menu(
id = menuInfo.menuId ?: 0,
name = menuInfo.name ?: "",
price = menuInfo.price ?: 0,
rate = menuInfo.mainRating ?: 0.0
rate = menuInfo.rating ?: 0.0
)
menus.add(menu)
}
}
Log.d("mapFixedMenuResponseToMenu", menus.toString())
Timber.d(menus.toString())

return menus
}
10 changes: 8 additions & 2 deletions app/src/main/java/com/eatssu/android/data/service/MealService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import retrofit2.http.Path
import retrofit2.http.Query

interface MealService {
@GET("meals") //변동메뉴 식단 리스트 조회 By 식당
/**
* 변동메뉴 식단 리스트 조회 By 식당
*/
@GET("meals")
fun getTodayMeal(
@Query("date") date: String,
@Query("restaurant") restaurant: String,
@Query("time") time: String,
): Call<BaseResponse<ArrayList<GetMealResponse>>>

@GET("meals/{mealId}/menus-info") //메뉴 정보 리스트 조회
/**
* 메뉴 정보 리스트 조회
*/
@GET("meals/{mealId}/menus-info")
suspend fun getMenuInfoByMealId(
@Path("mealId") mealId: Long,
): BaseResponse<MenuOfMealResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import retrofit2.http.GET
import retrofit2.http.Query

interface MenuService {
@GET("menus") //고정 메뉴 리스트 조회

/**
* 고정 메뉴 리스트 조회
*/
@GET("menus")
fun getFixMenu(
@Query("restaurant") restaurant: String,
): Call<BaseResponse<GetFixedMenuResponse>>
Expand Down
Loading