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

[feat] 마이페이지 회원정보 조회 api 연동 #52

Merged
merged 11 commits into from
Jul 20, 2023
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.sopt.geonppang.data.datasource.remote

import com.sopt.geonppang.data.model.response.ResponseMypageBookmark
import com.sopt.geonppang.data.model.response.ResponseMypageInfo
import com.sopt.geonppang.data.model.response.ResponseMypageReview
import com.sopt.geonppang.data.service.MypageService
import javax.inject.Inject

class MypageDataSource @Inject constructor(
private val mypageService: MypageService,
) {
suspend fun fetchMypageInfo(): ResponseMypageInfo =
mypageService.fetchMypageInfo()

suspend fun fetchMyBookmarkList(): ResponseMypageBookmark =
mypageService.fetchMypageBookmark()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.sopt.geonppang.data.model.response

import com.sopt.geonppang.domain.model.BreadType
import com.sopt.geonppang.domain.model.Profile
import kotlinx.serialization.Serializable

@Serializable
data class ResponseMypageInfo(
val code: Int,
val data: Data,
val message: String
) {
@Serializable
data class Data(
val memberNickname: String,
val mainPurpose: String,
val breadType: BreadType
) {
@Serializable
data class BreadType(
val breadTypeId: Int,
val breadTypeName: String,
val isGlutenFree: Boolean,
val isNutFree: Boolean,
val isSugarFree: Boolean,
val isVegan: Boolean
)
}

fun toMypageInfo() = Profile(
memberNickname = data.memberNickname,
mainPurpose = data.mainPurpose,
breadType = BreadType(
breadTypeId = data.breadType.breadTypeId,
breadTypeName = data.breadType.breadTypeName,
isGlutenFree = data.breadType.isGlutenFree,
isVegan = data.breadType.isVegan,
isNutFree = data.breadType.isNutFree,
isSugarFree = data.breadType.isSugarFree
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package com.sopt.geonppang.data.repository
import com.sopt.geonppang.data.datasource.remote.MypageDataSource
import com.sopt.geonppang.domain.model.Bakery
import com.sopt.geonppang.domain.model.MyReview
import com.sopt.geonppang.domain.model.Profile
import com.sopt.geonppang.domain.repository.MypageRepository
import javax.inject.Inject

class MypageRepositoryImpl @Inject constructor(
private val mypageDataSource: MypageDataSource,
) : MypageRepository {
override suspend fun fetchMypageInfo(): Result<Profile> = runCatching {
mypageDataSource.fetchMypageInfo().toMypageInfo()
}

override suspend fun fetchMyBookmark(): Result<List<Bakery>> = runCatching {
mypageDataSource.fetchMyBookmarkList().toMypageBookmark()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.sopt.geonppang.data.service

import com.sopt.geonppang.data.model.response.ResponseMypageBookmark
import com.sopt.geonppang.data.model.response.ResponseMypageInfo
import com.sopt.geonppang.data.model.response.ResponseMypageReview
import retrofit2.http.GET

interface MypageService {
@GET("/member")
suspend fun fetchMypageInfo(): ResponseMypageInfo

@GET("member/bookMarks")
suspend fun fetchMypageBookmark(): ResponseMypageBookmark

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/sopt/geonppang/domain/model/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ data class Profile(
val memberNickname: String,
val mainPurpose: String,
val breadType: BreadType
)
) {
constructor() : this("", "", BreadType(0, "", false, false, false, false))
}
Copy link
Member

Choose a reason for hiding this comment

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

what is this?

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.sopt.geonppang.domain.repository

import com.sopt.geonppang.domain.model.Bakery
import com.sopt.geonppang.domain.model.MyReview
import com.sopt.geonppang.domain.model.Profile

interface MypageRepository {
suspend fun fetchMypageInfo(): Result<Profile>
suspend fun fetchMyBookmark(): Result<List<Bakery>>
suspend fun fetchMyReview(): Result<List<MyReview>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
binding.viewModel = viewModel
binding.lifecycleOwner = this

viewModel.fetchMypageInfo()
Copy link
Member

Choose a reason for hiding this comment

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

뷰모델 init{} 블록으로 이동


addListeners()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.sopt.geonppang.presentation.mypage
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopt.geonppang.domain.model.Bakery
import com.sopt.geonppang.domain.model.BreadType
import com.sopt.geonppang.domain.model.MyReview
import com.sopt.geonppang.domain.model.Profile
import com.sopt.geonppang.domain.repository.MypageRepository
Expand All @@ -19,27 +18,18 @@ import javax.inject.Inject
class MyPageViewModel @Inject constructor(
private val mypageRepository: MypageRepository,
) : ViewModel() {
private val _profile = Profile(
memberNickname = "안빵이들",
mainPurpose = "맛 . 다이어트",
breadType = BreadType(
breadTypeId = 1,
breadTypeName = "글루텐프리",
isGlutenFree = true,
isVegan = true,
isNutFree = false,
isSugarFree = true
)
)
val profile = _profile
private var _mypageInfoState = MutableStateFlow(Profile())
val mypageInfoState get() = _mypageInfoState.asStateFlow()
Copy link
Member

Choose a reason for hiding this comment

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

뭔가 이상한데...?


private var _mypageReviewListState = MutableStateFlow<UiState<List<MyReview>>>(UiState.Loading)
private var _mypageReviewListState =
MutableStateFlow<UiState<List<MyReview>>>(UiState.Loading)
val mypageReviewListState get() = _mypageReviewListState.asStateFlow()

private var _myReviewCount = MutableStateFlow<Int?>(null)
val myReviewCount get() = _myReviewCount.asStateFlow()

private var _mypageBookmarkListState = MutableStateFlow<UiState<List<Bakery>>>(UiState.Loading)
private var _mypageBookmarkListState =
MutableStateFlow<UiState<List<Bakery>>>(UiState.Loading)
val mypageBookmarkListState get() = _mypageBookmarkListState.asStateFlow()

private var _myBookmarkCount = MutableStateFlow<Int?>(null)
Expand All @@ -50,6 +40,17 @@ class MyPageViewModel @Inject constructor(
fetchMypageBookmarkList()
}

fun fetchMypageInfo() {
viewModelScope.launch {
mypageRepository.fetchMypageInfo()
.onSuccess { myInfo ->
myInfo.let {
_mypageInfoState.value = myInfo
}
}
}
}

private fun fetchMypageReviewList() {
viewModelScope.launch {
mypageRepository.fetchMyReview().onSuccess { myReviewList ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import androidx.activity.viewModels
import com.sopt.geonppang.R
import com.sopt.geonppang.databinding.ActivityReviewWritingBinding
import com.sopt.geonppang.util.binding.BindingActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ReviewWritingActivity :
BindingActivity<ActivityReviewWritingBinding>(R.layout.activity_review_writing) {
private val viewModel: ReviewViewModel by viewModels()
Expand Down Expand Up @@ -39,10 +41,22 @@ class ReviewWritingActivity :
}

private fun showReviewSuccessDialog() {
ReviewSuccessBottomDialogFragment().show(supportFragmentManager, "reviewSuccessDialog")
val bakeryId = intent.getIntExtra(BAKERY_ID, -1)
val reviewSuccessDialogFragment = ReviewSuccessBottomDialogFragment().apply {
arguments = Bundle().apply {
bakeryId?.let { bakeryId ->
putInt(BAKERY_ID, bakeryId)
}
}
}
reviewSuccessDialogFragment.show(supportFragmentManager, "reviewSuccessDialog")
}

private fun showReviewCancelDialog() {
ReviewCancelBottomDialogFragment().show(supportFragmentManager, "reviewCancelDialog")
}

companion object {
const val BAKERY_ID = "bakeryId"
}
}
12 changes: 6 additions & 6 deletions app/src/main/res/layout/fragment_my_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:backgroundTint="@color/point_2"
android:text="@{viewModel.profile.mainPurpose}"
android:text="@{viewModel.mypageInfoState.mainPurpose}"
app:layout_constraintStart_toEndOf="@+id/iv_my_page_profile_img"
app:layout_constraintTop_toTopOf="@+id/iv_my_page_profile_img"
tools:text="맛 . 다이어트" />
Expand All @@ -67,7 +67,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@{viewModel.profile.memberNickname}"
android:text="@{viewModel.mypageInfoState.memberNickname}"
android:textAppearance="@style/TextAppearance.Title2"
android:textColor="@color/gray_600"
app:layout_constraintStart_toStartOf="@+id/chip_my_page_profile_purpose"
Expand Down Expand Up @@ -99,31 +99,31 @@

<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Style.Radius3.Stroke"
visibility="@{viewModel.profile.breadType.isGlutenFree}"
visibility="@{viewModel.mypageInfoState.breadType.component3()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/transparent"
android:text="@string/my_page_gluten_free" />

<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Style.Radius3.Stroke"
visibility="@{viewModel.profile.breadType.isNutFree}"
visibility="@{viewModel.mypageInfoState.breadType.component4()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/transparent"
android:text="@string/my_page_nut_free" />

<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Style.Radius3.Stroke"
visibility="@{viewModel.profile.breadType.isVegan}"
visibility="@{viewModel.mypageInfoState.breadType.component5()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/transparent"
android:text="@string/my_page_vegan" />

<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Style.Radius3.Stroke"
visibility="@{viewModel.profile.breadType.isSugarFree}"
visibility="@{viewModel.mypageInfoState.breadType.component6()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/transparent"
Expand Down
Loading