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/#73] 여행 대시 보드 뷰 / 서버 통신 구현 #83

Merged
merged 16 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.tripdashboard.TripDashBoardActivity"
android:name="com.going.presentation.dashboard.DashBoardActivity"
android:exported="false"
android:screenOrientation="portrait" />

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/going/doorip/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.going.doorip.di

import com.going.data.datasource.AuthDataSource
import com.going.data.datasource.DashBoardDataSource
import com.going.data.datasource.MockDataSource
import com.going.data.datasource.SettingDataSource
import com.going.data.datasource.TendencyDataSource
import com.going.data.datasource.TodoDataSource
import com.going.data.datasourceImpl.AuthDataSourceImpl
import com.going.data.datasourceImpl.DashBoardDataSourceImpl
import com.going.data.datasourceImpl.MockDataSourceImpl
import com.going.data.datasourceImpl.SettingDataSourceImpl
import com.going.data.datasourceImpl.TendencyDataSourceImpl
Expand Down Expand Up @@ -40,6 +42,11 @@ object DataSourceModule {
fun provideTodoDataSource(todoDataSourceImpl: TodoDataSourceImpl): TodoDataSource =
todoDataSourceImpl

@Provides
@Singleton
fun provideDashBoardDataSource(dashBoardDataSourceImpl: DashBoardDataSourceImpl): DashBoardDataSource =
dashBoardDataSourceImpl

@Provides
@Singleton
fun provideTendencyDataSource(tendencyDataSourceImpl: TendencyDataSourceImpl): TendencyDataSource =
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/going/doorip/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.going.doorip.di

import com.going.data.repositoryImpl.AuthRepositoryImpl
import com.going.data.repositoryImpl.DashBoardRepositoryImpl
import com.going.data.repositoryImpl.MockRepositoryImpl
import com.going.data.repositoryImpl.SettingRepositoryImpl
import com.going.data.repositoryImpl.TendencyRepositoryImpl
import com.going.data.repositoryImpl.TodoRepositoryImpl
import com.going.data.repositoryImpl.TokenRepositoryImpl
import com.going.domain.repository.AuthRepository
import com.going.domain.repository.DashBoardRepository
import com.going.domain.repository.MockRepository
import com.going.domain.repository.SettingRepository
import com.going.domain.repository.TendencyRepository
Expand Down Expand Up @@ -47,6 +49,11 @@ object RepositoryModule {
fun provideTodoRepository(todoRepositoryImpl: TodoRepositoryImpl): TodoRepository =
todoRepositoryImpl

@Provides
@Singleton
fun providesDashBoardRepository(dashBoardRepositoryImpl: DashBoardRepositoryImpl): DashBoardRepository =
dashBoardRepositoryImpl

@Provides
@Singleton
fun provideTendencyRepository(tendencyRepositoryImpl: TendencyRepositoryImpl): TendencyRepository =
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/going/doorip/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.going.doorip.di

import com.going.data.service.AuthService
import com.going.data.service.DashBoardService
import com.going.data.service.MockService
import com.going.data.service.SettingService
import com.going.data.service.TendencyService
Expand Down Expand Up @@ -36,6 +37,11 @@ object ServiceModule {
fun provideTodoService(retrofit: Retrofit): TodoService =
retrofit.create(TodoService::class.java)

@Provides
@Singleton
fun provideDashBoardService(retrofit: Retrofit): DashBoardService =
retrofit.create(DashBoardService::class.java)

@Provides
@Singleton
fun provideTendencyService(retrofit: Retrofit): TendencyService =
Expand Down
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> =
Copy link
Member

Choose a reason for hiding this comment

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

줄바꿈....좀...ㅎㅎ

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()
Copy link
Contributor

Choose a reason for hiding this comment

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

.map 이용 조아욥

})
Copy link
Member

Choose a reason for hiding this comment

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

함수명도 model로 수정해주세요~

}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AuthInterceptor @Inject constructor(

Timber.d("GET ACCESS TOKEN : ${dataStore.accessToken}")


val authRequest = if (dataStore.accessToken.isNotBlank()) {
originalRequest.newAuthBuilder().build()
} else {
Expand Down
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
Copy link
Member

Choose a reason for hiding this comment

The 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()
}
}
13 changes: 13 additions & 0 deletions data/src/main/java/com/going/data/service/DashBoardService.kt
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

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

..? ㅋㅋ


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setTabLayout()
setViewPager()
setTravelerName()

}

Expand All @@ -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"
Copy link
Member

Choose a reason for hiding this comment

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

이렇 중요한 텍스트는 const val로 관리해주시면 좋을 것 같아요 ~

Copy link
Member

Choose a reason for hiding this comment

The 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?>()
Copy link
Member

Choose a reason for hiding this comment

The 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"
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.going.presentation.tripdashboard
package com.going.presentation.dashboard

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.going.presentation.tripdashboard.triplist.CompletedTripFragment
import com.going.presentation.tripdashboard.triplist.OngoingTripFragment
import com.going.presentation.dashboard.triplist.CompletedTripFragment
import com.going.presentation.dashboard.triplist.OngoingTripFragment

class DashBoardViewPagerAdapter(fragment: FragmentActivity) : FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 2
Expand Down
Loading