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/#96] 여행 생성 뷰 / 서버 통신 구현 #108

Merged
merged 11 commits into from
Jan 14, 2024
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@

</application>

</manifest>
</manifest>
11 changes: 9 additions & 2 deletions app/src/main/java/com/going/doorip/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.going.doorip.di

import com.going.data.datasource.AuthDataSource
import com.going.data.datasource.DashBoardDataSource
import com.going.data.datasource.EnterPreferenceDataSource
import com.going.data.datasource.EnterTripDataSource
import com.going.data.datasource.MockDataSource
import com.going.data.datasource.ProfileDataSource
Expand All @@ -11,6 +12,7 @@ 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.EnterPreferenceDataSourceImpl
import com.going.data.datasourceImpl.EnterTripDataSourceImpl
import com.going.data.datasourceImpl.MockDataSourceImpl
import com.going.data.datasourceImpl.ProfileDataSourceImpl
Expand Down Expand Up @@ -65,11 +67,16 @@ object DataSourceModule {

@Provides
@Singleton
fun provideEnterTripDataSource(entertripDataSourceImpl: EnterTripDataSourceImpl): EnterTripDataSource =
entertripDataSourceImpl
fun provideEnterTripDataSource(enterTripDataSourceImpl: EnterTripDataSourceImpl): EnterTripDataSource =
enterTripDataSourceImpl

@Provides
@Singleton
fun provideStartInviteTripDataSource(startInviteTripDataSourceImpl: StartInviteTripDataSourceImpl): StartInviteTripDataSource =
startInviteTripDataSourceImpl

@Provides
@Singleton
fun provideEnterPreferenceDataSource(enterPreferenceDataSourceImpl: EnterPreferenceDataSourceImpl): EnterPreferenceDataSource =
enterPreferenceDataSourceImpl
}
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
Expand Up @@ -2,6 +2,7 @@ package com.going.doorip.di

import com.going.data.repositoryImpl.AuthRepositoryImpl
import com.going.data.repositoryImpl.DashBoardRepositoryImpl
import com.going.data.repositoryImpl.EnterPreferenceRepositoryImpl
import com.going.data.repositoryImpl.EnterTripRepositoryImpl
import com.going.data.repositoryImpl.MockRepositoryImpl
import com.going.data.repositoryImpl.ProfileRepositoryImpl
Expand All @@ -12,6 +13,7 @@ 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.EnterPreferenceRepository
import com.going.domain.repository.EnterTripRepository
import com.going.domain.repository.MockRepository
import com.going.domain.repository.ProfileRepository
Expand Down Expand Up @@ -79,4 +81,9 @@ object RepositoryModule {
@Singleton
fun provideStartInviteTripRepository(startInviteTripRepositoryImpl: StartInviteTripRepositoryImpl): StartInviteTripRepository =
startInviteTripRepositoryImpl

@Provides
@Singleton
fun provideEnterPreferenceRepository(enterPreferenceRepositoryImpl: EnterPreferenceRepositoryImpl): EnterPreferenceRepository =
enterPreferenceRepositoryImpl
}
7 changes: 6 additions & 1 deletion app/src/main/java/com/going/doorip/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.going.doorip.di

