-
Notifications
You must be signed in to change notification settings - Fork 2
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/#73] 여행 대시 보드 뷰 / 서버 통신 구현 #83
Changes from 11 commits
a5d69c9
12bc5f6
832cd4b
140478d
a7c1526
f2f845e
f633066
8333877
b2c86da
48e7291
1c62950
0348fe8
c9c0354
5a756eb
100c0e2
992a39d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.going.data.datasource | ||
|
||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.response.DashBoardResponseDto | ||
|
||
interface DashBoardDataSource { | ||
suspend fun getTripList( | ||
progress: String | ||
): BaseResponse<DashBoardResponseDto> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.going.data.datasourceImpl | ||
|
||
import com.going.data.datasource.DashBoardDataSource | ||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.response.DashBoardResponseDto | ||
import com.going.data.service.DashBoardService | ||
import javax.inject.Inject | ||
|
||
class DashBoardDataSourceImpl @Inject constructor( | ||
private val dashBoardService: DashBoardService | ||
) : DashBoardDataSource { | ||
override suspend fun getTripList(progress: String): BaseResponse<DashBoardResponseDto> = | ||
dashBoardService.getTripList(progress) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.going.data.dto.response | ||
|
||
import com.going.domain.entity.response.DashBoardModel | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class DashBoardResponseDto( | ||
@SerialName("name") | ||
val name: String, | ||
@SerialName("trips") | ||
val trips: List<TripsResponseDto> | ||
|
||
) { | ||
@Serializable | ||
data class TripsResponseDto( | ||
@SerialName("tripId") | ||
val tripId: Long, | ||
@SerialName("title") | ||
val title: String, | ||
@SerialName("startDate") | ||
val startDate: String, | ||
@SerialName("endDate") | ||
val endDate: String, | ||
@SerialName("day") | ||
val day: Int | ||
) { | ||
fun toTripsModel() = | ||
DashBoardModel.DashBoardTripModel(tripId, title, startDate, endDate, day) | ||
} | ||
|
||
fun toDashBoardEntity() = | ||
DashBoardModel(name, trips.map { | ||
it.toTripsModel() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .map 이용 조아욥 |
||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수명도 model로 수정해주세요~ |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.going.data.repositoryImpl | ||
|
||
import com.going.data.datasource.DashBoardDataSource | ||
import com.going.domain.entity.response.DashBoardModel | ||
import com.going.domain.repository.DashBoardRepository | ||
import javax.inject.Inject | ||
|
||
class DashBoardRepositoryImpl @Inject constructor( | ||
private val dashBoardSource: DashBoardDataSource | ||
) : DashBoardRepository { | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도...ㅎㅎ |
||
override suspend fun getDashBoardList( | ||
progress: String | ||
): Result<DashBoardModel> = | ||
runCatching { | ||
dashBoardSource.getTripList(progress).data.toDashBoardEntity() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.going.data.service | ||
|
||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.response.DashBoardResponseDto | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface DashBoardService { | ||
@GET("api/trips") | ||
suspend fun getTripList( | ||
@Query("progress") progress: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 조아요 쿼리 |
||
) : BaseResponse<DashBoardResponseDto> | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.going.domain.entity.response | ||
|
||
data class DashBoardModel( | ||
val name: String, | ||
val trips: List<DashBoardTripModel> | ||
){ | ||
data class DashBoardTripModel( | ||
val tripId: Long, | ||
val title: String, | ||
val startDate: String, | ||
val endDate: String, | ||
val day: Int | ||
) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.going.domain.repository | ||
|
||
import com.going.domain.entity.response.DashBoardModel | ||
|
||
interface DashBoardRepository { | ||
suspend fun getDashBoardList( | ||
progress : String, | ||
) : Result<DashBoardModel> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
package com.going.presentation.tripdashboard | ||
package com.going.presentation.dashboard | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import com.going.presentation.R | ||
import com.going.presentation.databinding.ActivityTripDashBoardBinding | ||
import com.going.ui.base.BaseActivity | ||
import com.google.android.material.tabs.TabLayoutMediator | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
class TripDashBoardActivity : | ||
@AndroidEntryPoint | ||
class DashBoardActivity : | ||
BaseActivity<ActivityTripDashBoardBinding>(R.layout.activity_trip_dash_board) { | ||
|
||
private val tabTextList = listOf(TAB_ONGOING, TAB_COMPLETED) | ||
|
||
private val viewModel by viewModels<DashBoardViewModel>() | ||
|
||
var name: String? = null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ..? ㅋㅋ |
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setTabLayout() | ||
setViewPager() | ||
setTravelerName() | ||
|
||
} | ||
|
||
|
@@ -31,14 +39,23 @@ class TripDashBoardActivity : | |
|
||
private fun setViewPager() { | ||
binding.vpDashboard.adapter = DashBoardViewPagerAdapter(this) | ||
binding.vpDashboard.isUserInputEnabled = false | ||
TabLayoutMediator(binding.tabDashboard, binding.vpDashboard) { tab, pos -> | ||
tab.text = tabTextList[pos] | ||
}.attach() | ||
} | ||
|
||
private fun setTravelerName() { | ||
val progress = "incomplete" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇 중요한 텍스트는 const val로 관리해주시면 좋을 것 같아요 ~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아래 뷰모델에서 지정을 해줬으니, 그거 가져와서 임포트 하시는게 더 좋을 듯 |
||
viewModel.getTravelerNameFromServer(progress) | ||
viewModel.name.observe(this) { travelerName -> | ||
binding.tvDashboardTitle.text = getString(R.string.dashboard_tv_title, travelerName) | ||
} | ||
} | ||
|
||
companion object { | ||
const val TAB_ONGOING = "진행중인 여행" | ||
const val TAB_COMPLETED = "완료된 여행" | ||
const val TAB_COMPLETED = "지나간 여행" | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.going.presentation.dashboard | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.going.domain.entity.response.DashBoardModel | ||
import com.going.domain.repository.DashBoardRepository | ||
import com.going.ui.extension.UiState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class DashBoardViewModel @Inject constructor( | ||
private val dashBoardRepository: DashBoardRepository | ||
) : ViewModel() { | ||
private val _dashBoardOngoingListState = | ||
MutableStateFlow<UiState<DashBoardModel>>(UiState.Empty) | ||
val dashBoardOngoingListState: StateFlow<UiState<DashBoardModel>> get() = _dashBoardOngoingListState | ||
|
||
private val _dashBoardCompletedListState = | ||
MutableStateFlow<UiState<DashBoardModel>>(UiState.Empty) | ||
|
||
val name = MutableLiveData<String?>() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. liveData 사용할 떄, 특수한 경우가 아니면 기본을 String값으로 하고 초기값을 ""로 설정해두어서 nullable하지 않은 변수를 다뤄주세요 ! |
||
|
||
val dashBoardCompletedListState: StateFlow<UiState<DashBoardModel>> get() = _dashBoardCompletedListState | ||
|
||
fun getTripListFromServer( | ||
progress: String | ||
) { | ||
val dashBoardListState = if (progress == ONGOING) { | ||
_dashBoardOngoingListState | ||
} else { | ||
_dashBoardCompletedListState | ||
} | ||
dashBoardListState.value = UiState.Loading | ||
viewModelScope.launch { | ||
dashBoardRepository.getDashBoardList(progress) | ||
.onSuccess { | ||
dashBoardListState.value = UiState.Success(it) | ||
} | ||
.onFailure { | ||
dashBoardListState.value = UiState.Failure(it.message.orEmpty()) | ||
} | ||
} | ||
} | ||
|
||
fun getTravelerNameFromServer(progress: String) { | ||
viewModelScope.launch { | ||
dashBoardRepository.getDashBoardList(progress) | ||
.onSuccess { | ||
name.value = it.name | ||
} | ||
.onFailure { | ||
name.value = null | ||
} | ||
} | ||
} | ||
|
||
|
||
companion object { | ||
const val ONGOING = "incomplete" | ||
const val COMPLETED = "complete" | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
줄바꿈....좀...ㅎㅎ