Skip to content

Commit f9f76de

Browse files
authored
Merge pull request #94 from everymeals/feature/home_api
[feature/home_api] 홈화면 api 연결 및 가게 상세 연결
2 parents b7fbbb7 + d2371f6 commit f9f76de

File tree

20 files changed

+524
-305
lines changed

20 files changed

+524
-305
lines changed

data/src/main/java/com/everymeal/data/datasource/restaurant/RestaurantDataSource.kt

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.everymeal.data.datasource.restaurant
22

33
import androidx.paging.PagingData
4+
import com.everymeal.data.model.restaruant.GetUnivRestaurantResponse
45
import com.everymeal.data.model.restaruant.RestaurantResponse
56
import kotlinx.coroutines.flow.Flow
67

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

1516
suspend fun getRestaurantDetail(index: Int): Result<RestaurantResponse>
17+
18+
suspend fun getHomeRestaurant(
19+
campusIdx: Int,
20+
order: String,
21+
group: String? = null,
22+
grade: String? = null,
23+
): Result<GetUnivRestaurantResponse>
1624
}

data/src/main/java/com/everymeal/data/datasource/restaurant/RestaurantDataSourceImpl.kt

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.everymeal.data.datasource.restaurant
33
import androidx.paging.Pager
44
import androidx.paging.PagingConfig
55
import androidx.paging.PagingData
6+
import com.everymeal.data.model.restaruant.GetUnivRestaurantResponse
67
import com.everymeal.data.model.restaruant.RestaurantResponse
78
import com.everymeal.data.model.unwrapData
89
import com.everymeal.data.service.restaurant.RestaurantApi
@@ -35,4 +36,20 @@ class RestaurantDataSourceImpl @Inject constructor(
3536
override suspend fun getRestaurantDetail(index: Int): Result<RestaurantResponse> {
3637
return runCatching { restaurantApi.getRestaurantDetail(index) }.unwrapData()
3738
}
39+
40+
override suspend fun getHomeRestaurant(
41+
campusIdx: Int,
42+
order: String,
43+
group: String?,
44+
grade: String?
45+
): Result<GetUnivRestaurantResponse> {
46+
return runCatching { restaurantApi.getUnivRestaurant(
47+
campusIdx = campusIdx,
48+
order = order,
49+
group = group,
50+
grade = grade,
51+
offset = 0,
52+
limit = 3)
53+
}.unwrapData()
54+
}
3855
}

data/src/main/java/com/everymeal/data/model/restaruant/GetUnivRestaurantResponse.kt

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.everymeal.data.model.restaruant
22

3+
import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
34
import com.everymeal.domain.model.restaurant.RestaurantDataEntity
45
import kotlinx.serialization.Serializable
56

@@ -64,4 +65,10 @@ fun RestaurantResponse.toEntity(): RestaurantDataEntity {
6465
images = this.images,
6566
isLiked = this.isLiked
6667
)
68+
}
69+
70+
fun GetUnivRestaurantResponse.toEntity(): GetUnivRestaurantEntity {
71+
return GetUnivRestaurantEntity(
72+
data = this.content.map { it.toEntity() }
73+
)
6774
}

data/src/main/java/com/everymeal/data/repository/restaurant/RestaurantRepositoryImpl.kt

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.Flow
88
import kotlinx.coroutines.flow.map
99
import androidx.paging.map
1010
import com.everymeal.data.model.restaruant.toEntity
11+
import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
1112
import javax.inject.Inject
1213