import android.provider.ContactsContract.Profile
import com.going.data.service.AuthService
import com.going.data.service.DashBoardService
import com.going.data.service.EnterPreferenceService
import com.going.data.service.EnterTripService
import com.going.data.service.MockService
import com.going.data.service.ProfileService
Expand Down Expand Up @@ -65,4 +65,9 @@ object ServiceModule {
@Singleton
fun provideStartInviteTripService(retrofit: Retrofit): StartInviteTripService =
retrofit.create(StartInviteTripService::class.java)

@Provides
@Singleton
fun provideEnterPreferenceService(retrofit: Retrofit): EnterPreferenceService =
retrofit.create(EnterPreferenceService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.going.data.datasource

import com.going.data.dto.BaseResponse
import com.going.data.dto.request.EnterPreferenceRequestDto
import com.going.data.dto.response.EnterPreferenceResponseDto
import retrofit2.http.Body

interface EnterPreferenceDataSource {
suspend fun postTripInfo(
@Body request: EnterPreferenceRequestDto
): BaseResponse<EnterPreferenceResponseDto>

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class DashBoardDataSourceImpl @Inject constructor(
private val dashBoardService: DashBoardService
) : DashBoardDataSource {

override suspend fun getTripList(progress: String): BaseResponse<DashBoardResponseDto> =
override suspend fun getTripList(
progress: String
): BaseResponse<DashBoardResponseDto> =
dashBoardService.getTripList(progress)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.going.data.datasourceImpl

import com.going.data.datasource.EnterPreferenceDataSource
import com.going.data.dto.BaseResponse
import com.going.data.dto.request.EnterPreferenceRequestDto
import com.going.data.dto.response.EnterPreferenceResponseDto
import com.going.data.service.EnterPreferenceService
import javax.inject.Inject

class EnterPreferenceDataSourceImpl @Inject constructor(
private val enterPreferenceService: EnterPreferenceService
) : EnterPreferenceDataSource {

override suspend fun postTripInfo(
request: EnterPreferenceRequestDto
): BaseResponse<EnterPreferenceResponseDto> =
enterPreferenceService.postTripInfoFromServer(request)

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class AuthInterceptor @Inject constructor(
return response
}

private fun Request.newAuthBuilder() =
this.newBuilder().addHeader(AUTHORIZATION, "$BEARER ${dataStore.accessToken}")
private fun Request.newAuthBuilder() =
this.newBuilder().addHeader(AUTHORIZATION, "$BEARER ${dataStore.accessToken}")
Comment on lines +87 to +88
Copy link
Contributor

Choose a reason for hiding this comment

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

컨s 부탁tv해욥


companion object {
private const val CODE_TOKEN_EXPIRED = 401
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.going.data.dto.request

import com.going.domain.entity.request.EnterPreferenceRequestModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class EnterPreferenceRequestDto(
@SerialName("title")
val title: String,
@SerialName("startDate")
val startDate: String,
@SerialName("endDate")
val endDate: String,
@SerialName("styleA")
val styleA: Int,
@SerialName("styleB")
val styleB: Int,
@SerialName("styleC")
val styleC: Int,
@SerialName("styleD")
val styleD: Int,
@SerialName("styleE")
val styleE: Int
)

fun EnterPreferenceRequestModel.toEnterPreferenceRequestDto(): EnterPreferenceRequestDto =
EnterPreferenceRequestDto(title, startDate, endDate, styleA, styleB, styleC, styleD, styleE)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ data class EnterTripRequestDto(

fun EnterTripRequestModel.toEnterTripRequestDto(): EnterTripRequestDto =
EnterTripRequestDto(code)

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.going.data.dto.response

import com.going.domain.entity.response.EnterPreferenceModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class EnterPreferenceResponseDto(
@SerialName("tripId")
val tripId: Long,
@SerialName("title")
val title: String,
@SerialName("startDate")
val startDate: String,
@SerialName("endDate")
val endDate: String,
@SerialName("code")
val code: String,
@SerialName("day")
val day: Int,
) {
fun toEnterPreferenceModel() =
EnterPreferenceModel(tripId, title, startDate, endDate, code, day)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.going.data.repositoryImpl

import com.going.data.datasource.EnterPreferenceDataSource
import com.going.data.dto.request.toEnterPreferenceRequestDto
import com.going.domain.entity.request.EnterPreferenceRequestModel
import com.going.domain.entity.response.EnterPreferenceModel
import com.going.domain.repository.EnterPreferenceRepository
import javax.inject.Inject

class EnterPreferenceRepositoryImpl @Inject constructor(
private val enterPreferenceDataSource: EnterPreferenceDataSource
) : EnterPreferenceRepository {

override suspend fun postTripInfo(
request: EnterPreferenceRequestModel
): Result<EnterPreferenceModel> =
runCatching {
enterPreferenceDataSource.postTripInfo(
request.toEnterPreferenceRequestDto(),
).data.toEnterPreferenceModel()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.going.data.service

import com.going.data.dto.BaseResponse
import com.going.data.dto.request.EnterPreferenceRequestDto
import com.going.data.dto.response.EnterPreferenceResponseDto
import retrofit2.http.Body
import retrofit2.http.POST

interface EnterPreferenceService {

@POST("api/trips")
suspend fun postTripInfoFromServer(
@Body request: EnterPreferenceRequestDto,
): BaseResponse<EnterPreferenceResponseDto>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.going.domain.entity.request

data class EnterPreferenceRequestModel(
val title: String,
val startDate: String,
val endDate: String,
val styleA: Int,
val styleB: Int,
val styleC: Int,
val styleD: Int,
val styleE: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.going.domain.entity.response

data class EnterPreferenceModel(
val tripId: Long,
val title: String,
val startDate: String,
val endDate: String,
val code: String,
val day: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.going.domain.repository

import com.going.domain.entity.request.EnterPreferenceRequestModel
import com.going.domain.entity.response.EnterPreferenceModel

interface EnterPreferenceRepository {

suspend fun postTripInfo(
request: EnterPreferenceRequestModel
): Result<EnterPreferenceModel>

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

import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import com.going.presentation.R
import com.going.presentation.databinding.ActivityTripDashBoardBinding
import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -22,6 +25,7 @@ class DashBoardActivity :
setTabLayout()
setViewPager()
setTravelerName()
initCreateTripBtnClickListener()

}

Expand Down Expand Up @@ -51,6 +55,18 @@ class DashBoardActivity :
}
}

private fun initCreateTripBtnClickListener() {
binding.btnDashboardCreateTrip.setOnSingleClickListener {
navigateToDashboard()
}
}

private fun navigateToDashboard() {
Intent(this, CreateTripActivity::class.java).apply {
startActivity(this)
}
}

companion object {
const val TAB_ONGOING = "진행중인 여행"
const val TAB_COMPLETED = "지나간 여행"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS
calendar.set(Calendar.DAY_OF_MONTH, viewModel.endDay.value ?: 0)
val endDate = calendar.time

if(startDate.before(endDate)) {
if (startDate.before(endDate)) {
dismiss()
} else {
toast(getString(R.string.create_trip_toast_error))
Expand Down
Loading