Skip to content

Commit

Permalink
[fix/home_detail_action]: 식당 등록 API groupId 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dogdduddy authored and Jim-swit committed Mar 16, 2024
1 parent fc94059 commit 0a4a31b
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface RestaurantDataSource {

suspend fun postRestaurantLocationInfo(restaurantLocationInfo: RestaurantLocationInfo): String

suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String
suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest, groupId: Int): String

suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class RestaurantDataSourceImpl @Inject constructor(
return restaurantAPI.postRestaurantLocationInfo(restaurantLocationInfo).data
}

override suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String {
override suspend fun postRestaurantInfo(
restaurantRegistrationRequest: RestaurantRegistrationRequest,
groupId: Int,
): String {
runCatching {
restaurantAPI.postRestaurantInfo(
mapOf(
Expand All @@ -100,7 +103,7 @@ class RestaurantDataSourceImpl @Inject constructor(
"goWellWithLiquor" to restaurantRegistrationRequest.goWellWithLiquor.toRequestBody(),
"recommendMenu" to restaurantRegistrationRequest.recommendMenu.toRequestBody(),
"restaurantLocationId" to restaurantRegistrationRequest.restaurantLocationAggregateId.toRequestBody(),
"groupId" to "10".toRequestBody()
"groupId" to groupId.toString().toRequestBody()
),
pictures = restaurantRegistrationRequest.pictures
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ class RestaurantRepositoryImpl @Inject constructor(
return restaurantDataSource.postRestaurantLocationInfo(restaurantLocationInfo)
}

override suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String {
return restaurantDataSource.postRestaurantInfo(restaurantRegistrationRequest)
override suspend fun postRestaurantInfo(
restaurantRegistrationRequest: RestaurantRegistrationRequest,
groupId: Int,
): String {
return restaurantDataSource.postRestaurantInfo(restaurantRegistrationRequest, groupId)
}

override suspend fun getRestaurants(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface RestaurantRepository {

suspend fun postRestaurantLocationInfo(restaurantLocationInfo: RestaurantLocationInfo): String

suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String
suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest, groupId: Int): String

suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class PostRestaurantInfoUseCase @Inject constructor(
canDrinkLiquor: Boolean,
goWellWithLiquor: String,
recommendMenu: String,
restaurantLocationAggregateIdg: String
restaurantLocationAggregateIdg: String,
groupId: Int,
): String {
return restaurantRepository.postRestaurantInfo(
RestaurantRegistrationRequest(
Expand All @@ -30,6 +31,7 @@ class PostRestaurantInfoUseCase @Inject constructor(
recommendMenu,
restaurantLocationAggregateIdg
),
groupId,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ class MainActivity : BaseActivity() {
binding.toolBar.isVisible = isVisible
}

fun navigateToEditRestaurantInfo(restaurantId: Int) {

val action = HomeFragmentDirections.actionHomeFragmentToRegisterRestaurantFragment(
targetRestaurantId = restaurantId
)
navController.navigate(action)
}
// fun navigateToEditRestaurantInfo(restaurantId: Int) {
//
// val action = HomeFragmentDirections.actionHomeFragmentToRegisterRestaurantFragment(
// targetRestaurantId = restaurantId
// )
// navController.navigate(action)
// }

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConfirmRestaurantRegistrationFragment : Fragment() {
private var _binding: FragmentConfirmRestaurantRegistrationBinding? = null
private val binding get() = _binding!!
private val navArgs by navArgs<ConfirmRestaurantRegistrationFragmentArgs>()
private val groupId by lazy { navArgs.groupId }

private lateinit var mapView: MapView

Expand All @@ -52,7 +53,10 @@ class ConfirmRestaurantRegistrationFragment : Fragment() {
binding.selectButton.setOnClickListener {

val action = ConfirmRestaurantRegistrationFragmentDirections
.actionConfirmRestaurantRegistrationFragmentToRegisterRestaurantFragment(navArgs.restaurantLocationInfo)
.actionConfirmRestaurantRegistrationFragmentToRegisterRestaurantFragment(
groupId,
navArgs.restaurantLocationInfo
)
findNavController().navigate(action)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RegisterRestaurantFragment : BaseFragment() {
private val viewModel: RegisterRestaurantViewModel by viewModels()

private val navArgs by navArgs<RegisterRestaurantFragmentArgs>()
private val groupId by lazy { navArgs.groupId }

private val foodCategoryDialog by lazy {
FoodCategoryBottomSheetDialog { selectedItem ->
Expand Down Expand Up @@ -341,7 +342,6 @@ class RegisterRestaurantFragment : BaseFragment() {
MediaType.parse("image/png"),
imageFile
)

val body =
MultipartBody.Part.createFormData(
"pictures",
Expand All @@ -358,6 +358,7 @@ class RegisterRestaurantFragment : BaseFragment() {
lifecycleScope.launch(Dispatchers.IO) {
viewModel.registerRestaurant(
pictures,
groupId,
navArgs.restaurantLocationInfo ?: throw Exception()
) { restaurantId ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gdsc.presentation.view.restaurantregistration

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
Expand All @@ -9,6 +10,7 @@ import androidx.annotation.DrawableRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -29,15 +31,20 @@ class SearchRestaurantLocationInfoFragment : Fragment() {
private var _binding: FragmentSearchRestaurantLocationInfoBinding? = null
private val binding get() = _binding!!
private val viewModel: SearchRestaurantLocationInfoViewModel by viewModels()

private val navArgs: SearchRestaurantLocationInfoFragmentArgs by navArgs()
private val groupId by lazy { navArgs.groupId }

private val adapter by lazy {
RestaurantLocationInfoAdapter {
viewLifecycleOwner.lifecycleScope.launch {
val canRegister = viewModel.canRegisterRestaurant(it.id)

val action = SearchRestaurantLocationInfoFragmentDirections
.actionSearchRestaurantLocationInfoFragmentToConfirmRestaurantRegistrationFragment(
groupId,
canRegister,
it
it,
)
findNavController().navigate(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class RegisterRestaurantViewModel @Inject constructor(

fun registerRestaurant(
pictures: List<MultipartBody.Part>,
groupId: Int,
restaurantLocationInfo: RestaurantLocationInfo,
actionAfterRegisterSuccess: (String) -> Unit = {}
) {
Expand All @@ -170,7 +171,8 @@ class RegisterRestaurantViewModel @Inject constructor(
recommendMenu = recommendMenuListState.value.joinToString(" ") {
"#$it"
},
restaurantLocationAggregateIdg = restaurantLocationInfoId
restaurantLocationAggregateIdg = restaurantLocationInfoId,
groupId = groupId,
)

actionAfterRegisterSuccess(restaurantId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SpecificWebViewFragment : Fragment() {
parentActivity.slideDownBottomNavigationView()
},
{
parentActivity.navigateToEditRestaurantInfo(it)
// parentActivity.navigateToEditRestaurantInfo(it)
},
{
repeatWhenUiStarted {
Expand Down
21 changes: 21 additions & 0 deletions presentation/src/main/res/navigation/main_nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<action
android:id="@+id/action_home_fragment_to_all_search_fragment"
app:destination="@id/all_search_fragment" />
<action
android:id="@+id/action_home_fragment_to_search_restaurant_location_info_fragment"
app:destination="@+id/search_restaurant_location_info_fragment"/>
</fragment>
<fragment
android:id="@+id/all_search_fragment"
Expand Down Expand Up @@ -59,24 +62,38 @@
android:name="org.gdsc.presentation.view.restaurantregistration.SearchRestaurantLocationInfoFragment"
android:label="fragment_food_spot_registration"
tools:layout="@layout/fragment_search_restaurant_location_info" >

<argument
android:name="groupId"
app:argType="integer"/>

<action
android:id="@+id/action_search_restaurant_location_info_fragment_to_confirmRestaurantRegistrationFragment"
app:destination="@id/confirm_restaurant_registration_fragment" />

</fragment>
<fragment
android:id="@+id/confirm_restaurant_registration_fragment"
android:name="org.gdsc.presentation.view.restaurantregistration.ConfirmRestaurantRegistrationFragment"
android:label="fragment_confirm_restaurant_registration"
tools:layout="@layout/fragment_confirm_restaurant_registration">

<argument
android:name="groupId"
app:argType="integer"/>

<argument
android:name="canRegister"
app:argType="boolean" />

<argument
android:name="restaurantLocationInfo"
app:argType="org.gdsc.domain.model.RestaurantLocationInfo" />

<action
android:id="@+id/action_confirmRestaurantRegistrationFragment_to_registerRestaurantFragment"
app:destination="@id/registerRestaurant_fragment" />

</fragment>
<fragment
android:id="@+id/registerRestaurant_fragment"
Expand Down Expand Up @@ -107,6 +124,10 @@
app:argType="integer"
android:defaultValue="-1"/>

<argument
android:name="groupId"
app:argType="integer"/>

<action
android:id="@+id/action_registerRestaurantFragment_to_multiImagePickerFragment"
app:destination="@id/multiImagePicker_fragment"/>
Expand Down

0 comments on commit 0a4a31b

Please sign in to comment.