1314
class RestaurantRepositoryImpl @Inject constructor(
@@ -28,4 +29,13 @@ class RestaurantRepositoryImpl @Inject constructor(
2829
override suspend fun getRestaurantDetail(index: Int): Result<RestaurantDataEntity> {
2930
return restaurantDataSource.getRestaurantDetail(index).map { it.toEntity() }
3031
}
32+
33+
override suspend fun getHomeRestaurant(
34+
campusIdx: Int,
35+
order: String,
36+
group: String?,
37+
grade: String?
38+
): Result<GetUnivRestaurantEntity> {
39+
return restaurantDataSource.getHomeRestaurant(campusIdx, order, group, grade).map { it.toEntity() }
40+
}
3141
}

domain/src/main/java/com/everymeal/domain/repository/restaurant/RestaurantRepository.kt

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.everymeal.domain.repository.restaurant
22

33
import androidx.paging.PagingData
4+
import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
45
import com.everymeal.domain.model.restaurant.RestaurantDataEntity
56
import kotlinx.coroutines.flow.Flow
67

@@ -16,4 +17,11 @@ interface RestaurantRepository {
1617
suspend fun getRestaurantDetail(
1718
index: Int
1819
) : Result<RestaurantDataEntity>
20+
21+
suspend fun getHomeRestaurant(
22+
campusIdx: Int,
23+
order: String,
24+
group: String? = null,
25+
grade: String? = null,
26+
) : Result<GetUnivRestaurantEntity>
1927
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.everymeal.domain.usecase.restaurant
2+
3+
import com.everymeal.domain.model.restaurant.GetUnivRestaurantEntity
4+
import com.everymeal.domain.repository.restaurant.RestaurantRepository
5+
import javax.inject.Inject
6+
7+
class GetHomeRestaurantUseCase @Inject constructor(
8+
private val restaurantRepository: RestaurantRepository
9+
) {
10+
suspend operator fun invoke(
11+
campusIdx: Int,
12+
order: String,
13+
group: String?,
14+
grade: String?
15+
) : Result<GetUnivRestaurantEntity> {
16+
return restaurantRepository.getHomeRestaurant(campusIdx, order, group, grade)
17+
}
18+
}

presentation/src/main/java/com/everymeal/presentation/components/EveryMealBottomSheetDialog.kt

+25-19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import androidx.compose.ui.unit.dp
3434
import androidx.compose.ui.unit.sp
3535
import com.everymeal.presentation.R
3636
import com.everymeal.presentation.ui.detail.ReportCategoryType
37+
import com.everymeal.presentation.ui.detail.RestaurantCategoryType
3738
import com.everymeal.presentation.ui.home.HomeCategoryList
3839
import com.everymeal.presentation.ui.theme.EveryMealTypo
3940
import com.everymeal.presentation.ui.theme.EveryMealTypography
@@ -165,6 +166,7 @@ fun SortCategoryItem(
165166
@OptIn(ExperimentalMaterial3Api::class)
166167
@Composable
167168
fun EveryMealCategoryRatingBottomSheetDialog(
169+
title : String = "",
168170
currentRating: Int,
169171
restaurantCategoryType: String,
170172
onClick: () -> Unit,
@@ -181,26 +183,30 @@ fun EveryMealCategoryRatingBottomSheetDialog(
181183
.fillMaxWidth()
182184
.padding(horizontal = 20.dp)
183185
) {
184-
Text(
185-
modifier = Modifier
186-
.fillMaxWidth()
187-
.padding(vertical = 14.dp),
188-
text = stringResource(R.string.meal_category),
189-
fontSize = 17.sp,
190-
color = Gray900,
191-
fontWeight = FontWeight.SemiBold,
192-
)
193-
Spacer(modifier = Modifier.padding(4.dp))
194-
HomeCategoryList(
195-
isBottomSheet = true,
196-
restaurantCategoryType
197-
) {
198-
onCategoryClick(it)
186+
if(title.RestaurantCategoryType() != RestaurantCategoryType.CAFE
187+
&& title.RestaurantCategoryType() != RestaurantCategoryType.DRINK) {
188+
Spacer(modifier = Modifier.padding(4.dp))
189+
Text(
190+
modifier = Modifier
191+
.fillMaxWidth()
192+
.padding(vertical = 14.dp),
193+
text = stringResource(R.string.meal_category),
194+
fontSize = 17.sp,
195+
color = Gray900,
196+
fontWeight = FontWeight.SemiBold,
197+
)
198+
Spacer(modifier = Modifier.padding(4.dp))
199+
HomeCategoryList(
200+
isBottomSheet = true,
201+
restaurantCategoryType
202+
) {
203+
onCategoryClick(it)
204+
}
205+
Spacer(modifier = Modifier.padding(14.dp))
206+
Divider(
207+
color = Gray200,
208+
)
199209
}
200-
Spacer(modifier = Modifier.padding(14.dp))
201-
Divider(
202-
color = Gray200,
203-
)
204210
Spacer(modifier = Modifier.padding(4.dp))
205211
Text(
206212
modifier = Modifier

presentation/src/main/java/com/everymeal/presentation/components/EveryMealRestaurantItem.kt

+75-60
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.ui.Modifier
2323
import androidx.compose.ui.draw.clip
2424
import androidx.compose.ui.graphics.Color
2525
import androidx.compose.ui.graphics.vector.ImageVector
26+
import androidx.compose.ui.layout.ContentScale
2627
import androidx.compose.ui.res.stringResource
2728
import androidx.compose.ui.res.vectorResource
2829
import androidx.compose.ui.text.font.FontWeight
@@ -74,6 +75,7 @@ fun RestaurantTitle(
7475
) {
7576
Row(
7677
modifier = modifier,
78+
verticalAlignment = Alignment.CenterVertically,
7779
) {
7880
Text(
7981
modifier = Modifier.padding(top = 6.dp),
@@ -104,7 +106,9 @@ fun RestaurantLoveCount(
104106
onLoveClick: () -> Unit,
105107
) {
106108
Column(
107-
modifier = Modifier.clickable(
109+
modifier = Modifier
110+
.padding(top = 6.dp)
111+
.clickable(
108112
indication = null,
109113
interactionSource = remember { MutableInteractionSource() }
110114
) { onLoveClick() },
@@ -157,23 +161,33 @@ fun RestaurantRating(restaurant: RestaurantDataEntity) {
157161
fun RestaurantImage(restaurant: RestaurantDataEntity) {
158162
Row(
159163
modifier = Modifier.fillMaxWidth(),
160-
horizontalArrangement = Arrangement.SpaceBetween
164+
horizontalArrangement = Arrangement.spacedBy(6.dp)
161165
) {
166+
// restaurant.images?.take(3)?.forEachIndexed { index, image ->
167+
// AsyncImage(
168+
// model = image,
169+
// contentDescription = null,
170+
// modifier = Modifier
171+
// .weight(1f)
172+
// .aspectRatio(1f)
173+
// .padding(end = if (index < 2) 6.dp else 0.dp)
174+
// .clip(RoundedCornerShape(8.dp)),
175+
// contentScale = ContentScale.Crop
176+
// )
177+
// }
162178
restaurant.images?.let {
163179
when {
164-
restaurant.images?.size == 3 -> {
165-
restaurant.images?.forEachIndexed { index, image ->
180+
restaurant.images?.size!! >= 3 -> {
181+
restaurant.images?.take(3)?.forEachIndexed { index, image ->
166182
AsyncImage(
183+
model = image,
184+
contentDescription = null,
167185
modifier = Modifier
168186
.weight(1f)
169187
.aspectRatio(1f)
170188
.clip(RoundedCornerShape(8.dp)),
171-
model = image,
172-
contentDescription = null
189+
contentScale = ContentScale.Crop
173190
)
174-
if(index != 2) {
175-
Spacer(modifier = Modifier.padding(end = 6.dp))
176-
}
177191
}
178192
}
179193

@@ -185,11 +199,12 @@ fun RestaurantImage(restaurant: RestaurantDataEntity) {
185199
.aspectRatio(1f)
186200
.clip(RoundedCornerShape(8.dp)),
187201
model = image,
188-
contentDescription = null
202+
contentDescription = null,
203+
contentScale = ContentScale.Crop
189204
)
190-
if(index != 1) {
191-
Spacer(modifier = Modifier.padding(end = 6.dp))
192-
}
205+
// if(index != 1) {
206+
// Spacer(modifier = Modifier.padding(end = 6.dp))
207+
// }
193208
}
194209
Spacer(modifier = Modifier.weight(1f))
195210
}
@@ -205,56 +220,56 @@ fun RestaurantImage(restaurant: RestaurantDataEntity) {
205220
)
206221
Spacer(modifier = Modifier
207222
.weight(2f)
208-
.padding(end = 6.dp)
223+
// .padding(end = 6.dp)
209224
)
210225
}
211226

212-
restaurant.images?.size!! > 3 -> {
213-
AsyncImage(
214-
modifier = Modifier
215-
.weight(1f)
216-
.aspectRatio(1f)
217-
.clip(RoundedCornerShape(8.dp)),
218-
model = restaurant.images!![0],
219-
contentDescription = null
220-
)
221-
Spacer(modifier = Modifier.padding(end = 6.dp))
222-
AsyncImage(
223-
modifier = Modifier
224-
.weight(1f)
225-
.aspectRatio(1f)
226-
.clip(RoundedCornerShape(8.dp)),
227-
model = restaurant.images!![0],
228-
contentDescription = null
229-
)
230-
Spacer(modifier = Modifier.padding(end = 6.dp))
231-
Box(
232-
modifier = Modifier
233-
.weight(1f)
234-
.aspectRatio(1f)
235-
) {
236-
AsyncImage(
237-
modifier = Modifier
238-
.aspectRatio(1f)
239-
.fillMaxSize(),
240-
model = restaurant.images!![0],
241-
contentDescription = null
242-
)
243-
Box(
244-
modifier = Modifier
245-
.matchParentSize()
246-
.clip(RoundedCornerShape(8.dp))
247-
.background(Color.Black.copy(alpha = 0.2f)),
248-
contentAlignment = Alignment.Center
249-
) {
250-
Text(
251-
text = "+${restaurant.reviewCount - 2}",
252-
color = Color.White,
253-
fontSize = 14.sp
254-
)
255-
}
256-
}
257-
}
227+
// restaurant.images?.size!! > 3 -> {
228+
// AsyncImage(
229+
// modifier = Modifier
230+
// .weight(1f)
231+
// .aspectRatio(1f)
232+
// .clip(RoundedCornerShape(8.dp)),
233+
// model = restaurant.images!![0],
234+
// contentDescription = null
235+
// )
236+
// Spacer(modifier = Modifier.padding(end = 6.dp))
237+
// AsyncImage(
238+
// modifier = Modifier
239+
// .weight(1f)
240+
// .aspectRatio(1f)
241+
// .clip(RoundedCornerShape(8.dp)),
242+
// model = restaurant.images!![0],
243+
// contentDescription = null
244+
// )
245+
// Spacer(modifier = Modifier.padding(end = 6.dp))
246+
// Box(
247+
// modifier = Modifier
248+
// .weight(1f)
249+
// .aspectRatio(1f)
250+
// ) {
251+
// AsyncImage(
252+
// modifier = Modifier
253+
// .aspectRatio(1f)
254+
// .fillMaxSize(),
255+
// model = restaurant.images!![0],
256+
// contentDescription = null
257+
// )
258+
// Box(
259+
// modifier = Modifier
260+
// .matchParentSize()
261+
// .clip(RoundedCornerShape(8.dp))
262+
// .background(Color.Black.copy(alpha = 0.2f)),
263+
// contentAlignment = Alignment.Center
264+
// ) {
265+
// Text(
266+
// text = "+${restaurant.reviewCount - 2}",
267+
// color = Color.White,
268+
// fontSize = 14.sp
269+
// )
270+
// }
271+
// }
272+
// }
258273
}
259274
}
260275
}

presentation/src/main/java/com/everymeal/presentation/ui/bottom/BottomNavigation.kt

+1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ enum class EveryMealRoute(val route: String) {
3939
DETAIL_LIST("detail-list"),
4040
DETAIL_RESTAURANT("detail-restaurant"),
4141
SCHOOL_AUTH("school-auth"),
42+
WITH_DRAW("with-draw")
4243
}

0 commit comments

Comments
 (0)