Skip to content

Commit

Permalink
Merge pull request #94 from everymeals/feature/home_api
Browse files Browse the repository at this point in the history
[feature/home_api] 홈화면 api 연결 및 가게 상세 연결
  • Loading branch information
SsongSik authored Feb 4, 2024
2 parents b7fbbb7 + d2371f6 commit f9f76de
Show file tree
Hide file tree
Showing 20 changed files with 524 additions and 305 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.everymeal.data.datasource.restaurant

import androidx.paging.PagingData
import com.everymeal.data.model.restaruant.GetUnivRestaurantResponse
import com.everymeal.data.model.restaruant.RestaurantResponse
import kotlinx.coroutines.flow.Flow

Expand All @@ -13,4 +14,11 @@ interface RestaurantDataSource {
): Flow<PagingData<RestaurantResponse>>

suspend fun getRestaurantDetail(index: Int): Result<RestaurantResponse>

suspend fun getHomeRestaurant(
campusIdx: Int,
order: String,
group: String? = null,
grade: String? = null,
): Result<GetUnivRestaurantResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.everymeal.data.datasource.restaurant
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.everymeal.data.model.restaruant.GetUnivRestaurantResponse
import com.everymeal.data.model.restaruant.RestaurantResponse
import com.everymeal.data.model.unwrapData
import com.everymeal.data.service.restaurant.RestaurantApi
Expand Down Expand Up @@ -35,4 +36,20 @@ class RestaurantDataSourceImpl @Inject constructor(
override suspend fun getRestaurantDetail(index: Int): Result<RestaurantResponse> {
return runCatching { restaurantApi.getRestaurantDetail(index) }.unwrapData()
}

override suspend fun getHomeRestaurant(
campusIdx: Int,
order: String,
group: String?,
grade: String?
): Result<GetUnivRestaurantResponse> {
return runCatching { restaurantApi.getUnivRestaurant(
campusIdx = campusIdx,
order = order,
group = group,
grade = grade,
offset = 0,
limit = 3)
}.unwrapData()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.everymeal.data.model.restaruant

import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
import com.everymeal.domain.model.restaurant.RestaurantDataEntity
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -64,4 +65,10 @@ fun RestaurantResponse.toEntity(): RestaurantDataEntity {
images = this.images,
isLiked = this.isLiked
)
}

fun GetUnivRestaurantResponse.toEntity(): GetUnivRestaurantEntity {
return GetUnivRestaurantEntity(
data = this.content.map { it.toEntity() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import androidx.paging.map
import com.everymeal.data.model.restaruant.toEntity
import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
import javax.inject.Inject

class RestaurantRepositoryImpl @Inject constructor(
Expand All @@ -28,4 +29,13 @@ class RestaurantRepositoryImpl @Inject constructor(
override suspend fun getRestaurantDetail(index: Int): Result<RestaurantDataEntity> {
return restaurantDataSource.getRestaurantDetail(index).map { it.toEntity() }
}

override suspend fun getHomeRestaurant(
campusIdx: Int,
order: String,
group: String?,
grade: String?
): Result<GetUnivRestaurantEntity> {
return restaurantDataSource.getHomeRestaurant(campusIdx, order, group, grade).map { it.toEntity() }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.everymeal.domain.repository.restaurant

import androidx.paging.PagingData
import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
import com.everymeal.domain.model.restaurant.RestaurantDataEntity
import kotlinx.coroutines.flow.Flow

Expand All @@ -16,4 +17,11 @@ interface RestaurantRepository {
suspend fun getRestaurantDetail(
index: Int
) : Result<RestaurantDataEntity>

suspend fun getHomeRestaurant(
campusIdx: Int,
order: String,
group: String? = null,
grade: String? = null,
) : Result<GetUnivRestaurantEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.everymeal.domain.usecase.restaurant

import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
import com.everymeal.domain.repository.restaurant.RestaurantRepository
import javax.inject.Inject

class GetHomeRestaurantUseCase @Inject constructor(
private val restaurantRepository: RestaurantRepository
) {
suspend operator fun invoke(
campusIdx: Int,
order: String,
group: String?,
grade: String?
) : Result<GetUnivRestaurantEntity> {
return restaurantRepository.getHomeRestaurant(campusIdx, order, group, grade)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.everymeal.presentation.R
import com.everymeal.presentation.ui.detail.ReportCategoryType
import com.everymeal.presentation.ui.detail.RestaurantCategoryType
import com.everymeal.presentation.ui.home.HomeCategoryList
import com.everymeal.presentation.ui.theme.EveryMealTypo
import com.everymeal.presentation.ui.theme.EveryMealTypography
Expand Down Expand Up @@ -165,6 +166,7 @@ fun SortCategoryItem(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EveryMealCategoryRatingBottomSheetDialog(
title : String = "",
currentRating: Int,
restaurantCategoryType: String,
onClick: () -> Unit,
Expand All @@ -181,26 +183,30 @@ fun EveryMealCategoryRatingBottomSheetDialog(
.fillMaxWidth()
.padding(horizontal = 20.dp)
) {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 14.dp),
text = stringResource(R.string.meal_category),
fontSize = 17.sp,
color = Gray900,
fontWeight = FontWeight.SemiBold,
)
Spacer(modifier = Modifier.padding(4.dp))
HomeCategoryList(
isBottomSheet = true,
restaurantCategoryType
) {
onCategoryClick(it)
if(title.RestaurantCategoryType() != RestaurantCategoryType.CAFE
&& title.RestaurantCategoryType() != RestaurantCategoryType.DRINK) {
Spacer(modifier = Modifier.padding(4.dp))
Text(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 14.dp),
text = stringResource(R.string.meal_category),
fontSize = 17.sp,
color = Gray900,
fontWeight = FontWeight.SemiBold,
)
Spacer(modifier = Modifier.padding(4.dp))
HomeCategoryList(
isBottomSheet = true,
restaurantCategoryType
) {
onCategoryClick(it)
}
Spacer(modifier = Modifier.padding(14.dp))
Divider(
color = Gray200,
)
}
Spacer(modifier = Modifier.padding(14.dp))
Divider(
color = Gray200,
)
Spacer(modifier = Modifier.padding(4.dp))
Text(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -74,6 +75,7 @@ fun RestaurantTitle(
) {
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
modifier = Modifier.padding(top = 6.dp),
Expand Down Expand Up @@ -104,7 +106,9 @@ fun RestaurantLoveCount(
onLoveClick: () -> Unit,
) {
Column(
modifier = Modifier.clickable(
modifier = Modifier
.padding(top = 6.dp)
.clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) { onLoveClick() },
Expand Down Expand Up @@ -157,23 +161,33 @@ fun RestaurantRating(restaurant: RestaurantDataEntity) {
fun RestaurantImage(restaurant: RestaurantDataEntity) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
horizontalArrangement = Arrangement.spacedBy(6.dp)
) {
// restaurant.images?.take(3)?.forEachIndexed { index, image ->
// AsyncImage(
// model = image,
// contentDescription = null,
// modifier = Modifier
// .weight(1f)
// .aspectRatio(1f)
// .padding(end = if (index < 2) 6.dp else 0.dp)
// .clip(RoundedCornerShape(8.dp)),
// contentScale = ContentScale.Crop
// )
// }
restaurant.images?.let {
when {
restaurant.images?.size == 3 -> {
restaurant.images?.forEachIndexed { index, image ->
restaurant.images?.size!! >= 3 -> {
restaurant.images?.take(3)?.forEachIndexed { index, image ->
AsyncImage(
model = image,
contentDescription = null,
modifier = Modifier
.weight(1f)
.aspectRatio(1f)
.clip(RoundedCornerShape(8.dp)),
model = image,
contentDescription = null
contentScale = ContentScale.Crop
)
if(index != 2) {
Spacer(modifier = Modifier.padding(end = 6.dp))
}
}
}

Expand All @@ -185,11 +199,12 @@ fun RestaurantImage(restaurant: RestaurantDataEntity) {
.aspectRatio(1f)
.clip(RoundedCornerShape(8.dp)),
model = image,
contentDescription = null
contentDescription = null,
contentScale = ContentScale.Crop
)
if(index != 1) {
Spacer(modifier = Modifier.padding(end = 6.dp))
}
// if(index != 1) {
// Spacer(modifier = Modifier.padding(end = 6.dp))
// }
}
Spacer(modifier = Modifier.weight(1f))
}
Expand All @@ -205,56 +220,56 @@ fun RestaurantImage(restaurant: RestaurantDataEntity) {
)
Spacer(modifier = Modifier
.weight(2f)
.padding(end = 6.dp)
// .padding(end = 6.dp)
)
}

restaurant.images?.size!! > 3 -> {
AsyncImage(
modifier = Modifier
.weight(1f)
.aspectRatio(1f)
.clip(RoundedCornerShape(8.dp)),
model = restaurant.images!![0],
contentDescription = null
)
Spacer(modifier = Modifier.padding(end = 6.dp))
AsyncImage(
modifier = Modifier
.weight(1f)
.aspectRatio(1f)
.clip(RoundedCornerShape(8.dp)),
model = restaurant.images!![0],
contentDescription = null
)
Spacer(modifier = Modifier.padding(end = 6.dp))
Box(
modifier = Modifier
.weight(1f)
.aspectRatio(1f)
) {
AsyncImage(
modifier = Modifier
.aspectRatio(1f)
.fillMaxSize(),
model = restaurant.images!![0],
contentDescription = null
)
Box(
modifier = Modifier
.matchParentSize()
.clip(RoundedCornerShape(8.dp))
.background(Color.Black.copy(alpha = 0.2f)),
contentAlignment = Alignment.Center
) {
Text(
text = "+${restaurant.reviewCount - 2}",
color = Color.White,
fontSize = 14.sp
)
}
}
}
// restaurant.images?.size!! > 3 -> {
// AsyncImage(
// modifier = Modifier
// .weight(1f)
// .aspectRatio(1f)
// .clip(RoundedCornerShape(8.dp)),
// model = restaurant.images!![0],
// contentDescription = null
// )
// Spacer(modifier = Modifier.padding(end = 6.dp))
// AsyncImage(
// modifier = Modifier
// .weight(1f)
// .aspectRatio(1f)
// .clip(RoundedCornerShape(8.dp)),
// model = restaurant.images!![0],
// contentDescription = null
// )
// Spacer(modifier = Modifier.padding(end = 6.dp))
// Box(
// modifier = Modifier
// .weight(1f)
// .aspectRatio(1f)
// ) {
// AsyncImage(
// modifier = Modifier
// .aspectRatio(1f)
// .fillMaxSize(),
// model = restaurant.images!![0],
// contentDescription = null
// )
// Box(
// modifier = Modifier
// .matchParentSize()
// .clip(RoundedCornerShape(8.dp))
// .background(Color.Black.copy(alpha = 0.2f)),
// contentAlignment = Alignment.Center
// ) {
// Text(
// text = "+${restaurant.reviewCount - 2}",
// color = Color.White,
// fontSize = 14.sp
// )
// }
// }
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ enum class EveryMealRoute(val route: String) {
DETAIL_LIST("detail-list"),
DETAIL_RESTAURANT("detail-restaurant"),
SCHOOL_AUTH("school-auth"),
WITH_DRAW("with-draw")
}
Loading

0 comments on commit f9f76de

Please sign in to comment.