Skip to content

Commit

Permalink
[Fix] Change DTO (#246)
Browse files Browse the repository at this point in the history
* chore: change dto

* chore: change dto
  • Loading branch information
HI-JIN2 authored Nov 28, 2024
1 parent 1e76c14 commit ba974ca
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
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(),
)

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(),

)

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

0 comments on commit ba974ca

Please sign in to comment.